title: FactoryGirl-created record is not in database during test
body: <p>I'm trying to save users to the database and test that I can view the user's profile page with the following spec:</p>
  
  <pre><code>require 'spec_helper'
  
  describe "User pages" do
  
    subject { page }
  
    let(:user) { create(:user) }
    before { sign_in user }
  
    describe "profile page" do
      before { visit '/#/user' }
  
      it { should have_content("Name") }
      it { should have_content("Email address") }
      it { should have_content("Mobile phone") }
      it { current_path.should end_with('#/user') }
    end
  end
  </code></pre>
  
  <p>This is my user factory:</p>
  
  <pre><code>FactoryGirl.define do
  
    factory :service_company do
      name     "Service Company Test"
    end
  
    factory :yard do
      name     "Yard Test"
    end
  
    factory :service_company_account do
      association :yard, factory: :yard
      association :service_company, factory: :service_company
    end
  
    factory :user do
      name     "Pawan Raj"
      email    "pawan@example.com"
      phone    "5125552343"
      password "foobar"
      password_confirmation "foobar"
  
      association :service_company_account, factory: :service_company_account
    end
  end
  </code></pre>
  
  <p>In my users controller in the get_logged_in_user action (which is called in the above test), the Users table is always empty even after the create, and I can't understand why. When I look at the test.log file, the database seems to be saying the user already exists, but then it seems to insert the new user anyways. So one way or another, I would think the user SHOULD exist after this create() call. I probably have some fundamental misunderstanding of how FactoryGirl is supposed to work:</p>
  
  <pre><code>D, [2014-07-31T02:04:12.784184 #37634] DEBUG -- :   [1m[35mUser Exists (0.3ms)[0m  SELECT  1 AS one FROM "users"  WHERE LOWER("users"."email") = LOWER('pawan@example.com') LIMIT 1
  D, [2014-07-30T18:30:41.624291 #37146] DEBUG -- :   [1m[35mSQL (0.5ms)[0m  INSERT INTO "users" ("created_at", "email", "name", "password_digest", "phone", "remember_token", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id"  [["created_at", "2014-07-30 23:30:41.622815"], ["email", "pawan@example.com"], ["name", "Pawan Raj"], ["password_digest", "$2a$04$VbyWKSjHxAv1C1K7ZGqIh.RZzO/wbLhimQuLrdjVPTcStoGuFcKra"], ["phone", "5125552343"], ["remember_token", "529ae9a893f14df202410268095dde8e64670980"], ["updated_at", "2014-07-30 23:30:41.622815"]]
  D, [2014-07-31T02:04:12.788341 #37634] DEBUG -- :   [1m[35mSQL (0.3ms)[0m  UPDATE "service_company_accounts" SET "updated_at" = $1, "user_id" = $2 WHERE "service_company_accounts"."id" = 302  [["updated_at", "2014-07-31 07:04:12.785914"], ["user_id", 2848]]
  D, [2014-07-31T02:04:12.788696 #37634] DEBUG -- :   [1m[36m (0.1ms)[0m  [1mRELEASE SAVEPOINT active_record_1[0m
  </code></pre>
  
  <p>Also, for the record, this does all work fine when I use the site by hand. So it's a testing problem.</p>
  
  <p>EDIT: This is the entirety of my spec_helper.rb file in case it helps shed any light on the situation:</p>
  
  <pre><code>require 'rubygems'
  require 'spork'
  
  Spork.prefork do
    ENV["RAILS_ENV"] ||= 'test'
    require File.expand_path("../../config/environment", __FILE__)
    require 'capybara/rspec'
    require 'capybara/angular'
    require 'capybara/poltergeist'
    require 'rspec/rails'
    require 'rspec/autorun'
    require 'mailchimp'
    require 'paperclip/matchers'
  
    Capybara.javascript_driver = :poltergeist
    Capybara.default_driver = :poltergeist
  
    Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
  
    ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
  
    RSpec.configure do |config|
      config.fixture_path = "#{::Rails.root}/spec/fixtures"
      config.use_transactional_fixtures = true
      config.infer_base_class_for_anonymous_controllers = false
      config.order = "random"
      config.include Capybara::Angular::DSL
      config.include Paperclip::Shoulda::Matchers
    end
  end
  </code></pre>