title: How to test a method that runs an SQL query
body: <p>I've made a custom SQL query and I want to create a unit tests to demonstrate that it works. I have tested it in SQLDeveloper and it works as I want it to on my test database but I want to leave a unit test for those who have to maintain this code later. </p>
  
  <pre><code>def report_of_merchants_who_have_not_pressed_the_service_rendered_button
      sql = "SELECT MIN(departure_date), ch_invoice.invoice_id
      FROM ch_invoice
      INNER JOIN ch_trip
      ON ch_invoice.invoice_id = ch_trip.invoice_id
      WHERE departure_date &lt; SYSDATE
      AND service_rendered = 0
      AND paid = 1
      Group By ch_invoice.invoice_id"
  
      report = ActiveRecord::Base.connection.exec_query(sql)
      render json: report
    end
  </code></pre>
  
  <p>My thought was to create four invoices, three of which are not meeting the above criteria and one that does. Where I am getting stuck is how to check that the query only returns back one response. How do I test that one row of the query is coming out?</p>
  
  <p><strong>Clarification</strong>
  I was intending on creating these invoices &amp; trips with FactoryGirl to fill the models. Will that still work?</p>