Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're running a request spec: when you call visit the code under test is run in a server instance (in the same process). In particular this means that it's using a different thread. </p> <p>As a result the application code ends up using a different database connection, and since transactions are a per connection thing there is no transaction used when your controller inserts records into the database. </p> <p>There are several ways to address this. One is to abandon rspec's transactional fixtures and use the database_cleaner gem. You can set it up so that controller and model specs use transactions but request specs use truncate to forcibly clear out tables. </p> <p>Another approach is to try and force both the spec code and the server code to use the same database connection, this eliminating the problem. You can see this approach in <a href="https://stackoverflow.com/questions/8774227/why-not-use-shared-activerecord-connections-for-rspec-selenium">this answer</a>. In my experience this works pretty well until you start using a capybara driver such as poltergeist which will run any javascript on the page and your page fires ajax requests. </p> <p>The approach I've been using is to set the active record connection pool size to 1: there is only 1 connection allowed so everyone will use the same one. You do then have to do some work to ensure that connections are returned to the pool or your spec just hangs.</p> <p>I wrote up the details a while ago as a <a href="http://www.spacevatican.org/2012/8/18/threading-the-rat/" rel="nofollow noreferrer">blog post</a>, but in a nutshell you need to</p> <ul> <li>call <code>ActiveRecord::Base.clear_active_connections!</code> before calling methods like visit, click and so on</li> <li>hack config.middleware.insert_before <code>ActiveRecord::ConnectionAdapters::ConnectionManagement</code> so that it clears the connection after each request (by default it doesn't do this in tests).</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload