mongoid-preferences 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -75,7 +75,7 @@ module Mongoid
|
|
75
75
|
# Returns a hash of preferences merged from file and model
|
76
76
|
def merged_preferences
|
77
77
|
# get the preferences from model
|
78
|
-
model_preferences_hash = self.read_attribute(:preferences)
|
78
|
+
model_preferences_hash = HashWithIndifferentAccess.new(self.read_attribute(:preferences))
|
79
79
|
# get the default preferences form file
|
80
80
|
default_preferences_hash = default_preferences
|
81
81
|
# merge the preferences
|
@@ -213,6 +213,42 @@ describe Mongoid::Preferences::Preferenceable do
|
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
216
|
+
context 'when add new preference with string key' do
|
217
|
+
before {
|
218
|
+
@pref_value = true
|
219
|
+
model_with_preferences.write_pref('preference_key', @pref_value)
|
220
|
+
model_with_preferences.save
|
221
|
+
}
|
222
|
+
it 'returns the preference value accessing with string key' do
|
223
|
+
# Force reload of instance
|
224
|
+
reloaded_instance = Dummy.last
|
225
|
+
expect(reloaded_instance.pref('preference_key')).to eq(@pref_value)
|
226
|
+
end
|
227
|
+
it 'returns the preference value accessing with symbol key' do
|
228
|
+
# Force reload of instance
|
229
|
+
reloaded_instance = Dummy.last
|
230
|
+
expect(reloaded_instance.pref(:preference_key)).to eq(@pref_value)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context 'when add new preference with symbol key' do
|
235
|
+
before {
|
236
|
+
@pref_value = true
|
237
|
+
model_with_preferences.write_pref(:preference_key, @pref_value)
|
238
|
+
model_with_preferences.save
|
239
|
+
}
|
240
|
+
it 'returns the preference value accessing with string key' do
|
241
|
+
# Force reload of instance
|
242
|
+
reloaded_instance = Dummy.last
|
243
|
+
expect(reloaded_instance.pref('preference_key')).to eq(@pref_value)
|
244
|
+
end
|
245
|
+
it 'returns the preference value accessing with symbol key' do
|
246
|
+
# Force reload of instance
|
247
|
+
reloaded_instance = Dummy.last
|
248
|
+
expect(reloaded_instance.pref(:preference_key)).to eq(@pref_value)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
216
252
|
end
|
217
253
|
|
218
254
|
describe '#displayable_preferences' do
|