Use factoryGirl with js: true

What i have figured is that If i use factorygirl with js: true, the database becomes locked.
So i had to write this long scenario

 scenario "and see the question on the screen below" ,js: true do
    sign_in_admin(admin)
    create_event
    code = page.find('div span#code').text 
    click_link "Logout"
    fill_in "subscriber_code",with: code
    click_button "Join Event"
    fill_in "body",with: "Hi how are you?"
    click_button "Ask"
    click_link "Logout"
    sign_in_admin(admin)
    click_button "approve"
    click_link "Logout"
    fill_in "subscriber_code",with: code
    click_button "Join Event"
    page.should have_content "Hi how are you?"
    click_button "up"
    click_link "Logout"
    fill_in "subscriber_code",with: code
    click_button "Join Event"
    votes = page.find('#votes').text 
    expect(votes).to eq("1")
    click_button "up"
    expect(page).to have_button "down"
    click_button "down"
    click_link "Logout"
    fill_in "subscriber_code",with: code
    click_button "Join Event"
    votes = page.find('#votes').text 
    expect(votes).to eq("1")
   end

This is my databse_cleaner

config.before(:suite) do
DatabaseCleaner.clean_with :truncation
end

  config.use_transactional_fixtures = false
  
 config.include FactoryGirl::Syntax::Methods
  config.before :each do
    if Capybara.current_driver == :rack_test
      DatabaseCleaner.strategy = :transaction
    else
      DatabaseCleaner.strategy = :truncation
    end
    DatabaseCleaner.start
  end
     
  config.after do
    DatabaseCleaner.clean
  end

So how can I break the above scenario using FactoryGirl like question = create(:question) which currently is locking the database and also is giving RecordNotFound error.

Hi Charlie,

Are you using sqlite? I have run into concurrency issues and database locking with sqlite and js: true specs in the past. If so, I’d recommend you give postgres a try instead of sqlite.

Yes I am using sqlite. Ok let me give postgres a try then.

On the mac I get a strange error that server of postgres is not running when it is actually running using the GUI app I downloaded.

When I used to use Postgres.app, I found that I often (but frustratingly, not always) needed to declare this line in my database.yml to let Rails find the PG instance of Postgres.app:

host:localhost

One further note: unless you’re using Sqlite in production, you should whenever possible be trying to use the same database type in development and test that you use in production. While ActiveRecord is designed to be fairly portable across different database platforms, nothing is more frustrating than tracking down some weird Heisenbug that only exists in production due to a difference in RDBMS.