Skip to content

Commit

Permalink
Fix I18n 1.1 compatibility issues in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
shioyama committed Sep 21, 2018
1 parent 051f402 commit f44caf5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 0 additions & 5 deletions spec/integration/active_record_compatibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@
describe "fallbacks" do
let!(:post) { FallbackPost.create(title: "foo title") }

it "falls through to default locale with no options" do
Mobility.locale = :ja
expect(post.title).to eq("foo title")
end

it "does not fall through to default locale when fallback: false option passed in" do
Mobility.locale = :ja
expect(post.title(fallback: false)).to eq(nil)
Expand Down
11 changes: 10 additions & 1 deletion spec/mobility/plugins/fallbacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,19 @@ def read(locale, **options)
context "fallbacks is true" do
let(:fallbacks) { true }

# @note I18n changed its behavior in 1.1 (see: https://github.com/svenfuchs/i18n/pull/415)
# To correctly test all versions, we actually generate fallbacks and
# determine what the value should be, then check that it matches the
# actual fallback value.
# TODO: Simplify this when support for I18n < 1.1 is dropped.
it "uses default fallbacks" do
original_default_locale = I18n.default_locale
I18n.default_locale = :ja
expect(subject.read(:"en-US")).to eq("フー")
fallbacks = Mobility::Fallbacks.build({})
locales = fallbacks[:"en-US"]
# in I18n 1.1 value is nil here
value = locales.map { |locale| subject.read(locale, locale: true) }.compact.first
expect(subject.read(:"en-US")).to eq(value)
I18n.default_locale = original_default_locale
end
end
Expand Down

0 comments on commit f44caf5

Please sign in to comment.