aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/lib/active_resource
diff options
context:
space:
mode:
Diffstat (limited to 'activeresource/lib/active_resource')
-rw-r--r--activeresource/lib/active_resource/base.rb8
-rw-r--r--activeresource/lib/active_resource/connection.rb6
-rw-r--r--activeresource/lib/active_resource/http_mock.rb4
3 files changed, 15 insertions, 3 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index eea6259a64..97baa46682 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -436,7 +436,13 @@ module ActiveResource
# Note.exists(1349)
# # => false
def exists?(id, options = {})
- id && !find_single(id, options).nil?
+ if id
+ prefix_options, query_options = split_options(options[:params])
+ path = element_path(id, prefix_options, query_options)
+ response = connection.head(path, headers)
+ response.code == 200
+ end
+ # id && !find_single(id, options).nil?
rescue ActiveResource::ResourceNotFound
false
end
diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb
index 2bf83b1615..e4e6da50c9 100644
--- a/activeresource/lib/active_resource/connection.rb
+++ b/activeresource/lib/active_resource/connection.rb
@@ -101,6 +101,12 @@ module ActiveResource
request(:post, path, body.to_s, build_request_headers(headers))
end
+ # Execute a HEAD request.
+ # Used to ...
+ def head(path, headers= {})
+ request(:head, path, build_request_headers(headers))
+ end
+
private
# Makes request to remote service.
diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb
index d70364c5eb..d1c1412575 100644
--- a/activeresource/lib/active_resource/http_mock.rb
+++ b/activeresource/lib/active_resource/http_mock.rb
@@ -9,7 +9,7 @@ module ActiveResource
@responses = responses
end
- for method in [ :post, :put, :get, :delete ]
+ for method in [ :post, :put, :get, :delete, :head ]
module_eval <<-EOE, __FILE__, __LINE__
def #{method}(path, request_headers = {}, body = nil, status = 200, response_headers = {})
@responses[Request.new(:#{method}, path, nil, request_headers)] = Response.new(body || "", status, response_headers)
@@ -56,7 +56,7 @@ module ActiveResource
EOE
end
- for method in [ :get, :delete ]
+ for method in [ :get, :delete, :head ]
module_eval <<-EOE, __FILE__, __LINE__
def #{method}(path, headers)
request = ActiveResource::Request.new(:#{method}, path, nil, headers)