Setting sessions in controller testing

Hi Guys,

I’m writing some controller tests in rspec and one of them needs a
session
to be set. Does anyone know how to set a session in rails tests?

If it is a normal controller or non-Webkit test, you can access the
controller variable directly (I think with @controller), so you can just
set session vars directly like:

@controller.session[:current_user] = @my_user

If you are writing a capybara webkit test, you don’t have direct access
to the same ruby environment where the session runs, but you can use
this excellent gem to access it:

If you’re using devise, there’s patterns for doing this both in and out
of webkit. Checkout this for an explanation:

To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/a4281a9d-e8ae-46f2-9d0f-ee2f04109eb6%40googlegroups.com
https://groups.google.com/d/msgid/rubyonrails-talk/a4281a9d-e8ae-46f2-9d0f-ee2f04109eb6%40googlegroups.com?utm_medium=email&utm_source=footer.
For more options, visit https://groups.google.com/d/optout
https://groups.google.com/d/optout.


Jason Fleetwood-Boldt
[email protected]

All material © Jason Fleetwood-Boldt 2014. Public conversations may be
turned into blog posts (original poster information will be made
anonymous). Email [email protected] with questions/concerns about
this.

Hello muchira,

Are you using devise gem for login ?

On Thu, Dec 4, 2014 at 12:22 PM, bertly_the_coder [email protected]
wrote:

To post to this group, send email to [email protected].
To view this discussion on the web visit

https://groups.google.com/d/msgid/rubyonrails-talk/a4281a9d-e8ae-46f2-9d0f-ee2f04109eb6%40googlegroups.com

https://groups.google.com/d/msgid/rubyonrails-talk/a4281a9d-e8ae-46f2-9d0f-ee2f04109eb6%40googlegroups.com?utm_medium=email&utm_source=footer

.
For more options, visit https://groups.google.com/d/optout.