From 3dd4638bf78bc5e5aa7d33fc8119b89263a8c352 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Thu, 25 Jun 2015 23:03:56 -0500 Subject: [PATCH] Account for different handling of symbol keys in Rails 4.0 Comparing as a JSON string vs. as the Hash that is convert to JSON works around the different Hash representations. This likely has to do with the introduction of config.action_dispatch.perform_deep_munge in Rails 4.1 See Rails issue 13420 1) Failure: ActiveModel::Serializer::Adapter::Json::HasManyTestTest#test_has_many_with_no_serializer [active_model_serializers/test/adapter/json/has_many_test.rb:36]: --- expected +++ actual @@ -1 +1 @@ -{:id=>42, :tags=>[{"attributes"=>{"id"=>1, "name"=>"#hash_tag"}}]} +{:id=>42, :tags=>[{"attributes"=>{:id=>1, :name=>"#hash_tag"}}]} 2) Failure: ActiveModel::Serializer::AssociationsTest#test_has_many_with_no_serializer [active_model_serializers/test/serializers/associations_test.rb:74]: --- expected +++ actual @@ -1 +1 @@ -[{"attributes"=>{"name"=>"#hashtagged"}}] +[{"attributes"=>{:name=>"#hashtagged"}}] --- test/adapter/json/has_many_test.rb | 2 +- test/serializers/associations_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/adapter/json/has_many_test.rb b/test/adapter/json/has_many_test.rb index eeff41df8..a88b2f544 100644 --- a/test/adapter/json/has_many_test.rb +++ b/test/adapter/json/has_many_test.rb @@ -38,7 +38,7 @@ def test_has_many_with_no_serializer tags: [ {"attributes"=>{"id"=>1, "name"=>"#hash_tag"}} ] - }, adapter.serializable_hash[:post_with_tags]) + }.to_json, adapter.serializable_hash[:post_with_tags].to_json) end end end diff --git a/test/serializers/associations_test.rb b/test/serializers/associations_test.rb index f92e5a906..04681d2c4 100644 --- a/test/serializers/associations_test.rb +++ b/test/serializers/associations_test.rb @@ -71,7 +71,7 @@ def test_has_many_with_no_serializer PostWithTagsSerializer.new(@post).each_association do |name, serializer, options| assert_equal name, :tags assert_equal serializer, nil - assert_equal [{ attributes: { name: "#hashtagged" }}].as_json, options[:virtual_value] + assert_equal [{ attributes: { name: "#hashtagged" }}].to_json, options[:virtual_value].to_json end end