You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering if it would be possible to add a matcher that checks whether any Mongoid query is performed by a block of code.
I am implementing various caching strategies (not necessarily using Rails.cacheas depicted below), and I'd like to test easily whether a query was actually fired by the adapter.
I'm not so knowledgeable about Mongoid internals, and after trying a bit I could not come up with some relevant expectation strategy for such a matcher.
The matcher I'm thinking about would be useful to test this
classFooServicedefself.recent_foosRails.cache.fetch("foos",expires_in: 1.day)doFoo.desc(:created_at).limit(10)endendenddescribeFooServicecontext'when recent foos were already retrieved'before{FooService.recent_foos}context'retrieving foos again within 2 hours'before{Timecop.freeze(2.hours.from_now}after{Timecop.return}it'does not hit the DB'expect{FooService.recent_foos}.not_tofire_mongodb_queryendendend
The text was updated successfully, but these errors were encountered:
Cf https://stackoverflow.com/questions/50647759/rspec-expect-no-mongoid-database-query-fired
I was wondering if it would be possible to add a matcher that checks whether any Mongoid query is performed by a block of code.
I am implementing various caching strategies (not necessarily using
Rails.cache
as depicted below), and I'd like to test easily whether a query was actually fired by the adapter.I'm not so knowledgeable about Mongoid internals, and after trying a bit I could not come up with some relevant expectation strategy for such a matcher.
The matcher I'm thinking about would be useful to test this
The text was updated successfully, but these errors were encountered: