From d35999a7eec185f6b334bd3a4e3e3c4dd8464f15 Mon Sep 17 00:00:00 2001 From: Lee Mallabone Date: Wed, 6 Feb 2013 17:32:15 -0800 Subject: [PATCH] Add failing test to show behavior of custom serializer with nils. --- test/serialization_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/serialization_test.rb b/test/serialization_test.rb index 538101f7..06c531eb 100644 --- a/test/serialization_test.rb +++ b/test/serialization_test.rb @@ -63,6 +63,10 @@ class RenderJsonTest < ActionController::TestCase end end + class DummyCustomSerializer < ActiveModel::Serializer + attributes :id + end + class HypermediaSerializable def active_model_serializer HypermediaSerializer @@ -117,6 +121,11 @@ class RenderJsonTest < ActionController::TestCase render :json => ActiveSupport::JSON.encode(:hello => 'world') end + def render_json_nil_with_custom_serializer + render :json => nil, :serializer => DummyCustomSerializer + end + + def render_json_with_extra_options render :json => JsonRenderable.new, :except => [:c, :e] end @@ -216,6 +225,11 @@ class RenderJsonTest < ActionController::TestCase assert_equal '[]', @response.body end + def test_render_json_nil_with_custom_serializer + get :render_json_nil_with_custom_serializer + assert_equal 'null', @response.body + end + def test_render_json get :render_json_hello_world assert_equal '{"hello":"world"}', @response.body