Skip to content

Commit

Permalink
Make ActiveResource#exists? work [#3020 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
rubymerchant authored and lifo committed Aug 9, 2009
1 parent 29a5549 commit 323f58f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions activeresource/lib/active_resource/connection.rb
Expand Up @@ -75,7 +75,8 @@ class Connection
HTTP_FORMAT_HEADER_NAMES = { :get => 'Accept', HTTP_FORMAT_HEADER_NAMES = { :get => 'Accept',
:put => 'Content-Type', :put => 'Content-Type',
:post => 'Content-Type', :post => 'Content-Type',
:delete => 'Accept' :delete => 'Accept',
:head => 'Accept'
} }


attr_reader :site, :user, :password, :timeout, :proxy, :ssl_options attr_reader :site, :user, :password, :timeout, :proxy, :ssl_options
Expand Down Expand Up @@ -155,7 +156,7 @@ def post(path, body = '', headers = {})
# Execute a HEAD request. # Execute a HEAD request.
# Used to obtain meta-information about resources, such as whether they exist and their size (via response headers). # Used to obtain meta-information about resources, such as whether they exist and their size (via response headers).
def head(path, headers = {}) def head(path, headers = {})
request(:head, path, build_request_headers(headers)) request(:head, path, build_request_headers(headers, :head))
end end




Expand Down
8 changes: 8 additions & 0 deletions activeresource/test/base_test.rb
Expand Up @@ -965,6 +965,14 @@ def to_param
end end
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 def test_to_xml
matz = Person.find(1) matz = Person.find(1)
xml = matz.encode xml = matz.encode
Expand Down

0 comments on commit 323f58f

Please sign in to comment.