Skip to content

Commit

Permalink
MONGOID-5334 enforce Hash type in localized demongoize (#5430)
Browse files Browse the repository at this point in the history
* MONGOID-5334 add type check

* MONGOID-5334 change back type check

* MONGOID-5334 enforce Hash type in localized demongoize
  • Loading branch information
Neilshweky committed Aug 3, 2022
1 parent 28cbc6d commit bb76525
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/mongoid/fields/localized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ class Localized < Standard
# @return [ Object ] The value for the current locale.
def demongoize(object)
return if object.nil?
type.demongoize(lookup(object))
case object
when Hash
type.demongoize(lookup(object))
end
end

# Is the field localized or not?
Expand Down
12 changes: 12 additions & 0 deletions spec/mongoid/fields/localized_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@
end
end


context "passing a bogus value" do

let(:value) do
field.demongoize("bogus")
end

it "returns nil" do
expect(value).to be_nil
end
end

context "when the value does not exist" do

context "when not using fallbacks" do
Expand Down

0 comments on commit bb76525

Please sign in to comment.