From 323f58f19f052d77e972b94767ab133d58fdcd90 Mon Sep 17 00:00:00 2001 From: Jatinder Singh Date: Sun, 9 Aug 2009 22:24:50 +0100 Subject: [PATCH] Make ActiveResource#exists? work [#3020 state:resolved] Signed-off-by: Pratik Naik --- activeresource/lib/active_resource/connection.rb | 5 +++-- activeresource/test/base_test.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index 01bcbe7e217f9..acb9ff58ab551 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.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 diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb index 26020bd4f8966..e725d8ecc402e 100644 --- a/activeresource/test/base_test.rb +++ b/activeresource/test/base_test.rb @@ -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