Where are the factory_girl records?

Posted by gmile on Stack Overflow See other posts from Stack Overflow or by gmile
Published on 2010-03-25T20:22:34Z Indexed on 2010/03/25 20:33 UTC
Read the original article Hit count: 739

I'm trying to perform an integration test via Watir and RSpec. So, I created a test file within /integration and wrote a test, which adds a test user into a base via factory_girl.

The problem is — I can't actually perform a login with my test user. The test I wrote looks as following:

...

before(:each)
  @user = Factory(:user)
  @browser = FireWatir::Firefox.new
end

it "should login"
  @browser.text_field(:id, "username").set(@user.username)
  @browser.text_field(:id, "password").set(@user.password)
  @browser.button(:id, "get_in").click
end

...

As I'm starting the test and see a "performance" in browser, it always fires up a Username is not valid error.

I've started an investigation, and did a small trick. First of all I've started to have doubts if the factory actually creates the user in DB. So after the immediate call to factory I've put some puts User.find stuff only to discover that the user is actually in DB. Ok, but as user still couldn't have logged in I've decided to see if he's present in DB with my own eyes.

I've added a sleep right after a factory call, and went to see what's in the DB at the moment. I was crushed to see that the user is actually missing there! How come? Still, when I'm trying to output a user within the code, he is actually being fetched from somewhere. So where does the records, made by factory_girl within a runtime lie? Is it test or dev DB? I don't get it.

I've 10 times checked if I'm running my Mongrel in test mode (does it matter? I think it does, as I'm trying to tun an integration test) and if my database.yml holds the correct connection specific data.

I'm using an authlogic, if that can give any clue (no, putting activate_authlogic doesn't work here).

© Stack Overflow or respective owner

Related posts about factory-girl

Related posts about database