Skip to content

Commit

Permalink
add one more spec calling a model instance method
Browse files Browse the repository at this point in the history
  • Loading branch information
doits committed Jul 30, 2019
1 parent fc171dc commit 129f087
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion spec/mobility/plugins/fallbacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ def read(locale, **options)
end
Class.new(backend_subclass).include(described_class.new(fallbacks))
end
let(:object) { (stub_const 'MobilityModel', Class.new).include(Mobility).new }
let(:object) do
(stub_const 'MobilityModel', Class.new)
.include(Mobility)
.include(
Module.new do
def fallback_locale_method
'de-DE'
end
end
).new
end
subject { backend_class.new(object, "title") }

context "fallbacks is a hash" do
Expand Down Expand Up @@ -185,6 +195,44 @@ def read(locale, **options)
end
end

context "fallbacks is a proc calling a model method" do
let(:fallbacks) { proc { fallback_locale_method } }

it "returns value when value is not nil" do
expect(subject.read(:ja)).to eq("フー")
end

it "falls through to fallback locale when value is nil" do
expect(subject.read(:"en-US")).to eq("foo")
end

it "falls through to fallback locale when value is blank" do
expect(subject.read(:pt)).to eq("foo")
end

it "falls through to fallback locale when fallback: true option is passed" do
expect(subject.read(:"en-US", fallback: true)).to eq("foo")
end

it "uses locale passed in as value of fallback option when present" do
expect(subject.read(:"en-US", fallback: :ja)).to eq("フー")
end

it "uses array of locales passed in as value of fallback options when present" do
expect(subject.read(:"en-US", fallback: [:pl, :'de-DE'])).to eq("foo")
end

it "passes options to getter in fallback locale" do
expect(subject.read(:'en-US', bar: true)).to eq("bar")
end

it "does not modify options passed in" do
options = { fallback: false }
subject.read(:"en-US", options)
expect(options).to eq({ fallback: false })
end
end

context "fallbacks is true" do
let(:fallbacks) { true }

Expand Down

0 comments on commit 129f087

Please sign in to comment.