aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test/cases/base/custom_methods_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activeresource/test/cases/base/custom_methods_test.rb')
-rw-r--r--activeresource/test/cases/base/custom_methods_test.rb56
1 files changed, 28 insertions, 28 deletions
diff --git a/activeresource/test/cases/base/custom_methods_test.rb b/activeresource/test/cases/base/custom_methods_test.rb
index 0fbf94bc0e..3eaa9b1c5b 100644
--- a/activeresource/test/cases/base/custom_methods_test.rb
+++ b/activeresource/test/cases/base/custom_methods_test.rb
@@ -5,32 +5,32 @@ require 'active_support/core_ext/hash/conversions'
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')
+ @matz = { :person => { :id => 1, :name => 'Matz' } }.to_json
+ @matz_deep = { :person => { :id => 1, :name => 'Matz', :other => 'other' } }.to_json
+ @matz_array = { :people => [{ :person => { :id => 1, :name => 'Matz' } }] }.to_json
+ @ryan = { :person => { :name => 'Ryan' } }.to_json
+ @addy = { :address => { :id => 1, :street => '12345 Street' } }.to_json
+ @addy_deep = { :address => { :id => 1, :street => '12345 Street', :zip => "27519" } }.to_json
ActiveResource::HttpMock.respond_to do |mock|
- 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_array
- mock.get "/people/managers.xml", {}, @matz_array
- mock.post "/people/hire.xml?name=Matz", {}, nil, 201
- 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
- mock.delete "/people/deactivate.xml?name=Matz", {}, nil, 200
- mock.delete "/people/1/deactivate.xml", {}, nil, 200
- mock.post "/people/new/register.xml", {}, @ryan, 201, 'Location' => '/people/5.xml'
- mock.post "/people/1/register.xml", {}, @matz, 201
- mock.get "/people/1/addresses/1.xml", {}, @addy
- mock.get "/people/1/addresses/1/deep.xml", {}, @addy_deep
- mock.put "/people/1/addresses/1/normalize_phone.xml?locale=US", {}, nil, 204
- mock.put "/people/1/addresses/sort.xml?by=name", {}, nil, 204
- mock.post "/people/1/addresses/new/link.xml", {}, { :street => '12345 Street' }.to_xml(:root => 'address'), 201, 'Location' => '/people/1/addresses/2.xml'
+ mock.get "/people/1.json", {}, @matz
+ mock.get "/people/1/shallow.json", {}, @matz
+ mock.get "/people/1/deep.json", {}, @matz_deep
+ mock.get "/people/retrieve.json?name=Matz", {}, @matz_array
+ mock.get "/people/managers.json", {}, @matz_array
+ mock.post "/people/hire.json?name=Matz", {}, nil, 201
+ mock.put "/people/1/promote.json?position=Manager", {}, nil, 204
+ mock.put "/people/promote.json?name=Matz", {}, nil, 204, {}
+ mock.put "/people/sort.json?by=name", {}, nil, 204
+ mock.delete "/people/deactivate.json?name=Matz", {}, nil, 200
+ mock.delete "/people/1/deactivate.json", {}, nil, 200
+ mock.post "/people/new/register.json", {}, @ryan, 201, 'Location' => '/people/5.json'
+ mock.post "/people/1/register.json", {}, @matz, 201
+ mock.get "/people/1/addresses/1.json", {}, @addy
+ mock.get "/people/1/addresses/1/deep.json", {}, @addy_deep
+ mock.put "/people/1/addresses/1/normalize_phone.json?locale=US", {}, nil, 204
+ mock.put "/people/1/addresses/sort.json?by=name", {}, nil, 204
+ mock.post "/people/1/addresses/new/link.json", {}, { :address => { :street => '12345 Street' } }.to_json, 201, 'Location' => '/people/1/addresses/2.json'
end
Person.user = nil
@@ -81,14 +81,14 @@ class CustomMethodsTest < Test::Unit::TestCase
def test_custom_new_element_method
# Test POST against a new element URL
ryan = Person.new(:name => 'Ryan')
- assert_equal ActiveResource::Response.new(@ryan, 201, {'Location' => '/people/5.xml'}), ryan.post(:register)
- expected_request = ActiveResource::Request.new(:post, '/people/new/register.xml', @ryan)
+ assert_equal ActiveResource::Response.new(@ryan, 201, { 'Location' => '/people/5.json' }), ryan.post(:register)
+ expected_request = ActiveResource::Request.new(:post, '/people/new/register.json', @ryan)
assert_equal expected_request.body, ActiveResource::HttpMock.requests.first.body
# Test POST against a nested collection URL
addy = StreetAddress.new(:street => '123 Test Dr.', :person_id => 1)
- assert_equal ActiveResource::Response.new({ :street => '12345 Street' }.to_xml(:root => 'address'),
- 201, {'Location' => '/people/1/addresses/2.xml'}),
+ assert_equal ActiveResource::Response.new({ :address => { :street => '12345 Street' } }.to_json,
+ 201, { 'Location' => '/people/1/addresses/2.json' }),
addy.post(:link)
matz = Person.find(1)