From 9e4461438f8ce584b635aca35579c36537a340ca Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 21 Jun 2007 15:07:15 +0000 Subject: Added proper handling of arrays. Closes #8537 [hasmanyjosh] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7074 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activeresource/test/base/custom_methods_test.rb | 5 +++-- activeresource/test/base_test.rb | 16 ++++++++++------ activeresource/test/connection_test.rb | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) (limited to 'activeresource/test') diff --git a/activeresource/test/base/custom_methods_test.rb b/activeresource/test/base/custom_methods_test.rb index f591c14260..0e1c00c478 100644 --- a/activeresource/test/base/custom_methods_test.rb +++ b/activeresource/test/base/custom_methods_test.rb @@ -6,6 +6,7 @@ class CustomMethodsTest < Test::Unit::TestCase def setup @matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person') @matz_deep = { :id => 1, :name => 'Matz', :other => 'other' }.to_xml(:root => 'person') + @matz_array = [{ :id => 1, :name => 'Matz' }].to_xml(:root => 'people') @ryan = { :name => 'Ryan' }.to_xml(:root => 'person') @addy = { :id => 1, :street => '12345 Street' }.to_xml(:root => 'address') @addy_deep = { :id => 1, :street => '12345 Street', :zip => "27519" }.to_xml(:root => 'address') @@ -15,8 +16,8 @@ class CustomMethodsTest < Test::Unit::TestCase mock.get "/people/1.xml", {}, @matz mock.get "/people/1/shallow.xml", {}, @matz mock.get "/people/1/deep.xml", {}, @matz_deep - mock.get "/people/retrieve.xml?name=Matz", {}, "#{@matz}" - mock.get "/people/managers.xml", {}, "#{@matz}" + mock.get "/people/retrieve.xml?name=Matz", {}, @matz_array + mock.get "/people/managers.xml", {}, @matz_array mock.put "/people/1/promote.xml?position=Manager", {}, nil, 204 mock.put "/people/promote.xml?name=Matz", {}, nil, 204, {} mock.put "/people/sort.xml?by=name", {}, nil, 204 diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb index 6c924447de..328d3ae133 100644 --- a/activeresource/test/base_test.rb +++ b/activeresource/test/base_test.rb @@ -9,6 +9,10 @@ class BaseTest < Test::Unit::TestCase @david = { :id => 2, :name => 'David' }.to_xml(:root => 'person') @addy = { :id => 1, :street => '12345 Street' }.to_xml(:root => 'address') @default_request_headers = { 'Content-Type' => 'application/xml' } + @rick = { :name => "Rick", :age => 25 }.to_xml(:root => "person") + @people = [{ :id => 1, :name => 'Matz' }, { :id => 2, :name => 'David' }].to_xml(:root => 'people') + @people_david = [{ :id => 2, :name => 'David' }].to_xml(:root => 'people') + @addresses = [{ :id => 1, :street => '12345 Street' }].to_xml(:root => 'addresses') ActiveResource::HttpMock.respond_to do |mock| mock.get "/people/1.xml", {}, @matz @@ -18,9 +22,9 @@ class BaseTest < Test::Unit::TestCase mock.delete "/people/1.xml", {}, nil, 200 mock.delete "/people/2.xml", {}, nil, 400 mock.get "/people/99.xml", {}, nil, 404 - mock.post "/people.xml", {}, "Rick25", 201, 'Location' => '/people/5.xml' - mock.get "/people.xml", {}, "#{@matz}#{@david}" - mock.get "/people/1/addresses.xml", {}, "#{@addy}" + mock.post "/people.xml", {}, @rick, 201, 'Location' => '/people/5.xml' + mock.get "/people.xml", {}, @people + mock.get "/people/1/addresses.xml", {}, @addresses mock.get "/people/1/addresses/1.xml", {}, @addy mock.get "/people/1/addresses/2.xml", {}, nil, 404 mock.get "/people/2/addresses/1.xml", {}, nil, 404 @@ -225,7 +229,7 @@ class BaseTest < Test::Unit::TestCase end def test_find_all_by_from - ActiveResource::HttpMock.respond_to { |m| m.get "/companies/1/people.xml", {}, "#{@david}" } + ActiveResource::HttpMock.respond_to { |m| m.get "/companies/1/people.xml", {}, @people_david } people = Person.find(:all, :from => "/companies/1/people.xml") assert_equal 1, people.size @@ -233,7 +237,7 @@ class BaseTest < Test::Unit::TestCase end def test_find_all_by_from_with_options - ActiveResource::HttpMock.respond_to { |m| m.get "/companies/1/people.xml", {}, "#{@david}" } + ActiveResource::HttpMock.respond_to { |m| m.get "/companies/1/people.xml", {}, @people_david } people = Person.find(:all, :from => "/companies/1/people.xml") assert_equal 1, people.size @@ -241,7 +245,7 @@ class BaseTest < Test::Unit::TestCase end def test_find_all_by_symbol_from - ActiveResource::HttpMock.respond_to { |m| m.get "/people/managers.xml", {}, "#{@david}" } + ActiveResource::HttpMock.respond_to { |m| m.get "/people/managers.xml", {}, @people_david } people = Person.find(:all, :from => :managers) assert_equal 1, people.size diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb index 13b518d782..24893f8cd3 100644 --- a/activeresource/test/connection_test.rb +++ b/activeresource/test/connection_test.rb @@ -115,7 +115,7 @@ class ConnectionTest < Test::Unit::TestCase def test_get_collection_empty people = @conn.get("/people_empty_elements.xml") - assert_nil people + assert_equal [], people end def test_post -- cgit v1.2.3