diff options
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/serialization_test.rb | 6 | ||||
-rw-r--r-- | activemodel/test/cases/serializers/json_serialization_test.rb | 10 |
2 files changed, 13 insertions, 3 deletions
diff --git a/activemodel/test/cases/serialization_test.rb b/activemodel/test/cases/serialization_test.rb index 29bcdeae67..1ec915d245 100644 --- a/activemodel/test/cases/serialization_test.rb +++ b/activemodel/test/cases/serialization_test.rb @@ -77,12 +77,12 @@ class SerializationTest < ActiveModel::TestCase assert_equal expected , @user.serializable_hash(:methods => [:bar]) end - def test_should_not_call_methods_for_attributes - def @user.name + def test_should_use_read_attribute_for_serialization + def @user.read_attribute_for_serialization(n) "Jon" end - expected = { "name" => "David" } + expected = { "name" => "Jon" } assert_equal expected, @user.serializable_hash(:only => :name) end diff --git a/activemodel/test/cases/serializers/json_serialization_test.rb b/activemodel/test/cases/serializers/json_serialization_test.rb index 40fdcf20ca..a754d610b9 100644 --- a/activemodel/test/cases/serializers/json_serialization_test.rb +++ b/activemodel/test/cases/serializers/json_serialization_test.rb @@ -206,4 +206,14 @@ class JsonSerializationTest < ActiveModel::TestCase assert_no_match %r{"preferences":}, json end + test "custom as_json options should be extendible" do + def @contact.as_json(options = {}); super(options.merge(:only => [:name])); end + json = @contact.to_json + + assert_match %r{"name":"Konata Izumi"}, json + assert_no_match %r{"created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))}}, json + assert_no_match %r{"awesome":}, json + assert_no_match %r{"preferences":}, json + end + end |