diff options
author | Jose and Yehuda <wycats@gmail.com> | 2011-10-15 18:37:12 +0200 |
---|---|---|
committer | Jose and Yehuda <wycats@gmail.com> | 2011-10-15 18:40:38 +0200 |
commit | 7a28498b55913aa0fd1d3529909ab57eaf64af0e (patch) | |
tree | d26461bf010228a22956517e6317e421861d39d1 /activemodel/test/cases/serializer_test.rb | |
parent | 322f47898e80af3fcdc3cb3db35e177d8216a2d2 (diff) | |
download | rails-7a28498b55913aa0fd1d3529909ab57eaf64af0e.tar.gz rails-7a28498b55913aa0fd1d3529909ab57eaf64af0e.tar.bz2 rails-7a28498b55913aa0fd1d3529909ab57eaf64af0e.zip |
Fix nil has_one association
Diffstat (limited to 'activemodel/test/cases/serializer_test.rb')
-rw-r--r-- | activemodel/test/cases/serializer_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activemodel/test/cases/serializer_test.rb b/activemodel/test/cases/serializer_test.rb index 168a77838f..165c1d2490 100644 --- a/activemodel/test/cases/serializer_test.rb +++ b/activemodel/test/cases/serializer_test.rb @@ -259,4 +259,22 @@ class SerializerTest < ActiveModel::TestCase ] }, serializer.as_json) end + + def test_associations_with_nil_association + user = User.new + blog = Blog.new + + json = BlogSerializer.new(blog, user).as_json + assert_equal({ + :author => nil + }, json) + + serializer = Class.new(BlogSerializer) do + def serializable_hash + attributes.merge(association_ids) + end + end + + assert_equal({ :author => nil }, serializer.new(blog, user).as_json) + end end |