title: deadlock detected with capybara-webkit
body: <p>I'm trying to pass this spec :</p>
  
  <pre><code>scenario "Edit a service", js: true do
    service = create_service_for(provider, title: "First service")
    fill_edit_service_form(service)
    expect(page).to have_css('#price', text: '10,00 $')
  end
  </code></pre>
  
  <p>This is a standard rails spec using capybara. I am using capybara-webkit for all scenario with javascript. When I'm trying to pass it, sometimes it works, sometimes it mark than there is a missing record in the database and sometime I have this error :</p>
  
  <pre><code>Run options: include {:locations=&gt;{"./spec/acceptances/provider_services_spec.rb"=&gt;[31]}}
  [K  1) Provider Services Edit a service
       Failure/Error: Unable to find matching line from backtrace
       ActiveRecord::StatementInvalid:
         PG::TRDeadlockDetected: ERROR:  deadlock detected
         DETAIL:  Process 24164 waits for AccessExclusiveLock on relation 3446991 of database 3446538; blocked by process 24184.
         Process 24184 waits for AccessShareLock on relation 3446902 of database 3446538; blocked by process 24164.
         HINT:  See server log for query details.
         : ALTER TABLE "active_admin_comments" DISABLE TRIGGER ALL;ALTER TABLE "provider_service_territory_provideds" DISABLE TRIGGER ALL;ALTER TABLE "provider_services" DISABLE TRIGGER ALL;ALTER TABLE "provider_divisions" DISABLE TRIGGER ALL;ALTER TABLE "provider_profiles" DISABLE TRIGGER ALL;ALTER TABLE "provider_service_intervention_level_provideds" DISABLE TRIGGER ALL;ALTER TABLE "provider_service_medium_provideds" DISABLE TRIGGER ALL;ALTER TABLE "provider_service_service_provideds" DISABLE TRIGGER ALL;ALTER TABLE "regions" DISABLE TRIGGER ALL;ALTER TABLE "service_formulas" DISABLE TRIGGER ALL;ALTER TABLE "region_translations" DISABLE TRIGGER ALL;ALTER TABLE "artists" DISABLE TRIGGER ALL;ALTER TABLE "admin_users" DISABLE TRIGGER ALL;ALTER TABLE "schema_migrations" DISABLE TRIGGER ALL;ALTER TABLE "services" DISABLE TRIGGER ALL;ALTER TABLE "services_provided" DISABLE TRIGGER ALL;ALTER TABLE "territories_provided" DISABLE TRIGGER ALL;ALTER TABLE "users" DISABLE TRIGGER ALL;ALTER TABLE "countries" DISABLE TRIGGER ALL;ALTER TABLE "coupons" DISABLE TRIGGER ALL;ALTER TABLE "currencies" DISABLE TRIGGER ALL;ALTER TABLE "formulas" DISABLE TRIGGER ALL;ALTER TABLE "collector_profiles" DISABLE TRIGGER ALL;ALTER TABLE "country_translations" DISABLE TRIGGER ALL;ALTER TABLE "images" DISABLE TRIGGER ALL;ALTER TABLE "intervention_levels_provided" DISABLE TRIGGER ALL;ALTER TABLE "measure_units" DISABLE TRIGGER ALL;ALTER TABLE "media_provided" DISABLE TRIGGER ALL;ALTER TABLE "messages" DISABLE TRIGGER ALL;ALTER TABLE "page_part_translations" DISABLE TRIGGER ALL;ALTER TABLE "orders" DISABLE TRIGGER ALL;ALTER TABLE "painting_categories" DISABLE TRIGGER ALL;ALTER TABLE "page_services" DISABLE TRIGGER ALL;ALTER TABLE "page_translations" DISABLE TRIGGER ALL;ALTER TABLE "painting_category_translations" DISABLE TRIGGER ALL;ALTER TABLE "page_parts" DISABLE TRIGGER ALL;ALTER TABLE "pages" DISABLE TRIGGER ALL;ALTER TABLE "painting_provenances" DISABLE TRIGGER ALL;ALTER TABLE "painting_prices" DISABLE TRIGGER ALL;ALTER TABLE "painting_technic_translations" DISABLE TRIGGER ALL;ALTER TABLE "painting_technics" DISABLE TRIGGER ALL;ALTER TABLE "painting_type_translations" DISABLE TRIGGER ALL;ALTER TABLE "period_translations" DISABLE TRIGGER ALL;ALTER TABLE "painting_types" DISABLE TRIGGER ALL;ALTER TABLE "paintings" DISABLE TRIGGER ALL;ALTER TABLE "periods" DISABLE TRIGGER ALL
       # -e:1:in `&lt;main&gt;'
  
   1/1 |========================= 100 ==========================&gt;| Time: 00:00:03 
  
  Finished in 3.41 seconds
  1 example, 1 failure
  
  Failed examples:
  
  rspec ./spec/acceptances/provider_services_spec.rb:29 # Provider Services Edit a service
       Screenshot: /home/dougui/rails/lescollectionneurs/tmp/capybara/screenshot_2014-02-20-18-22-55.658.png
  
  Randomized with seed 34053
  </code></pre>
  
  <p>I have a lock in a table. This not always the same table.</p>
  
  <p>It's better when I do this : </p>
  
  <pre><code>Capybara.reset_sessions!
  DatabaseCleaner.clean
  </code></pre>
  
  <p>Before and after the spec but it is not always working. If I run all my specs in the same file, I does not work.</p>
  
  <p>It appends when I was working on a unrelated things. It works with poltergeist.</p>
  
  <p>This is my spec_helper file : </p>
  
  <pre><code>ENV["RAILS_ENV"] ||= 'test'
  require 'rubygems'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'
  require 'capybara/rails'
  require 'capybara-webkit'
  require 'database_cleaner'
  require 'capybara/firebug'
  require 'capybara-screenshot/rspec'
  
  if defined?(Spring)
    Spring.watch "#{Rails.root}/spec/factories"
  else
    require 'shoulda-matchers'
  end
  
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  
  RSpec.configure do |config|
    config.infer_base_class_for_anonymous_controllers = false
    config.use_transactional_fixtures = false
    config.order = "random"
  
    config.include FactoryGirl::Syntax::Methods
    config.include Warden::Test::Helpers, type: :feature
    config.include FeatureHelpers, type: :feature
    config.include Devise::TestHelpers, type: :controller
    config.include ControllerHelpers, type: :controller
    config.include EmailSpec::Helpers
    config.include EmailSpec::Matchers
  
    config.before(:suite) do
      DatabaseCleaner.strategy = :transaction
      DatabaseCleaner.clean_with(:truncation)
    end
  
    config.before(:each) do
      if example.metadata[:js]
        DatabaseCleaner.strategy = :truncation
      else
        DatabaseCleaner.start
      end
    end
  
    config.after(:each) do
      DatabaseCleaner.clean
      DatabaseCleaner.strategy = :transaction if example.metadata[:js]
    end
  end
  
  Capybara.javascript_driver = :webkit
  
  include ActionDispatch::TestProcess
  I18n.locale = :fr
  
  Geocoder.configure(:lookup =&gt; :test)
  
  Geocoder::Lookup::Test.set_default_stub(
    [
      {
        'latitude'     =&gt; 40.7143528,
        'longitude'    =&gt; -74.0059731,
        'address'      =&gt; 'New York, NY, USA',
        'state'        =&gt; 'New York',
        'state_code'   =&gt; 'NY',
        'country'      =&gt; 'United States',
        'country_code' =&gt; 'US'
      }
    ]
  )
  </code></pre>
  
  <p>Here are the gem used : <a href="https://github.com/GCorbel/lescollectionneursassocies/blob/master/Gemfile">https://github.com/GCorbel/lescollectionneursassocies/blob/master/Gemfile</a>.</p>
  
  <p>Any suggestions?</p>
  
  <p>For more details, please look at the Github repo : <a href="https://github.com/GCorbel/lescollectionneursassocies/">https://github.com/GCorbel/lescollectionneursassocies/</a>.</p>