Permalink
Browse files

Always use simple Hashes with stringified keys

  • Loading branch information...
1 parent 78c7564 commit 65b90ddc5eb05e08b6d7d6a838442af3becc9550 @ledermann committed Mar 2, 2013
Showing with 16 additions and 16 deletions.
  1. +3 −3 lib/app/models/setting_object.rb
  2. +1 −1 lib/rails-settings.rb
  3. +4 −4 spec/serialize_spec.rb
  4. +1 −1 spec/setting_object_spec.rb
  5. +7 −7 spec/settings_spec.rb
@@ -11,10 +11,10 @@ class SettingObject < ActiveRecord::Base
end
end
- serialize :value, HashWithIndifferentAccess
+ serialize :value, Hash
def update!(value_attributes)
- self.value = self.value.merge(value_attributes)
+ self.value = self.value.merge(value_attributes.stringify_keys)
save! if self.value_changed?
end
@@ -25,7 +25,7 @@ def method_missing(method_name, *args, &block)
self.value[m[1]] = args.first
else
# Getter
- self.value[method_name] || target_class.default_settings[var.to_sym][method_name]
+ self.value[method_name.to_s] || target_class.default_settings[var.to_sym][method_name.to_s]
end
end
@@ -11,7 +11,7 @@ def self.has_settings(keys)
raise ArgumentError unless key.is_a?(Symbol)
raise ArgumentError unless defaults.nil? || defaults.is_a?(Hash)
- self.default_settings[key] = defaults.with_indifferent_access.freeze
+ self.default_settings[key] = defaults.stringify_keys.freeze
end
include RailsSettings::Base unless self.include?(RailsSettings::Base)
@@ -16,10 +16,10 @@
calendar_settings = user.setting_objects.where(:var => 'calendar').first
dashboard_settings.var.should == 'dashboard'
- dashboard_settings.value.should eq({:theme => 'white'}.with_indifferent_access)
+ dashboard_settings.value.should eq({'theme' => 'white'})
calendar_settings.var.should == 'calendar'
- calendar_settings.value.should eq({:scope => 'all'}.with_indifferent_access)
+ calendar_settings.value.should eq({'scope' => 'all'})
end
end
@@ -31,10 +31,10 @@
calendar_settings = user.setting_objects.where(:var => 'calendar').first
dashboard_settings.var.should == 'dashboard'
- dashboard_settings.value.should eq({:theme => 'white', :smart => true}.with_indifferent_access)
+ dashboard_settings.value.should eq({'theme' => 'white', 'smart' => true})
calendar_settings.var.should == 'calendar'
- calendar_settings.value.should eq({:scope => 'all'}.with_indifferent_access)
+ calendar_settings.value.should eq({'scope' => 'all'})
end
end
end
@@ -29,7 +29,7 @@
setting_object.foo = 42
setting_object.bar = 'hello'
- setting_object.value.should eq({:foo => 42, :bar => 'hello'}.with_indifferent_access)
+ setting_object.value.should eq({'foo' => 42, 'bar' => 'hello'})
end
it "should save" do
View
@@ -2,16 +2,16 @@
describe "Defaults" do
it "should be stored for simple class" do
- Account.default_settings.should eq(:portal => {}.with_indifferent_access)
+ Account.default_settings.should eq(:portal => {})
end
it "should be stored for parent class" do
- User.default_settings.should eq(:dashboard => { :theme => 'blue', :view => 'monthly', :filter => false }.with_indifferent_access,
- :calendar => { :scope => 'company'}.with_indifferent_access)
+ User.default_settings.should eq(:dashboard => { 'theme' => 'blue', 'view' => 'monthly', 'filter' => false },
+ :calendar => { 'scope' => 'company'})
end
it "should be stored for child class" do
- GuestUser.default_settings.should eq(:dashboard => { :theme => 'red', :view => 'monthly', :filter => false }.with_indifferent_access)
+ GuestUser.default_settings.should eq(:dashboard => { 'theme' => 'red', 'view' => 'monthly', 'filter' => false })
end
end
@@ -54,7 +54,7 @@
account.settings(:portal).fee.should eq(42.5)
RailsSettings::SettingObject.count.should eq(1)
- RailsSettings::SettingObject.first.value.should == { :premium => true, :fee => 42.5 }.with_indifferent_access
+ RailsSettings::SettingObject.first.value.should == { 'premium' => true, 'fee' => 42.5 }
end
it "should save settings separated" do
@@ -99,7 +99,7 @@
user.settings(:dashboard).theme.should eq('brown')
user.settings(:dashboard).filter.should eq(true)
RailsSettings::SettingObject.count.should eq(1)
- RailsSettings::SettingObject.first.value.should == { :theme => 'brown', :filter => true }.with_indifferent_access
+ RailsSettings::SettingObject.first.value.should == { 'theme' => 'brown', 'filter' => true }
end
it "should merge settings with defaults" do
@@ -110,7 +110,7 @@
user.settings(:dashboard).theme.should eq('brown')
user.settings(:dashboard).filter.should eq(false)
RailsSettings::SettingObject.count.should eq(1)
- RailsSettings::SettingObject.first.value.should == { :theme => 'brown' }.with_indifferent_access
+ RailsSettings::SettingObject.first.value.should == { 'theme' => 'brown' }
end
end
end

0 comments on commit 65b90dd

Please sign in to comment.