I'm trying to get some RSpec examples working with Capybara using the javascript driver (w/ Webkit or Poltergeist) but there's a locking issue with the database when updating a table. Here's part of the example in question:
scenario 'by changing the contract attributes', js: true do
login_as @admin, scope: :user
contract = Contract.create(number: '123',
start_at: Date.today,
end_at: Date.today + 1.month)
visit "/contracts/#{contract.id}/edit"
I'm using Devise and the Warden::Test::Helpers
to login.
Running RSpec takes a while and all I get:
Failure/Error: visit "/contracts/#{contract.id}/edit"
Capybara::Driver::Webkit::WebkitInvalidResponseError:
Unable to load URL: http://127.0.0.1:46520/contracts/1/edit
The log is showing that there's a database locking issue:
Started GET "/contracts/1/edit" for 127.0.0.1 at 2012-06-01 12:10:26 -0400
(0.2ms) BEGIN
(51083.3ms) UPDATE `users` SET `last_sign_in_at` = '2012-06-01 16:10:26', `current_sign_in_at` = '2012-06-01 16:10:26', `last_sign_in_ip` = '127.0.0.1', `current_sign_in_ip` = '127.0.0.1', `sign_in_count` = 1, `updated_at` = '2012-06-01 16:10:26' WHERE `users`.`id` = 1
Mysql2::Error: Lock wait timeout exceeded; try restarting transaction: UPDATE `users` SET `last_sign_in_at` = '2012-06-01 16:10:26', `current_sign_in_at` = '2012-06-01 16:10:26', `last_sign_in_ip` = '127.0.0.1', `current_sign_in_ip` = '127.0.0.1', `sign_in_count` = 1, `updated_at` = '2012-06-01 16:10:26' WHERE `users`.`id` = 1
(0.8ms) ROLLBACK
I've tried lots of things (that question seemed to closest to an actual solution: Capybara with :js => true causes test to fail) but nothing worked, even getting rid of DatabaseCleaner. Is there anything else I could try?
Edit: Here's the spec_helper.rb
file as requested: https://gist.github.com/2855631
It's almost certainly
config.use_transactional_fixtures = true
Which is trying to run your example inside of a transaction, for the purpose of having clean data. Since you're using Database Cleaner, you already have this feature, so set this to false and you should be good to go.
https://www.relishapp.com/rspec/rspec-rails/docs/transactions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With