Preserve cookies, so that we don't lose the session between requests. Make sure you are using the memory session store.
This commit is contained in:
parent
04261e66d8
commit
f74037e4da
@ -33,29 +33,38 @@ class Merb::Test::RspecStory
|
|||||||
|
|
||||||
#Session defines the following (used by webrat), but RspecStory doesn't. Merb's get/put/delete return a controller,
|
#Session defines the following (used by webrat), but RspecStory doesn't. Merb's get/put/delete return a controller,
|
||||||
#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.
|
||||||
|
def request_via_redirect(method,path,parameters={},headers={})
|
||||||
|
mycookies = @controller.cookies rescue nil #will be nil if no requests yet
|
||||||
|
@controller=self.send(method, path, parameters, headers) do |new_controller|
|
||||||
|
new_controller.cookies = mycookies
|
||||||
|
end
|
||||||
|
follow_redirect! while redirect?
|
||||||
|
status
|
||||||
|
end
|
||||||
|
|
||||||
def get_via_redirect(path, parameters = {}, headers = {})
|
def get_via_redirect(path, parameters = {}, headers = {})
|
||||||
@controller=get path, parameters, headers
|
request_via_redirect(:get,path,parameters,headers)
|
||||||
follow_redirect! while redirect?
|
|
||||||
status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def put_via_redirect(path, parameters = {}, headers = {})
|
def put_via_redirect(path, parameters = {}, headers = {})
|
||||||
@controller=put path, parameters, headers
|
request_via_redirect(:put,path,parameters,headers)
|
||||||
follow_redirect! while redirect?
|
|
||||||
status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_via_redirect(path, parameters = {}, headers = {})
|
def post_via_redirect(path, parameters = {}, headers = {})
|
||||||
@controller=post path, parameters, headers
|
request_via_redirect(:post,path,parameters,headers)
|
||||||
follow_redirect! while redirect?
|
|
||||||
status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_via_redirect(path, parameters = {}, headers = {})
|
def delete_via_redirect(path, parameters = {}, headers = {})
|
||||||
@controller=delete path, parameters, headers
|
request_via_redirect(:delete,path,parameters,headers)
|
||||||
follow_redirect! while redirect?
|
|
||||||
status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow_redirect!
|
def follow_redirect!
|
||||||
@controller=get @controller.headers["Location"]
|
mycookies = @controller.cookies rescue nil
|
||||||
|
@controller=get @controller.headers["Location"] do |new_controller|
|
||||||
|
new_controller.cookies=mycookies
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect?
|
def redirect?
|
||||||
@ -79,6 +88,13 @@ class Merb::Test::RspecStory
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Application < Merb::Controller
|
||||||
|
def cookies=(newcookies)
|
||||||
|
@_cookies = newcookies
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
#Other utilities used by Webrat that are present in Rails but not Merb. We can require heavy dependencies
|
#Other utilities used by Webrat that are present in Rails but not Merb. We can require heavy dependencies
|
||||||
#here because we're only loaded in Test mode.
|
#here because we're only loaded in Test mode.
|
||||||
require 'strscan'
|
require 'strscan'
|
||||||
|
Loading…
Reference in New Issue
Block a user