aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-06-04 06:43:30 -0600
committerSean Griffin <sean@thoughtbot.com>2014-06-04 06:43:30 -0600
commitc3bd7b57e359788b26674683fb5b1518c75f6bb1 (patch)
tree779f73e9319dedede9ee5c557be91a7cb92fec4a /activerecord/test/cases
parent0329d59a65a5afbf57de83670e3e05e4a73815e4 (diff)
downloadrails-c3bd7b57e359788b26674683fb5b1518c75f6bb1.tar.gz
rails-c3bd7b57e359788b26674683fb5b1518c75f6bb1.tar.bz2
rails-c3bd7b57e359788b26674683fb5b1518c75f6bb1.zip
Bring type casting behavior of hstore/json in line with serialized
`@raw_attributes` should not contain the type-cast, mutable version of the value.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/adapters/postgresql/hstore_test.rb10
-rw-r--r--activerecord/test/cases/adapters/postgresql/json_test.rb8
-rw-r--r--activerecord/test/cases/base_test.rb2
-rw-r--r--activerecord/test/cases/persistence_test.rb4
-rw-r--r--activerecord/test/cases/serialized_attribute_test.rb2
5 files changed, 22 insertions, 4 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/hstore_test.rb b/activerecord/test/cases/adapters/postgresql/hstore_test.rb
index 1fef4899be..78134ff316 100644
--- a/activerecord/test/cases/adapters/postgresql/hstore_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/hstore_test.rb
@@ -152,6 +152,16 @@ class PostgresqlHstoreTest < ActiveRecord::TestCase
assert_equal "GMT", y.timezone
end
+ def test_yaml_round_trip_with_store_accessors
+ x = Hstore.new(language: "fr", timezone: "GMT")
+ assert_equal "fr", x.language
+ assert_equal "GMT", x.timezone
+
+ y = YAML.load(YAML.dump(x))
+ assert_equal "fr", y.language
+ assert_equal "GMT", y.timezone
+ end
+
def test_gen1
assert_equal(%q(" "=>""), @column.class.hstore_to_string({' '=>''}))
end
diff --git a/activerecord/test/cases/adapters/postgresql/json_test.rb b/activerecord/test/cases/adapters/postgresql/json_test.rb
index 03b546119d..61d4e2b8ae 100644
--- a/activerecord/test/cases/adapters/postgresql/json_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/json_test.rb
@@ -147,6 +147,14 @@ class PostgresqlJSONTest < ActiveRecord::TestCase
assert_equal "320×480", y.resolution
end
+ def test_yaml_round_trip_with_store_accessors
+ x = JsonDataType.new(resolution: "320×480")
+ assert_equal "320×480", x.resolution
+
+ y = YAML.load(YAML.dump(x))
+ assert_equal "320×480", y.resolution
+ end
+
def test_update_all
json = JsonDataType.create! payload: { "one" => "two" }
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index d65c4b0638..f01901514e 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -1495,7 +1495,7 @@ class BasicsTest < ActiveRecord::TestCase
}
types = { 'author_name' => typecast.new }
- topic = Topic.allocate.init_with 'attributes' => attrs,
+ topic = Topic.allocate.init_with 'raw_attributes' => attrs,
'column_types' => types
assert_equal 't.lo', topic.author_name
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb
index bc5ccd0fe9..6b24fd8205 100644
--- a/activerecord/test/cases/persistence_test.rb
+++ b/activerecord/test/cases/persistence_test.rb
@@ -251,7 +251,7 @@ class PersistenceTest < ActiveRecord::TestCase
def test_create_columns_not_equal_attributes
topic = Topic.allocate.init_with(
- 'attributes' => {
+ 'raw_attributes' => {
'title' => 'Another New Topic',
'does_not_exist' => 'test'
}
@@ -302,7 +302,7 @@ class PersistenceTest < ActiveRecord::TestCase
topic_reloaded = Topic.allocate
topic_reloaded.init_with(
- 'attributes' => topic.attributes.merge('does_not_exist' => 'test')
+ 'raw_attributes' => topic.attributes.merge('does_not_exist' => 'test')
)
topic_reloaded.title = 'A New Topic'
assert_nothing_raised { topic_reloaded.save }
diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb
index 5ea62c9f59..debb227303 100644
--- a/activerecord/test/cases/serialized_attribute_test.rb
+++ b/activerecord/test/cases/serialized_attribute_test.rb
@@ -31,7 +31,7 @@ class SerializedAttributeTest < ActiveRecord::TestCase
def test_serialized_attribute_init_with
topic = Topic.allocate
- topic.init_with('attributes' => { 'content' => '--- foo' })
+ topic.init_with('raw_attributes' => { 'content' => '--- foo' })
assert_equal 'foo', topic.content
end