I’m a newcomer to the list. Appologies if this has been discussed
before,
but all I could find with regards to specing scopes relates to those
that
filter records or apply sorting. What’s the best way to spec a scope
that
uses the includes method? For instance:
class Location < ActiveRecord.Base
belongs_to: holiday_schedule
scope: with_holiday_schedule, includes(:holiday_schedule)
end
describe Location do
describe Location, “::with_holiday_schedule”
it “includes holiday schedule information to avoid N+1 queries” do
pending “a good way to check this…”
end
end
end
I’ve seen some references to hooking into ActiveSupport::Notifications
for
ActiveRecord SQL and then counting the SQL statements, though the code
I’ve
seen to do this is far from pretty. Does anyone have a better idea?
On Tue, Jul 12, 2011 at 16:03, Derek P. [email protected] wrote:
it “includes holiday schedule information to avoid N+1 queries” do
pending “a good way to check this…”
end
end
end
I’ve seen some references to hooking into ActiveSupport::Notifications for
ActiveRecord SQL and then counting the SQL statements, though the code I’ve
seen to do this is far from pretty. Does anyone have a better idea?
From what I understand, this is purely a performance enhancement, so
I’d expect only to check it with performance tests. In this case, I
would think that a timed test would do the job. It won’t be fast, but
it’ll work, and you won’t be tempted to use it as a behavior test,
since this seems like an issue of implementation and not behavior.
–
J. B. (Joe) Rainsberger :: http://www.jbrains.ca ::
http://blog.thecodewhisperer.com
Author, JUnit Recipes
Free Your Mind to Do Great Work ::
http://www.freeyourmind-dogreatwork.com