Make sure that PUTS and DELETES are handled correctly in merb
This commit is contained in:
parent
94f0086a55
commit
580a301984
@ -35,8 +35,13 @@ class Merb::Test::RspecStory
|
|||||||
#which is where we get our status and response from.
|
#which is where we get our status and response from.
|
||||||
#
|
#
|
||||||
#We have to preserve cookies like this, or the session is lost.
|
#We have to preserve cookies like this, or the session is lost.
|
||||||
|
#
|
||||||
|
#While (in a web application) a PUT is modelled as a POST with a parameter _method,
|
||||||
|
#this close to the metal we need to make sure that we actually hit the underlying 'put' method,
|
||||||
|
#so we rewrite 'method'.
|
||||||
def request_via_redirect(method,path,parameters={},headers={})
|
def request_via_redirect(method,path,parameters={},headers={})
|
||||||
mycookies = @controller.cookies rescue nil #will be nil if no requests yet
|
method = parameters["_method"] if !parameters["_method"].blank?
|
||||||
|
mycookies = defined?(@controller) ? @controller.cookies : nil #will be nil if no requests yet
|
||||||
@controller=self.send(method, path, parameters, headers) do |new_controller|
|
@controller=self.send(method, path, parameters, headers) do |new_controller|
|
||||||
new_controller.cookies = mycookies
|
new_controller.cookies = mycookies
|
||||||
end
|
end
|
||||||
|
@ -9,6 +9,8 @@ class ClicksButtonTest < Test::Unit::TestCase
|
|||||||
@session.stubs(:current_page).returns(@page)
|
@session.stubs(:current_page).returns(@page)
|
||||||
@response = mock
|
@response = mock
|
||||||
@session.stubs(:response).returns(@response)
|
@session.stubs(:response).returns(@response)
|
||||||
|
@controller = mock
|
||||||
|
@controller.stubs(:status).returns(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_fail_if_no_buttons
|
def test_should_fail_if_no_buttons
|
||||||
@ -349,4 +351,29 @@ class ClicksButtonTest < Test::Unit::TestCase
|
|||||||
@session.expects(:get_via_redirect).with("/login", "user" => {"email" => ""})
|
@session.expects(:get_via_redirect).with("/login", "user" => {"email" => ""})
|
||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_should_use_put_method_when_needed
|
||||||
|
@response.stubs(:body).returns(<<-EOS)
|
||||||
|
<form method="put" action="/login">
|
||||||
|
<input id="user_email" name="user[email]" value="test@example.com" type="hidden" />
|
||||||
|
<input type="submit" />
|
||||||
|
</form>
|
||||||
|
EOS
|
||||||
|
@session.stubs(:redirect?).returns(false)
|
||||||
|
@session.expects(:put).returns(@controller)
|
||||||
|
@session.clicks_button
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_use_delete_method_when_needed
|
||||||
|
@response.stubs(:body).returns(<<-EOS)
|
||||||
|
<form method="delete" action="/login">
|
||||||
|
<input id="user_email" name="user[email]" value="test@example.com" type="hidden" />
|
||||||
|
<input type="submit" />
|
||||||
|
</form>
|
||||||
|
EOS
|
||||||
|
@session.stubs(:redirect?).returns(false)
|
||||||
|
@session.expects(:delete).returns(@controller)
|
||||||
|
@session.clicks_button
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user