* Setting session from tests
@ 2010-02-09 7:07 misza222
2010-02-09 7:46 ` Daniel N
0 siblings, 1 reply; 3+ messages in thread
From: misza222 @ 2010-02-09 7:07 UTC (permalink / raw)
To: Rack Development
Hi,
How to set a session from within the tests?
I am using Rack::Test to test user authorization mechanism. I need to
make sure that user is redirected to the 'return_to' path which is
stored in a session.
post '/login', { :'user[email]' => @user.email, :'user[password]' =>
@user.password }
I tried creating mock request like
Rack::MockRequest.env_for("/login", {:"rack.session" => {:return_to =>
'/return_to'}})
and appending it as a 3rd parameter to the post method but no luck. It
was rather hit and miss approach as I don't really know how env is
organized :/
Can anyone help?
Cheers,
Michal
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Setting session from tests
2010-02-09 7:07 Setting session from tests misza222
@ 2010-02-09 7:46 ` Daniel N
2010-02-09 10:22 ` misza222
0 siblings, 1 reply; 3+ messages in thread
From: Daniel N @ 2010-02-09 7:46 UTC (permalink / raw)
To: rack-devel
When using rack test, it maintains a session for you.
In the one test you should post the login deets, and then visit the
URL you want to test.
The session should be sticky between requests from within the same test
hth
Daniel
On Tuesday, February 9, 2010, misza222 <misza222@gmail.com> wrote:
> Hi,
>
> How to set a session from within the tests?
> I am using Rack::Test to test user authorization mechanism. I need to
> make sure that user is redirected to the 'return_to' path which is
> stored in a session.
>
> post '/login', { :'user[email]' => @user.email, :'user[password]' =>
> @user.password }
>
> I tried creating mock request like
>
> Rack::MockRequest.env_for("/login", {:"rack.session" => {:return_to =>
> '/return_to'}})
>
> and appending it as a 3rd parameter to the post method but no luck. It
> was rather hit and miss approach as I don't really know how env is
> organized :/
>
> Can anyone help?
>
> Cheers,
>
> Michal
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Setting session from tests
2010-02-09 7:46 ` Daniel N
@ 2010-02-09 10:22 ` misza222
0 siblings, 0 replies; 3+ messages in thread
From: misza222 @ 2010-02-09 10:22 UTC (permalink / raw)
To: Rack Development
Thanks Daniel :)
On 9 Feb, 07:46, Daniel N <has....@gmail.com> wrote:
> When using rack test, it maintains a session for you.
>
> In the one test you should post the login deets, and then visit the
> URL you want to test.
>
> The session should be sticky between requests from within the same test
>
> hth
> Daniel
>
> On Tuesday, February 9, 2010, misza222 <misza...@gmail.com> wrote:
> > Hi,
>
> > How to set a session from within the tests?
> > I am using Rack::Test to test user authorization mechanism. I need to
> > make sure that user is redirected to the 'return_to' path which is
> > stored in a session.
>
> > post '/login', { :'user[email]' => @user.email, :'user[password]' =>
> > @user.password }
>
> > I tried creating mock request like
>
> > Rack::MockRequest.env_for("/login", {:"rack.session" => {:return_to =>
> > '/return_to'}})
>
> > and appending it as a 3rd parameter to the post method but no luck. It
> > was rather hit and miss approach as I don't really know how env is
> > organized :/
>
> > Can anyone help?
>
> > Cheers,
>
> > Michal
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-02-09 10:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-09 7:07 Setting session from tests misza222
2010-02-09 7:46 ` Daniel N
2010-02-09 10:22 ` misza222
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).