authentication - authenticating mock user when testing rails 3.1 -


i trying test rails 3.1 app (i'm learning testing go) , , stuck how authenticate user since sets session tests aren't using browser session undefined method. using new rails 3.1 has_secure password.

how can correctly set , test authentication, test parts of app require user authenticated?

my set follows:

rspec 2 capybara guard factory_girl

thank you!

when you're doing controller tests sessions hash last parameter. let's have in session controller tests:

post :create, :user => { :email => "blah@blah.com" }, :color => "red" 

this sends through 2 params through controller: params[:user] , params[:color].

what session variables ? session variables sent through last parameter. if wanted set last_logged_in session variable, change above to:

post :create, {:user => { :email => "blah@blah.com" }, :color => "red"}, {:last_logged_in => time.now} 

notice set braces put around user , color parameters. have access session[:last_logged_in] in controller.

i highly recommend reading ror guides. here's 1 controller testing: http://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -