Skip to content

Commit 50147d4

Browse files
authored
MONGOID-5334 enforce Hash type in localized demongoize (#5430)
* MONGOID-5334 add type check * MONGOID-5334 change back type check * MONGOID-5334 enforce Hash type in localized demongoize
1 parent 6684fe2 commit 50147d4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/mongoid/fields/localized.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ class Localized < Standard
1515
# @return [ Object ] The value for the current locale.
1616
def demongoize(object)
1717
return if object.nil?
18-
type.demongoize(lookup(object))
18+
case object
19+
when Hash
20+
type.demongoize(lookup(object))
21+
end
1922
end
2023

2124
# Is the field localized or not?

spec/mongoid/fields/localized_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@
113113
end
114114
end
115115

116+
117+
context "passing a bogus value" do
118+
119+
let(:value) do
120+
field.demongoize("bogus")
121+
end
122+
123+
it "returns nil" do
124+
expect(value).to be_nil
125+
end
126+
end
127+
116128
context "when the value does not exist" do
117129

118130
context "when not using fallbacks" do

0 commit comments

Comments
 (0)