aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/store_test.rb29
-rw-r--r--activerecord/test/fixtures/admin/users.yml3
2 files changed, 19 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
diff --git a/activerecord/test/fixtures/admin/users.yml b/activerecord/test/fixtures/admin/users.yml
index 6f11f2509e..e2884beda5 100644
--- a/activerecord/test/fixtures/admin/users.yml
+++ b/activerecord/test/fixtures/admin/users.yml
@@ -5,3 +5,6 @@ david:
jamis:
name: Jamis
account: signals37
+ settings:
+ :symbol: symbol
+ string: string