aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorAndrey Voronkov <voronkovaa@gmail.com>2012-05-09 19:20:14 +0400
committerAndrey Voronkov <voronkovaa@gmail.com>2012-05-09 19:20:14 +0400
commit3c0bf0435cfbc7a349faec5e1b5631e506b5dc70 (patch)
treea56031a9fbe8fef1d3459b7912e9dffb0e6a7d9c /activerecord/test/cases
parentfed97091b9546d369a240d10b184793d49247dd3 (diff)
downloadrails-3c0bf0435cfbc7a349faec5e1b5631e506b5dc70.tar.gz
rails-3c0bf0435cfbc7a349faec5e1b5631e506b5dc70.tar.bz2
rails-3c0bf0435cfbc7a349faec5e1b5631e506b5dc70.zip
Custom coders support for ActiveRecord::Store. JSON, YAML, Marshal can be used out of the box.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/store_test.rb36
1 files changed, 35 insertions, 1 deletions
diff --git a/activerecord/test/cases/store_test.rb b/activerecord/test/cases/store_test.rb
index 40520d6da2..e1d0f1f799 100644
--- a/activerecord/test/cases/store_test.rb
+++ b/activerecord/test/cases/store_test.rb
@@ -4,7 +4,7 @@ require 'models/admin/user'
class StoreTest < ActiveRecord::TestCase
setup do
- @john = Admin::User.create(:name => 'John Doe', :color => 'black', :remember_login => 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
@@ -40,4 +40,38 @@ class StoreTest < ActiveRecord::TestCase
@john.remember_login = false
assert_equal false, @john.remember_login
end
+
+ test "reading store attributes through accessors encoded with JSON" do
+ assert_equal 'tall', @john.height
+ assert_nil @john.weight
+ end
+
+ test "writing store attributes through accessors encoded with JSON" do
+ @john.height = 'short'
+ @john.weight = 'heavy'
+
+ assert_equal 'short', @john.height
+ assert_equal 'heavy', @john.weight
+ end
+
+ test "accessing attributes not exposed by accessors encoded with JSON" do
+ @john.json_data['somestuff'] = 'somecoolstuff'
+ @john.save
+
+ assert_equal 'somecoolstuff', @john.reload.json_data['somestuff']
+ end
+
+ test "updating the store will mark it as changed encoded with JSON" do
+ @john.height = 'short'
+ assert @john.json_data_changed?
+ end
+
+ test "object initialization with not nullable column encoded with JSON" do
+ assert_equal true, @john.is_a_good_guy
+ end
+
+ test "writing with not nullable column encoded with JSON" do
+ @john.is_a_good_guy = false
+ assert_equal false, @john.is_a_good_guy
+ end
end