aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test/format_test.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-12-28 17:03:58 +0000
committerRick Olson <technoweenie@gmail.com>2007-12-28 17:03:58 +0000
commitc54b915825b034b431b4b0cdb28f8ca00fca808d (patch)
treebbc4f216661139f0134e12005c5bfaadb02f894b /activeresource/test/format_test.rb
parent90d75e5109cb3e2fd172711b479ab29bda249544 (diff)
downloadrails-c54b915825b034b431b4b0cdb28f8ca00fca808d.tar.gz
rails-c54b915825b034b431b4b0cdb28f8ca00fca808d.tar.bz2
rails-c54b915825b034b431b4b0cdb28f8ca00fca808d.zip
Support agnostic formats when calling custom methods. Closes #10635 [joerichsen]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8502 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/test/format_test.rb')
-rw-r--r--activeresource/test/format_test.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/activeresource/test/format_test.rb b/activeresource/test/format_test.rb
index 609030250e..c2d3a08682 100644
--- a/activeresource/test/format_test.rb
+++ b/activeresource/test/format_test.rb
@@ -29,6 +29,40 @@ class FormatTest < Test::Unit::TestCase
end
end
+ def test_formats_on_custom_collection_method
+ for format in [ :json, :xml ]
+ using_format(Person, format) do
+ ActiveResource::HttpMock.respond_to.get "/people/retrieve.#{format}?name=David", {}, ActiveResource::Formats[format].encode([@david])
+ remote_programmers = Person.get(:retrieve, :name => 'David')
+ assert_equal 1, remote_programmers.size
+ assert_equal @david[:id], remote_programmers[0]['id']
+ assert_equal @david[:name], remote_programmers[0]['name']
+ end
+ end
+ end
+
+ def test_formats_on_custom_element_method
+ for format in [ :json, :xml ]
+ using_format(Person, format) do
+ ActiveResource::HttpMock.respond_to do |mock|
+ mock.get "/people/2.#{format}", {}, ActiveResource::Formats[format].encode(@david)
+ mock.get "/people/2/shallow.#{format}", {}, ActiveResource::Formats[format].encode(@david)
+ end
+ remote_programmer = Person.find(2).get(:shallow)
+ assert_equal @david[:id], remote_programmer['id']
+ assert_equal @david[:name], remote_programmer['name']
+ end
+ end
+
+ for format in [ :json, :xml ]
+ ryan = ActiveResource::Formats[format].encode({ :name => 'Ryan' })
+ using_format(Person, format) do
+ ActiveResource::HttpMock.respond_to.post "/people/new/register.#{format}", {}, ryan, 201, 'Location' => "/people/5.#{format}"
+ remote_ryan = Person.new(:name => 'Ryan')
+ assert_equal ActiveResource::Response.new(ryan, 201, {'Location' => "/people/5.#{format}"}), remote_ryan.post(:register)
+ end
+ end
+ end
private
def using_format(klass, mime_type_reference)