diff options
author | Jatinder Singh <jatinder.saundh@gmail.com> | 2009-08-09 22:24:50 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-08-09 22:24:57 +0100 |
commit | 1fc1986d6deacd71ec4bea2287d9cfed6123b898 (patch) | |
tree | 619342aaca4a0837048c54e9d420f6bf2f7cc672 | |
parent | 0ec64bea9293dd21588359da80bb43b82886cf2c (diff) | |
download | rails-1fc1986d6deacd71ec4bea2287d9cfed6123b898.tar.gz rails-1fc1986d6deacd71ec4bea2287d9cfed6123b898.tar.bz2 rails-1fc1986d6deacd71ec4bea2287d9cfed6123b898.zip |
Make ActiveResource#exists? work [#3020 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
-rw-r--r-- | activeresource/lib/active_resource/connection.rb | 5 | ||||
-rw-r--r-- | 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 c08b7272ae..884c425c1d 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -13,7 +13,8 @@ module ActiveResource 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 @@ -93,7 +94,7 @@ module ActiveResource # Executes 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 2e1236cab4..cba675177a 100644 --- a/activeresource/test/base_test.rb +++ b/activeresource/test/base_test.rb @@ -966,6 +966,14 @@ class BaseTest < Test::Unit::TestCase 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 |