aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/adapters/postgresql/composite_test.rb6
-rw-r--r--activerecord/test/cases/adapters/postgresql/hstore_test.rb24
-rw-r--r--activerecord/test/cases/adapters/postgresql/json_test.rb1
-rw-r--r--activerecord/test/cases/attribute_decorators_test.rb2
-rw-r--r--activerecord/test/cases/dirty_test.rb6
-rw-r--r--activerecord/test/cases/reflection_test.rb2
6 files changed, 20 insertions, 21 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/composite_test.rb b/activerecord/test/cases/adapters/postgresql/composite_test.rb
index a925263098..0b48fe9af8 100644
--- a/activerecord/test/cases/adapters/postgresql/composite_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/composite_test.rb
@@ -90,7 +90,11 @@ class PostgresqlCompositeWithCustomOIDTest < ActiveRecord::TestCase
end
end
- def type_cast_for_write(value)
+ def type_cast_from_user(value)
+ value
+ end
+
+ def type_cast_for_database(value)
return if value.nil?
"(#{value.city},#{value.street})"
end
diff --git a/activerecord/test/cases/adapters/postgresql/hstore_test.rb b/activerecord/test/cases/adapters/postgresql/hstore_test.rb
index a6482786c7..3aac23a193 100644
--- a/activerecord/test/cases/adapters/postgresql/hstore_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/hstore_test.rb
@@ -106,6 +106,7 @@ class PostgresqlHstoreTest < ActiveRecord::TestCase
def test_cast_value_on_write
x = Hstore.new tags: {"bool" => true, "number" => 5}
+ assert_equal({"bool" => true, "number" => 5}, x.tags_before_type_cast)
assert_equal({"bool" => "true", "number" => "5"}, x.tags)
x.save
assert_equal({"bool" => "true", "number" => "5"}, x.reload.tags)
@@ -295,24 +296,18 @@ class PostgresqlHstoreTest < ActiveRecord::TestCase
assert_equal({ }, hstore.reload.tags)
end
- # FIXME: remove this lambda once `serialize` no longer issues a db connection.
- LAZY_MODELS = lambda do
- return if defined?(TagCollection)
-
- class TagCollection
- def initialize(hash); @hash = hash end
- def to_hash; @hash end
- def self.load(hash); new(hash) end
- def self.dump(object); object.to_hash end
- end
+ class TagCollection
+ def initialize(hash); @hash = hash end
+ def to_hash; @hash end
+ def self.load(hash); new(hash) end
+ def self.dump(object); object.to_hash end
+ end
- class HstoreWithSerialize < Hstore
- serialize :tags, TagCollection
- end
+ class HstoreWithSerialize < Hstore
+ serialize :tags, TagCollection
end
def test_hstore_with_serialized_attributes
- LAZY_MODELS.call
HstoreWithSerialize.create! tags: TagCollection.new({"one" => "two"})
record = HstoreWithSerialize.first
assert_instance_of TagCollection, record.tags
@@ -323,7 +318,6 @@ class PostgresqlHstoreTest < ActiveRecord::TestCase
end
def test_clone_hstore_with_serialized_attributes
- LAZY_MODELS.call
HstoreWithSerialize.create! tags: TagCollection.new({"one" => "two"})
record = HstoreWithSerialize.first
dupe = record.dup
diff --git a/activerecord/test/cases/adapters/postgresql/json_test.rb b/activerecord/test/cases/adapters/postgresql/json_test.rb
index 61d4e2b8ae..eab6049956 100644
--- a/activerecord/test/cases/adapters/postgresql/json_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/json_test.rb
@@ -68,6 +68,7 @@ class PostgresqlJSONTest < ActiveRecord::TestCase
def test_cast_value_on_write
x = JsonDataType.new payload: {"string" => "foo", :symbol => :bar}
+ assert_equal({"string" => "foo", :symbol => :bar}, x.payload_before_type_cast)
assert_equal({"string" => "foo", "symbol" => "bar"}, x.payload)
x.save
assert_equal({"string" => "foo", "symbol" => "bar"}, x.reload.payload)
diff --git a/activerecord/test/cases/attribute_decorators_test.rb b/activerecord/test/cases/attribute_decorators_test.rb
index f17cc02f53..416eb650f6 100644
--- a/activerecord/test/cases/attribute_decorators_test.rb
+++ b/activerecord/test/cases/attribute_decorators_test.rb
@@ -15,6 +15,8 @@ module ActiveRecord
def type_cast(value)
"#{super} #{@decoration}"
end
+
+ alias type_cast_from_user type_cast
end
setup do
diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb
index 2beac84fb1..87f24e32b2 100644
--- a/activerecord/test/cases/dirty_test.rb
+++ b/activerecord/test/cases/dirty_test.rb
@@ -616,17 +616,15 @@ class DirtyTest < ActiveRecord::TestCase
end
end
- test "defaults with type that implements `type_cast_for_write`" do
+ test "defaults with type that implements `type_cast_for_database`" do
type = Class.new(ActiveRecord::Type::Value) do
def type_cast(value)
value.to_i
end
- def type_cast_for_write(value)
+ def type_cast_for_database(value)
value.to_s
end
-
- alias type_cast_for_database type_cast_for_write
end
model_class = Class.new(ActiveRecord::Base) do
diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb
index 793e193329..70d52634f7 100644
--- a/activerecord/test/cases/reflection_test.rb
+++ b/activerecord/test/cases/reflection_test.rb
@@ -96,7 +96,7 @@ class ReflectionTest < ActiveRecord::TestCase
object = Object.new
assert_equal object, column.type_cast(object)
- assert_equal object, column.type_cast_for_write(object)
+ assert_equal object, column.type_cast_from_user(object)
assert_equal object, column.type_cast_for_database(object)
end