aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test/connection_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activeresource/test/connection_test.rb')
-rw-r--r--activeresource/test/connection_test.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb
index 0744e327e6..efde099c90 100644
--- a/activeresource/test/connection_test.rb
+++ b/activeresource/test/connection_test.rb
@@ -1,10 +1,20 @@
require "#{File.dirname(__FILE__)}/abstract_unit"
+require 'base64'
class ConnectionTest < Test::Unit::TestCase
Response = Struct.new(:code)
def setup
@conn = ActiveResource::Connection.new('http://localhost')
+ @matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person')
+ @david = { :id => 2, :name => 'David' }.to_xml(:root => 'person')
+ @default_request_headers = { 'Content-Type' => 'application/xml' }
+ ActiveResource::HttpMock.respond_to do |mock|
+ mock.get "/people/1.xml", {}, @matz
+ mock.put "/people/1.xml", {}, nil, 204
+ mock.delete "/people/1.xml", {}, nil, 200
+ mock.post "/people.xml", {}, nil, 201, 'Location' => '/people/5.xml'
+ end
end
def test_handle_response
@@ -38,7 +48,37 @@ class ConnectionTest < Test::Unit::TestCase
assert_response_raises ActiveResource::ConnectionError, code
end
end
+
+ def test_site_accessor_accepts_uri_or_string_argument
+ site = URI.parse("http://localhost")
+
+ assert_nothing_raised { @conn.site = "http://localhost" }
+ assert_equal site, @conn.site
+ assert_nothing_raised { @conn.site = site }
+ assert_equal site, @conn.site
+ end
+
+ def test_get
+ matz = @conn.get("/people/1.xml")
+ assert_equal "Matz", matz["person"]["name"]
+ end
+
+ def test_post
+ response = @conn.post("/people.xml")
+ assert_equal "/people/5.xml", response["Location"]
+ end
+
+ def test_put
+ response = @conn.put("/people/1.xml")
+ assert_equal 204, response.code
+ end
+
+ def test_delete
+ response = @conn.delete("/people/1.xml")
+ assert_equal 200, response.code
+ end
+
protected
def assert_response_raises(klass, code)
assert_raise(klass, "Expected response code #{code} to raise #{klass}") do