Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

User creation into tests breaks require_no_user #85

Closed
freegenie opened this Issue · 3 comments

3 participants

@freegenie

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 
        activate_authlogic 
    end 
    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'                        
      ....
    end
end

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

@nathany

@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
Collaborator

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?
  end
end
@freegenie

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

@nathany nathany closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.