[rspec-users] How to test/spec an ActiveRecord find that uses :include

Pat Maddox pat.maddox at gmail.com
Wed Apr 15 11:53:07 EDT 2009

You have to hit the db here to make sure that it works.  Can't isolate
all the time, especially when building database-centric apps ;)

As for testing it, the easiest way I know of to test the association
was included is to check #loaded? on the proxy.

h = Harbor.first
h.marinas.should be_loaded

That works right out of the box and is usually enough to make you
confident that the find was done with an include.  You can also hook
into AR.find/execute and count the number of queries and verify that
there's only one.


On Wed, Apr 15, 2009 at 7:19 AM, Fernando Perez <lists at ruby-forum.com> wrote:
> Hi,
> I was refactoring my model specs so that they don't hit the database,
> but how to handle a custom find that uses :joins or :include with some
> important :conditions? I can't see a way to not hit the database.
> Should that spec actually belong to an integration spec?
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list