aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test/connection_test.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-04-29 03:14:36 +0000
committerRick Olson <technoweenie@gmail.com>2007-04-29 03:14:36 +0000
commitbd50d82f701c55d89b891ebd216ec84008b486c1 (patch)
tree5d9a4fc7dbf8e48088e66d2dc4de7ec76955f440 /activeresource/test/connection_test.rb
parent1162c29e308eb064c305a06262b8a47e2e0f1b48 (diff)
downloadrails-bd50d82f701c55d89b891ebd216ec84008b486c1.tar.gz
rails-bd50d82f701c55d89b891ebd216ec84008b486c1.tar.bz2
rails-bd50d82f701c55d89b891ebd216ec84008b486c1.zip
Add support for setting custom headers per ActiveResource model [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6624 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/test/connection_test.rb')
-rw-r--r--activeresource/test/connection_test.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb
index b434dd4012..67d5553e72 100644
--- a/activeresource/test/connection_test.rb
+++ b/activeresource/test/connection_test.rb
@@ -13,16 +13,21 @@ class ConnectionTest < Test::Unit::TestCase
@people_empty = [ ].to_xml(:root => 'people-empty-elements')
@matz = @matz.to_xml(:root => 'person')
@david = @david.to_xml(:root => 'person')
+ @header = {'key' => 'value'}
@default_request_headers = { 'Content-Type' => 'application/xml' }
ActiveResource::HttpMock.respond_to do |mock|
+ mock.get "/people/2.xml", @header, @david
mock.get "/people.xml", {}, @people
mock.get "/people_single_elements.xml", {}, @people_single
mock.get "/people_empty_elements.xml", {}, @people_empty
mock.get "/people/1.xml", {}, @matz
mock.put "/people/1.xml", {}, nil, 204
+ mock.put "/people/2.xml", {}, @header, 204
mock.delete "/people/1.xml", {}, nil, 200
+ mock.delete "/people/2.xml", @header, nil, 200
mock.post "/people.xml", {}, nil, 201, 'Location' => '/people/5.xml'
+ mock.post "/members.xml", {}, @header, 201, 'Location' => '/people/6.xml'
end
end
@@ -79,6 +84,11 @@ class ConnectionTest < Test::Unit::TestCase
assert_equal "Matz", matz["name"]
end
+ def test_get_with_header
+ david = @conn.get("/people/2.xml", @header)
+ assert_equal "David", david["name"]
+ end
+
def test_get_collection
people = @conn.get("/people.xml")
assert_equal "Matz", people[0]["name"]
@@ -100,16 +110,31 @@ class ConnectionTest < Test::Unit::TestCase
assert_equal "/people/5.xml", response["Location"]
end
+ def test_post_with_header
+ response = @conn.post("/members.xml", @header)
+ assert_equal "/people/6.xml", response["Location"]
+ end
+
def test_put
response = @conn.put("/people/1.xml")
assert_equal 204, response.code
end
+ def test_put_with_header
+ response = @conn.put("/people/2.xml", @header)
+ assert_equal 204, response.code
+ end
+
def test_delete
response = @conn.delete("/people/1.xml")
assert_equal 200, response.code
end
+ def test_delete_with_header
+ response = @conn.delete("/people/2.xml", @header)
+ assert_equal 200, response.code
+ end
+
protected
def assert_response_raises(klass, code)
assert_raise(klass, "Expected response code #{code} to raise #{klass}") do