diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-09-01 01:15:10 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-09-01 01:15:10 +0000 |
commit | 7749c9c2200ad190e3f9935c27f09ec9b95227f2 (patch) | |
tree | 5ef693429c4511957bee18bf20594b948bb3a249 /activeresource/test/http_mock.rb | |
parent | e278b72bf3238353906a6cb928410aaf712556f4 (diff) | |
download | rails-7749c9c2200ad190e3f9935c27f09ec9b95227f2.tar.gz rails-7749c9c2200ad190e3f9935c27f09ec9b95227f2.tar.bz2 rails-7749c9c2200ad190e3f9935c27f09ec9b95227f2.zip |
Major updates to ActiveResource, please see changelog and unit tests [Rick Olson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4890 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/test/http_mock.rb')
-rw-r--r-- | activeresource/test/http_mock.rb | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/activeresource/test/http_mock.rb b/activeresource/test/http_mock.rb index a4bc7e7cb2..75a54e71fe 100644 --- a/activeresource/test/http_mock.rb +++ b/activeresource/test/http_mock.rb @@ -2,6 +2,20 @@ require 'active_resource/connection' module ActiveResource class HttpMock + class Responder + def initialize(responses) + @responses = responses + end + + for method in [ :post, :put, :get, :delete ] + module_eval <<-EOE + def #{method}(path, body = nil, status = 200, headers = {}) + @responses[Request.new(:#{method}, path, nil)] = Response.new(body || {}, status, headers) + end + EOE + end + end + class << self def requests @@requests ||= [] @@ -11,11 +25,12 @@ module ActiveResource @@responses ||= {} end - def respond_to(pairs) + def respond_to(pairs = {}) reset! pairs.each do |(path, response)| responses[path] = response end + yield Responder.new(responses) if block_given? end def reset! @@ -42,7 +57,7 @@ module ActiveResource class Request attr_accessor :path, :method, :body - def initialize(method, path, body = nil) + def initialize(method, path, body = nil, headers = nil) @method, @path, @body = method, path, body end @@ -64,15 +79,24 @@ module ActiveResource end class Response - attr_accessor :body, :code + attr_accessor :body, :code, :headers - def initialize(body, code = 200) - @body, @code = body, code + def initialize(body, code = 200, headers = nil) + @body, @code, @headers = body, code, headers end def success? (200..299).include?(code) end + + def [](key) + headers[key] + end + + def []=(key, value) + headers[key] = value + end + end class Connection |