User creation into tests breaks require_no_user #85

freegenie opened this Issue Dec 25, 2009 · 3 comments


None yet
3 participants

I had a very hard time trying to figure out what was causing my test to fail. I was creating a user inside a test with Factory_girl, and this was causing the UserSession.find to get populated.

context "an anonymous user" do 
    setup do 
    should "request a password reset by username" do             
      user = Factory.create(:user, :username => "mike")            
      UserSession.find.destroy # I had to introduce this to ensure nobody is logged in!
      post :reset_request, :username => 'mike'                        

Is it an expected behaviour? If so, maybe it's worth two lines in the quickstart or in the test app.


nathany commented Jun 23, 2014

@freegenie You should have to call UserSession.create(user) for the UserSession to exist.

Does this still happen? If you run just a single test, does it happen? Maybe the session is leaking from a different test.


tiegz commented Jun 23, 2014

Ahhh, I might have run into this as well before. It might actually be session maintenance when the persistence token is being set for the first time when the user model is created in the factory. Either turning maintain_sessions=false in your model, or, this patch might work (and if so, maybe we should patch authlogic):

class User
  def update_sessions?
    super && !persistence_token_was.nil?

honestly, you can close this issue for me. I don't even remember.

nathany closed this Jun 23, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment