From 42fa2714c5005bb50679bf9a081d8bf0774f7eec Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 4 May 2010 22:27:17 -0300 Subject: Make use of to_xml and to_json in tests Signed-off-by: Jeremy Kemper --- activeresource/test/cases/base_test.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'activeresource/test/cases') diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index 2ed7e1c95f..e5f556962b 100644 --- a/activeresource/test/cases/base_test.rb +++ b/activeresource/test/cases/base_test.rb @@ -1009,7 +1009,10 @@ class BaseTest < Test::Unit::TestCase def test_to_xml matz = Person.find(1) - xml = matz.encode + encode = matz.encode + xml = matz.to_xml + + assert encode, xml assert xml.include?('') assert xml.include?('Matz') assert xml.include?('1') @@ -1019,9 +1022,11 @@ class BaseTest < Test::Unit::TestCase Person.include_root_in_json = true Person.format = :json joe = Person.find(6) - json = joe.encode + encode = joe.encode + json = joe.to_json Person.format = :xml + assert encode, json assert_match %r{^\{"person":\{"person":\{}, json assert_match %r{"id":6}, json assert_match %r{"name":"Joe"}, json -- cgit v1.2.3 From bea3c26833ad3e1e94f7331e0553a4e2164e7de5 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 6 May 2010 12:35:08 -0300 Subject: Make ActiveResource serialize XML correctly when element_name is set. [#4529] Signed-off-by: Jeremy Kemper --- activeresource/test/cases/base_test.rb | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'activeresource/test/cases') diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index e5f556962b..5df1f411a4 100644 --- a/activeresource/test/cases/base_test.rb +++ b/activeresource/test/cases/base_test.rb @@ -1018,6 +1018,23 @@ class BaseTest < Test::Unit::TestCase assert xml.include?('1') end + def test_to_xml_with_element_name + old_elem_name = Person.element_name + matz = Person.find(1) + Person.element_name = 'ruby_creator' + encode = matz.encode + xml = matz.to_xml + + assert encode, xml + assert xml.include?('') + assert xml.include?('') + assert xml.include?('Matz') + assert xml.include?('1') + assert xml.include?('') + ensure + Person.element_name = old_elem_name + end + def test_to_json Person.include_root_in_json = true Person.format = :json @@ -1033,6 +1050,25 @@ class BaseTest < Test::Unit::TestCase assert_match %r{\}\}\}$}, json end + def test_to_json_with_element_name + old_elem_name = Person.element_name + Person.include_root_in_json = true + Person.format = :json + joe = Person.find(6) + Person.element_name = 'ruby_creator' + encode = joe.encode + json = joe.to_json + Person.format = :xml + + assert encode, json + assert_match %r{^\{"ruby_creator":\{"person":\{}, json + assert_match %r{"id":6}, json + assert_match %r{"name":"Joe"}, json + assert_match %r{\}\}\}$}, json + ensure + Person.element_name = old_elem_name + end + def test_to_param_quacks_like_active_record new_person = Person.new assert_nil new_person.to_param -- cgit v1.2.3 From 7ffe76046ad142377bf6b286f4477b09513d1e37 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 14 May 2010 09:34:33 -0300 Subject: ActiveResource shouldn't consider modules in the path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#4529 state:committed] Signed-off-by: José Valim --- activeresource/test/cases/base_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activeresource/test/cases') diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index 5df1f411a4..4e21e84596 100644 --- a/activeresource/test/cases/base_test.rb +++ b/activeresource/test/cases/base_test.rb @@ -2,6 +2,7 @@ require 'abstract_unit' require "fixtures/person" require "fixtures/customer" require "fixtures/street_address" +require "fixtures/sound" require "fixtures/beast" require "fixtures/proxy" require 'active_support/json' @@ -563,6 +564,10 @@ class BaseTest < Test::Unit::TestCase assert_equal '/people/Greg/addresses/1.xml', StreetAddress.element_path(1, 'person_id' => 'Greg') end + def test_module_element_path + assert_equal '/sounds/1.xml', Asset::Sound.element_path(1) + end + def test_custom_element_path_with_redefined_to_param Person.module_eval do alias_method :original_to_param_element_path, :to_param -- cgit v1.2.3