title: RSpec - How to test a database view?
body: <p>I have a class that is backing a database view. I am using FactoryGirl to try and test this so I go through the normal steps of creating a <code>user</code> instance like so:</p>
  
  <pre><code>before(:each) do
    @user = FactoryGirl.create(:user)
  end
  </code></pre>
  
  <p>Then I check the view count:</p>
  
  <pre><code>Balance.all.count   # It is returning 0, it should be returning 1
  </code></pre>
  
  <p>My understanding of database views is that they do not update until after the transaction is committed to the database. I have a background working with NHibernate and in order to get an updated value from the database, I would do something like:</p>
  
  <pre><code>Session.Flush();
  </code></pre>
  
  <p>That would allow me then to query the database view and get updated values but still rollback or commit my transaction later.</p>
  
  <p>Is there a way to do this in ActiveRecord? Or is there a way to commit my changes to the database and clean it up? I don't want to turn off the transactions for all tests, just be able to test this one particular class.</p>