Skip to content

Commit b7e2d87

Browse files
authored
MONGOID-5438 Implement local override for i18n parameters (#5427)
* MONGOID-5438 Implement local override for i18n parameters * MONGOID-5438 get rid of enfore_available_locale changes * MONGOID-5438 get rid of before alls * MONGOID-5438 fix tests caused by rspec precedence * MONGOID-5438 attempt to fix tests when fallbacks disabled * MONGOID-5438 make fallbacks default to return [self] * MONGOID-5438 reset fallbacks * MONGOID-5438 attempt to fix tests * MONGOID-5438 retry_test * MONGOID-5438 undefine fallback methods after fallback tests * MONGOID-5438 add back defaults * MONGOID-5438 use new macros * MONGOID-5438 use before and after suite * MONGOID-5438 update mrss * MONGOID-5438 remove suite checks
1 parent bf0c010 commit b7e2d87

File tree

15 files changed

+107
-200
lines changed

15 files changed

+107
-200
lines changed

spec/integration/i18n_fallbacks_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
require 'spec_helper'
44

55
describe 'i18n fallbacks' do
6-
with_i18n_fallbacks
6+
require_fallbacks
77

88
context 'when fallbacks are enabled with a locale list' do
9+
with_default_i18n_configs
10+
911
before do
10-
I18n.default_locale = :en
1112
I18n.fallbacks[:de] = [ :en ]
1213
end
1314

spec/mongoid/contextual/memory_spec.rb

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@
522522
end
523523

524524
context "when getting a localized field" do
525+
with_default_i18n_configs
526+
525527
before do
526528
I18n.locale = :en
527529
d = Dictionary.create!(description: 'english-text')
@@ -530,10 +532,6 @@
530532
d.save!
531533
end
532534

533-
after do
534-
I18n.locale = :en
535-
end
536-
537535
let(:criteria) do
538536
Dictionary.all.tap do |crit|
539537
crit.documents = [ Dictionary.first ]
@@ -576,17 +574,11 @@
576574
end
577575

578576
context 'when fallbacks are enabled with a locale list' do
579-
with_i18n_fallbacks
577+
require_fallbacks
578+
with_default_i18n_configs
580579

581-
around(:all) do |example|
582-
prev_fallbacks = I18n.fallbacks.dup
580+
before do
583581
I18n.fallbacks[:he] = [ :en ]
584-
example.run
585-
I18n.fallbacks = prev_fallbacks
586-
end
587-
588-
after do
589-
I18n.locale = :en
590582
end
591583

592584
let(:distinct) do
@@ -602,6 +594,8 @@
602594
end
603595

604596
context "when the localized field is embedded" do
597+
with_default_i18n_configs
598+
605599
let(:person) do
606600
p = Passport.new
607601
I18n.locale = :en
@@ -612,10 +606,6 @@
612606
Person.create!(passport: p, employer_id: 12345)
613607
end
614608

615-
after do
616-
I18n.locale = :en
617-
end
618-
619609
let(:criteria) do
620610
Person.where(employer_id: 12345).tap do |crit|
621611
crit.documents = [ person ]
@@ -1697,6 +1687,7 @@
16971687
end
16981688

16991689
context 'when plucking a localized field' do
1690+
with_default_i18n_configs
17001691

17011692
before do
17021693
I18n.locale = :en
@@ -1706,10 +1697,6 @@
17061697
d.save!
17071698
end
17081699

1709-
after do
1710-
I18n.locale = :en
1711-
end
1712-
17131700
let(:criteria) do
17141701
Dictionary.all.tap do |crit|
17151702
crit.documents = [ Dictionary.first ]
@@ -1766,17 +1753,11 @@
17661753
end
17671754

17681755
context 'when fallbacks are enabled with a locale list' do
1769-
with_i18n_fallbacks
1756+
require_fallbacks
1757+
with_default_i18n_configs
17701758

1771-
around(:all) do |example|
1772-
prev_fallbacks = I18n.fallbacks.dup
1759+
before do
17731760
I18n.fallbacks[:he] = [ :en ]
1774-
example.run
1775-
I18n.fallbacks = prev_fallbacks
1776-
end
1777-
1778-
after do
1779-
I18n.locale = :en
17801761
end
17811762

17821763
let(:plucked) do
@@ -1792,6 +1773,8 @@
17921773
end
17931774

17941775
context "when the localized field is embedded" do
1776+
with_default_i18n_configs
1777+
17951778
before do
17961779
p = Passport.new
17971780
I18n.locale = :en
@@ -1802,10 +1785,6 @@
18021785
Person.create!(passport: p, employer_id: 12345)
18031786
end
18041787

1805-
after do
1806-
I18n.locale = :en
1807-
end
1808-
18091788
let(:plucked) do
18101789
Person.where(employer_id: 12345).pluck("pass.name").first
18111790
end
@@ -2045,6 +2024,8 @@
20452024
end
20462025

20472026
context "when tallying a localized field" do
2027+
with_default_i18n_configs
2028+
20482029
let(:d1) { Dictionary.new(description: 'en1') }
20492030
let(:d2) { Dictionary.new(description: 'en1') }
20502031
let(:d3) { Dictionary.new(description: 'en1') }
@@ -2106,6 +2087,7 @@
21062087
end
21072088

21082089
context "when tallying an embedded localized field" do
2090+
with_default_i18n_configs
21092091

21102092
let(:person1) { Person.create!(addresses: [ address1a, address1b ]) }
21112093
let(:person2) { Person.create!(addresses: [ address2a, address2b ]) }

spec/mongoid/contextual/mongo_spec.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@
561561
end
562562

563563
context "when getting a localized field" do
564+
with_default_i18n_configs
565+
564566
before do
565567
I18n.locale = :en
566568
d = Dictionary.create!(description: 'english-text')
@@ -660,13 +662,11 @@
660662
end
661663

662664
context 'when fallbacks are enabled with a locale list' do
663-
with_i18n_fallbacks
665+
require_fallbacks
666+
with_default_i18n_configs
664667

665-
around(:all) do |example|
666-
prev_fallbacks = I18n.fallbacks.dup
668+
before do
667669
I18n.fallbacks[:he] = [ :en ]
668-
example.run
669-
I18n.fallbacks = prev_fallbacks
670670
end
671671

672672
let(:distinct) do
@@ -694,6 +694,8 @@
694694
end
695695

696696
context "when the localized field is embedded" do
697+
with_default_i18n_configs
698+
697699
before do
698700
p = Passport.new
699701
I18n.locale = :en
@@ -839,6 +841,8 @@
839841
end
840842

841843
context "when tallying a localized field" do
844+
with_default_i18n_configs
845+
842846
before do
843847
I18n.locale = :en
844848
d1 = Dictionary.create!(description: 'en1')
@@ -893,6 +897,7 @@
893897
end
894898

895899
context "when tallying an embedded localized field" do
900+
with_default_i18n_configs
896901

897902
before do
898903
I18n.locale = :en

spec/mongoid/copyable_spec.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,15 @@
164164
end
165165

166166
context "when cloning a document with multiple languages field" do
167+
with_default_i18n_configs
167168

168169
before do
169-
I18n.enforce_available_locales = false
170170
I18n.locale = 'pt_BR'
171171
person.desc = "descrição"
172172
person.addresses.first.name = "descrição"
173173
person.save!
174174
end
175175

176-
after do
177-
I18n.locale = :en
178-
end
179-
180176
let!(:from_db) do
181177
Person.find(person.id)
182178
end
@@ -212,22 +208,18 @@
212208
end
213209

214210
context "when cloning a document with polymorphic embedded documents with multiple language field" do
211+
with_default_i18n_configs
215212

216213
let!(:shipment_address) do
217214
person.addresses.build({ shipping_name: "Title" }, ShipmentAddress)
218215
end
219216

220217
before do
221-
I18n.enforce_available_locales = false
222218
I18n.locale = 'pt_BR'
223219
person.addresses.type(ShipmentAddress).each { |address| address.shipping_name = "Título" }
224220
person.save!
225221
end
226222

227-
after do
228-
I18n.locale = :en
229-
end
230-
231223
let!(:from_db) do
232224
Person.find(person.id)
233225
end

spec/mongoid/criteria/queryable/options_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def localized?
221221
end
222222

223223
context "when the serializer is localized" do
224+
with_default_i18n_configs
224225

225226
before(:all) do
226227
class Field
@@ -232,7 +233,6 @@ def localized?
232233

233234
after(:all) do
234235
Object.send(:remove_const, :Field)
235-
::I18n.locale = :en
236236
end
237237

238238
let(:options) do

spec/mongoid/criteria/queryable/selector_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ def localized?
608608
end
609609

610610
context "when the serializer is localized" do
611+
with_default_i18n_configs
611612

612613
before(:all) do
613614
class Field
@@ -623,7 +624,6 @@ def localized?
623624

624625
after(:all) do
625626
Object.send(:remove_const, :Field)
626-
::I18n.locale = :en
627627
end
628628

629629
let(:selector) do

spec/mongoid/criteria_projection_spec.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
end
155155

156156
context 'when the field is localized' do
157+
with_default_i18n_configs
157158

158159
before do
159160
I18n.locale = :en
@@ -163,10 +164,6 @@
163164
d.save!
164165
end
165166

166-
after do
167-
I18n.locale = :en
168-
end
169-
170167
context 'when entire field is included' do
171168

172169
let(:dictionary) do

spec/mongoid/criteria_spec.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,7 @@
19531953
end
19541954

19551955
context 'when plucking a localized field' do
1956+
with_default_i18n_configs
19561957

19571958
before do
19581959
I18n.locale = :en
@@ -1962,10 +1963,6 @@
19621963
d.save!
19631964
end
19641965

1965-
after do
1966-
I18n.locale = :en
1967-
end
1968-
19691966
context 'when plucking the entire field' do
19701967
let(:plucked) do
19711968
Dictionary.all.pluck(:description)
@@ -2059,13 +2056,10 @@
20592056
end
20602057

20612058
context 'when fallbacks are enabled with a locale list' do
2062-
with_i18n_fallbacks
2059+
require_fallbacks
20632060

2064-
around(:all) do |example|
2065-
prev_fallbacks = I18n.fallbacks.dup
2061+
before do
20662062
I18n.fallbacks[:he] = [ :en ]
2067-
example.run
2068-
I18n.fallbacks = prev_fallbacks
20692063
end
20702064

20712065
let(:plucked) do
@@ -2093,6 +2087,8 @@
20932087
end
20942088

20952089
context "when the localized field is embedded" do
2090+
with_default_i18n_configs
2091+
20962092
before do
20972093
p = Passport.new
20982094
I18n.locale = :en

0 commit comments

Comments
 (0)