Skip to content

Commit

Permalink
Handle fallback: true with no fallbacks defined
Browse files Browse the repository at this point in the history
  • Loading branch information
shioyama committed Sep 9, 2017
1 parent 32ab338 commit e5c67ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 6 additions & 10 deletions lib/mobility/plugins/fallbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,12 @@ def initialize(fallbacks_option)
private

def define_read(fallbacks)
define_method :read do |locale, **options|
fallback = options.delete(:fallback)

if fallback == false || (fallback.nil? && fallbacks.nil?)
super(locale, options)
else
(fallback.is_a?(Symbol) ? [locale, *fallback] : fallbacks[locale]).detect do |fallback_locale|
value = super(fallback_locale, options)
break value if Util.present?(value)
end
define_method :read do |locale, fallback: nil, **options|
return super(locale, options) if fallback == false || (!fallback.is_a?(Symbol) && fallbacks.nil?)

(fallback.is_a?(Symbol) ? [locale, *fallback] : fallbacks[locale]).detect do |fallback_locale|
value = super(fallback_locale, options)
break value if Util.present?(value)
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/mobility/plugins/fallbacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def read(locale, **options)
it "uses locale passed in as value of fallback option when present" do
expect(subject.read(:"en-US", fallback: :ja)).to eq("フー")
end

it "does not use fallbacks when fallback: true option is passed" do
expect(subject.read(:"en-US", fallback: true)).to eq(nil)
end
end
end

Expand Down

0 comments on commit e5c67ae

Please sign in to comment.