提交 b9f8501f 编写于 作者: G Gaston Ramos 提交者: José Valim

- Fix ActiveResource::HttpMock.respond_to replace the response

  if it has the same request
Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 243513f4
......@@ -171,6 +171,8 @@ def responses
def respond_to(*args) #:yields: mock
pairs = args.first || {}
reset! if args.last.class != FalseClass
delete_responses_to_replace pairs.to_a
responses.concat pairs.to_a
if block_given?
yield Responder.new(responses)
......@@ -179,6 +181,13 @@ def respond_to(*args) #:yields: mock
end
end
def delete_responses_to_replace(new_responses)
new_responses.each{|nr|
request_to_remove = nr[0]
@@responses = responses.delete_if{|r| r[0] == request_to_remove}
}
end
# Deletes all logged requests and responses.
def reset!
requests.clear
......
......@@ -140,6 +140,21 @@ class HttpMockTest < ActiveSupport::TestCase
assert_equal 2, ActiveResource::HttpMock.responses.length
end
test "allows you to add replace the existing reponese with the same path" do
ActiveResource::HttpMock.respond_to do |mock|
mock.send(:get, "/people/1", {}, "XML1")
end
assert_equal 1, ActiveResource::HttpMock.responses.length
matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
get_matz = ActiveResource::Request.new(:get, '/people/1', nil)
ok_response = ActiveResource::Response.new(matz, 200, {})
ActiveResource::HttpMock.respond_to({get_matz => ok_response}, false)
assert_equal 1, ActiveResource::HttpMock.responses.length
end
def request(method, path, headers = {}, body = nil)
if [:put, :post].include? method
@http.send(method, path, body, headers)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册