views:

31

answers:

3

How can I manually set session while calling app.get() in script/console?

For example I want to access an authorised page, but it always redirects me to sign-in page. How can I set the session before calling app.get() so that I can make an authorised call to that page?

A: 

depends on what you are using for session authentication. if you do app.class, you will see that app is an ActionController::Integration::Session. What you need to do is authenticate yourself, then hitting your restricted pages should work

Matt Briggs
A: 

Here is an ugly workaround that I did.

#Type in script/console
include ActionController::TestProcess
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@controller = SomeController.new
get 'action', {}, {:signed => 42} #action, params, session
#now @response has the updated response object.

Before doing another get()/post() etc make sure you reset @controller by calling @controller = SomeController.new, or else @response doesn't seem to get updated on subsequent requests.

Vikrant Chaudhary
A: 

http://guides.rubyonrails.org/testing.html

This will help u..