aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test/http_mock.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-12-05 19:12:51 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-12-05 19:12:51 +0000
commit7370e54cc4d6b298a29383bf943b277bcfb730aa (patch)
tree5585190cfb324c1dbfcdebf69e431cc901e45960 /activeresource/test/http_mock.rb
parent0ee0c1b2aae3cb90869c79235470e6b69296feeb (diff)
downloadrails-7370e54cc4d6b298a29383bf943b277bcfb730aa.tar.gz
rails-7370e54cc4d6b298a29383bf943b277bcfb730aa.tar.bz2
rails-7370e54cc4d6b298a29383bf943b277bcfb730aa.zip
*_path instance methods. Check for missing/invalid site uri. http_mock response takes message arg, extracts numeric code. Tests log to test/debug.log
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5680 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/test/http_mock.rb')
-rw-r--r--activeresource/test/http_mock.rb32
1 files changed, 16 insertions, 16 deletions
diff --git a/activeresource/test/http_mock.rb b/activeresource/test/http_mock.rb
index 1166a56af7..e22a61e6a7 100644
--- a/activeresource/test/http_mock.rb
+++ b/activeresource/test/http_mock.rb
@@ -2,13 +2,13 @@ require 'active_resource/connection'
module ActiveResource
class InvalidRequestError < StandardError; end
-
+
class HttpMock
class Responder
def initialize(responses)
@responses = responses
end
-
+
for method in [ :post, :put, :get, :delete ]
module_eval <<-EOE
def #{method}(path, request_headers = {}, body = nil, status = 200, response_headers = {})
@@ -50,7 +50,7 @@ module ActiveResource
end
EOE
end
-
+
for method in [ :get, :delete ]
module_eval <<-EOE
def #{method}(path, headers)
@@ -60,7 +60,7 @@ module ActiveResource
end
EOE
end
-
+
def initialize(site)
@site = site
end
@@ -68,7 +68,7 @@ module ActiveResource
class Request
attr_accessor :path, :method, :body, :headers
-
+
def initialize(method, path, body = nil, headers = {})
@method, @path, @body, @headers = method, path, body, headers
@headers.update('Content-Type' => 'application/xml')
@@ -77,27 +77,28 @@ module ActiveResource
def ==(other_request)
other_request.hash == hash
end
-
+
def eql?(other_request)
self == other_request
end
-
+
def to_s
"<#{method.to_s.upcase}: #{path} [#{headers}] (#{body})>"
end
-
+
def hash
"#{path}#{method}#{headers}".hash
end
end
-
+
class Response
- attr_accessor :body, :code, :headers
-
- def initialize(body, code = 200, headers = {})
- @body, @code, @headers = body, code, headers
+ attr_accessor :body, :message, :code, :headers
+
+ def initialize(body, message = 200, headers = {})
+ @body, @message, @headers = body, message.to_s, headers
+ @code = @message[0,3].to_i
end
-
+
def success?
(200..299).include?(code)
end
@@ -105,11 +106,10 @@ module ActiveResource
def [](key)
headers[key]
end
-
+
def []=(key, value)
headers[key] = value
end
-
end
class Connection