ruby on rails - Undefined local variable or method 'session' in model test -


i'm creating ruby on rails application, , trying run test involving user model see if "remember me" feature works. i'm using rails' inbuilt cookies hash store cookies, , session hash store current session. i've run various tests (integration, model, , controller) use session variable, reason in particular case isn't being recognized.

nameerror: undefined local variable or method `session' #<usertest:0x0000000658b5c8> 

the error happens in else block in log_in_as method below:

test_helper.rb

...  def log_in_as(user, options = {})   password = options[:password] || 'password'   remember_me = options[:remember_me] || '1'    if integration_test?     post login_path, session: { email: user.email, password: password, remember_me: remember_me }   else     session[:user_id] = user.id   end end 

i call log_in_as in user test; both of these tests fail.

user_test.rb

require 'test_helper' ... test "login remembering"   log_in_as(@user, remember_me: '1')   assert_not_nil cookies['remember_token'] end  test "login without remembering"   log_in_as(@user, remember_me: '0')   assert_nil cookies['remember_token'] end ... 

and when remove line of code helper, error thrown saying cookies isn't recognized. issue here?

the session hash isn't available in models, in controllers , views , controller , view tests.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -