diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2012-05-30 23:18:08 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2012-05-30 23:21:57 -0700 |
commit | d5354af1149496e1a6ebccc5434dbba3bde86265 (patch) | |
tree | 0bd3a964279fcfd2f4be4225637e76b1efc1907e /activerecord/test/cases | |
parent | 9a30d82d455a5b8578f7dfe6f5f9479fca44c78f (diff) | |
download | rails-d5354af1149496e1a6ebccc5434dbba3bde86265.tar.gz rails-d5354af1149496e1a6ebccc5434dbba3bde86265.tar.bz2 rails-d5354af1149496e1a6ebccc5434dbba3bde86265.zip |
Fix backward compatibility with stored Hash values. Wrap coders to convert serialized values to indifferent access.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/store_test.rb | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/activerecord/test/cases/store_test.rb b/activerecord/test/cases/store_test.rb index 3a5d84df9f..79476ed2a4 100644 --- a/activerecord/test/cases/store_test.rb +++ b/activerecord/test/cases/store_test.rb @@ -3,8 +3,10 @@ require 'models/admin' require 'models/admin/user' class StoreTest < ActiveRecord::TestCase + fixtures :'admin/users' + setup do - @john = Admin::User.create(:name => 'John Doe', :color => 'black', :remember_login => true, :height => 'tall', :is_a_good_guy => true) + @john = Admin::User.create!(:name => 'John Doe', :color => 'black', :remember_login => true, :height => 'tall', :is_a_good_guy => true) end test "reading store attributes through accessors" do @@ -52,18 +54,19 @@ class StoreTest < ActiveRecord::TestCase end test "convert store attributes from Hash to HashWithIndifferentAccess saving the data and access attributes indifferently" do - @john.json_data = { :height => 'tall', 'weight' => 'heavy' } - assert_equal true, @john.json_data.instance_of?(Hash) - assert_equal 'tall', @john.json_data[:height] - assert_equal nil, @john.json_data['height'] - assert_equal nil, @john.json_data[:weight] - assert_equal 'heavy', @john.json_data['weight'] - @john.height = 'low' - assert_equal true, @john.json_data.instance_of?(HashWithIndifferentAccess) - assert_equal 'low', @john.json_data[:height] - assert_equal 'low', @john.json_data['height'] - assert_equal 'heavy', @john.json_data[:weight] - assert_equal 'heavy', @john.json_data['weight'] + user = Admin::User.find_by_name('Jamis') + assert_equal 'symbol', user.settings[:symbol] + assert_equal 'symbol', user.settings['symbol'] + assert_equal 'string', user.settings[:string] + assert_equal 'string', user.settings['string'] + assert_equal true, user.settings.instance_of?(ActiveSupport::HashWithIndifferentAccess) + + user.height = 'low' + assert_equal 'symbol', user.settings[:symbol] + assert_equal 'symbol', user.settings['symbol'] + assert_equal 'string', user.settings[:string] + assert_equal 'string', user.settings['string'] + assert_equal true, user.settings.instance_of?(ActiveSupport::HashWithIndifferentAccess) end test "convert store attributes from any format other than Hash or HashWithIndifferent access losing the data" do |