File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -14,9 +14,8 @@ class Localized < Standard
14
14
#
15
15
# @return [ Object ] The value for the current locale.
16
16
def demongoize ( object )
17
- if object
18
- type . demongoize ( lookup ( object ) )
19
- end
17
+ return if object . nil?
18
+ type . demongoize ( lookup ( object ) )
20
19
end
21
20
22
21
# Is the field localized or not?
@@ -86,7 +85,10 @@ def lookup(object)
86
85
end
87
86
return value unless value . nil?
88
87
if fallbacks? && ::I18n . respond_to? ( :fallbacks )
89
- object [ ::I18n . fallbacks [ locale ] . map ( &:to_s ) . find { |loc | object . has_key? ( loc ) } ]
88
+ fallback_key = ::I18n . fallbacks [ locale ] . find do |loc |
89
+ object . key? ( loc . to_s ) || object . key? ( loc )
90
+ end
91
+ object [ fallback_key . to_s ] || object [ fallback_key ]
90
92
end
91
93
end
92
94
end
Original file line number Diff line number Diff line change 102
102
end
103
103
end
104
104
105
+ context "when key is a symbol" do
106
+
107
+ let ( :value ) do
108
+ field . demongoize ( { :de => "This is a test" } )
109
+ end
110
+
111
+ it "returns the string from the set locale" do
112
+ expect ( value ) . to eq ( "This is a test" )
113
+ end
114
+ end
115
+
105
116
context "when the value does not exist" do
106
117
107
118
context "when not using fallbacks" do
142
153
end
143
154
end
144
155
156
+ context "when the fallback translation exists and is a symbol" do
157
+
158
+ let ( :value ) do
159
+ field . demongoize ( { :es => "testing" } )
160
+ end
161
+
162
+ it "returns the fallback translation" do
163
+ expect ( value ) . to eq ( "testing" )
164
+ end
165
+ end
166
+
145
167
context "when another fallback translation exists" do
146
168
147
169
let ( :value ) do
You can’t perform that action at this time.
0 commit comments