ruby on rails - Skiping callbacks during my tests -


i have following callback before_action :forbid_logged_user, only: [:new, :create] prevent user access (new) login page , submit (create) log in credentials when he's logged in.

def forbid_logged_user   if logged_in?     flash[:danger] = "you're logged in"     redirect_to current_user   end end 

however, have integration test execute post request (create) simulate log in.

test "login without remembering"   log_in_as(@user, remember_me: '1')   log_in_as(@user, remember_me: '0')   assert_empty cookies['remember_token'] end 

as can imagine, post request ignored because of call back, therefore returning false in test. indeed, test works when remove before_action callback create action, don't want to.

how can skip callback during tests?

thanks,

you can check environment skip callback in test environment, example:

if !rails.env.test? && logged_in?   flash[:danger] = "you're logged in"   redirect_to current_user end 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -