Permalink
Browse files

Make ActiveResource#exists? work [#3020 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
1 parent 29a5549 commit 323f58f19f052d77e972b94767ab133d58fdcd90 @rubymerchant rubymerchant committed with lifo Aug 9, 2009
Showing with 11 additions and 2 deletions.
  1. +3 −2 activeresource/lib/active_resource/connection.rb
  2. +8 −0 activeresource/test/base_test.rb
@@ -75,7 +75,8 @@ class Connection
HTTP_FORMAT_HEADER_NAMES = { :get => 'Accept',
:put => 'Content-Type',
:post => 'Content-Type',
- :delete => 'Accept'
+ :delete => 'Accept',
+ :head => 'Accept'
}
attr_reader :site, :user, :password, :timeout, :proxy, :ssl_options
@@ -155,7 +156,7 @@ def post(path, body = '', headers = {})
# Execute a HEAD request.
# Used to obtain meta-information about resources, such as whether they exist and their size (via response headers).
def head(path, headers = {})
- request(:head, path, build_request_headers(headers))
+ request(:head, path, build_request_headers(headers, :head))
end
@@ -965,6 +965,14 @@ def to_param
end
end
+ def test_exists_without_http_mock
+ http = Net::HTTP.new(Person.site.host, Person.site.port)
+ ActiveResource::Connection.any_instance.expects(:http).returns(http)
+ http.expects(:request).returns(ActiveResource::Response.new(""))
+
+ assert Person.exists?('not-mocked')
+ end
+
def test_to_xml
matz = Person.find(1)
xml = matz.encode

0 comments on commit 323f58f

Please sign in to comment.