From 9f8116fb778ab4b90592d0a9ab88316132f00a78 Mon Sep 17 00:00:00 2001 From: Gaurish Sharma Date: Fri, 9 Aug 2013 04:32:00 +0530 Subject: Add tests for ActiveModel::Serializers::JSON#as_json ordering --- activemodel/test/cases/serializers/json_serialization_test.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'activemodel/test') diff --git a/activemodel/test/cases/serializers/json_serialization_test.rb b/activemodel/test/cases/serializers/json_serialization_test.rb index f0347081ee..476ba3d8c5 100644 --- a/activemodel/test/cases/serializers/json_serialization_test.rb +++ b/activemodel/test/cases/serializers/json_serialization_test.rb @@ -155,12 +155,21 @@ class JsonSerializationTest < ActiveModel::TestCase end end - test "as_json should keep the default order in the hash" do + test "as_json should keep the MRI default order in the hash" do + skip "on JRuby as order is different" if defined? JRUBY_VERSION json = @contact.as_json assert_equal %w(name age created_at awesome preferences), json.keys end + test "as_json should keep the JRuby default order in the hash" do + skip "on MRI as order is different" unless defined? JRUBY_VERSION + json = @contact.as_json + + assert_equal %w(age name created_at awesome preferences), json.keys + end + + test "from_json should work without a root (class attribute)" do json = @contact.to_json result = Contact.new.from_json(json) -- cgit v1.2.3 From 90c450f6cd792187eeb1e039e0ff3722beb8b5c1 Mon Sep 17 00:00:00 2001 From: Gaurish Sharma Date: Fri, 9 Aug 2013 15:27:21 +0530 Subject: Avoid Skip in test, have a unified test for order --- .../test/cases/serializers/json_serialization_test.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'activemodel/test') diff --git a/activemodel/test/cases/serializers/json_serialization_test.rb b/activemodel/test/cases/serializers/json_serialization_test.rb index 476ba3d8c5..8eb7a58e90 100644 --- a/activemodel/test/cases/serializers/json_serialization_test.rb +++ b/activemodel/test/cases/serializers/json_serialization_test.rb @@ -155,21 +155,18 @@ class JsonSerializationTest < ActiveModel::TestCase end end - test "as_json should keep the MRI default order in the hash" do - skip "on JRuby as order is different" if defined? JRUBY_VERSION + test "as_json should keep the default order in the hash" do json = @contact.as_json - assert_equal %w(name age created_at awesome preferences), json.keys - end - - test "as_json should keep the JRuby default order in the hash" do - skip "on MRI as order is different" unless defined? JRUBY_VERSION - json = @contact.as_json + attributes_order = %w(name age created_at awesome preferences) + #Order on JRUBY is different + if defined? JRUBY_VERSION + attributes_order = %w(age name created_at awesome preferences) + end - assert_equal %w(age name created_at awesome preferences), json.keys + assert_equal attributes_order, json.keys end - test "from_json should work without a root (class attribute)" do json = @contact.to_json result = Contact.new.from_json(json) -- cgit v1.2.3 From c40111c346b91dcf05a2d1b2b7d46525f045989e Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sun, 18 Aug 2013 02:36:41 -0500 Subject: Refactor serialization test for hash order --- .../test/cases/serializers/json_serialization_test.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'activemodel/test') diff --git a/activemodel/test/cases/serializers/json_serialization_test.rb b/activemodel/test/cases/serializers/json_serialization_test.rb index 8eb7a58e90..00a636e633 100644 --- a/activemodel/test/cases/serializers/json_serialization_test.rb +++ b/activemodel/test/cases/serializers/json_serialization_test.rb @@ -155,16 +155,15 @@ class JsonSerializationTest < ActiveModel::TestCase end end - test "as_json should keep the default order in the hash" do + test "as_json should keep the default order in the hash according to used engine" do json = @contact.as_json - attributes_order = %w(name age created_at awesome preferences) - #Order on JRUBY is different - if defined? JRUBY_VERSION - attributes_order = %w(age name created_at awesome preferences) + # Check for original order only on MRI and sort for other implementations + if RUBY_ENGINE == 'ruby' + assert_equal %w(name age created_at awesome preferences), json.keys + else + assert_equal %w(age awesome created_at name preferences), json.keys.sort end - - assert_equal attributes_order, json.keys end test "from_json should work without a root (class attribute)" do -- cgit v1.2.3 From 99e33c03b7ccad3254c787a19bc7082e23dbcd27 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sun, 18 Aug 2013 16:39:31 -0500 Subject: Dont' check for any order in hash since we aren't sorting it and this is determinated only by the used interpreter --- activemodel/test/cases/serializers/json_serialization_test.rb | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'activemodel/test') diff --git a/activemodel/test/cases/serializers/json_serialization_test.rb b/activemodel/test/cases/serializers/json_serialization_test.rb index 00a636e633..e4f5e61e91 100644 --- a/activemodel/test/cases/serializers/json_serialization_test.rb +++ b/activemodel/test/cases/serializers/json_serialization_test.rb @@ -155,17 +155,6 @@ class JsonSerializationTest < ActiveModel::TestCase end end - test "as_json should keep the default order in the hash according to used engine" do - json = @contact.as_json - - # Check for original order only on MRI and sort for other implementations - if RUBY_ENGINE == 'ruby' - assert_equal %w(name age created_at awesome preferences), json.keys - else - assert_equal %w(age awesome created_at name preferences), json.keys.sort - end - end - test "from_json should work without a root (class attribute)" do json = @contact.to_json result = Contact.new.from_json(json) -- cgit v1.2.3 From 9f478deaab796f2464c8f105d16b55ef0b02a64d Mon Sep 17 00:00:00 2001 From: Rajarshi Das Date: Fri, 23 Aug 2013 15:40:09 +0530 Subject: remove unused instance variable --- activemodel/test/cases/serializers/xml_serialization_test.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'activemodel/test') diff --git a/activemodel/test/cases/serializers/xml_serialization_test.rb b/activemodel/test/cases/serializers/xml_serialization_test.rb index c4cfb0c255..11ee17bb27 100644 --- a/activemodel/test/cases/serializers/xml_serialization_test.rb +++ b/activemodel/test/cases/serializers/xml_serialization_test.rb @@ -53,8 +53,7 @@ class XmlSerializationTest < ActiveModel::TestCase @contact.address.city = "Springfield" @contact.address.apt_number = 35 @contact.friends = [Contact.new, Contact.new] - @related_contact = SerializableContact.new - @contact.contact = @related_contact + @contact.contact = SerializableContact.new end test "should serialize default root" do -- cgit v1.2.3