How can I check the type of request that Mongoid will generate?

I am trying to claim, using RSpec, that this Mongoid request will not load the record, just check its existence, because the record is large (several MB), and the code should only know if the record exists.

Did I play with .exists? in associations, but for some reason this does not work with has_one , for example:

 class Profile include Mongoid::Document has_one :chart end class Chart # this is heavy include Mongoid::Document belongs_to :profile end profile.chart.exists? # fails if chart returns nil 

The proxy method exists? doesn't seem to work for has_one relationships; although it is documented for has_many . I want to create my own, but I need to check in RSpec that in reality, the record is only requested and not loaded. I am thinking of doing something like testing the basic query created for the Mongo driver, as you can do with .to_sql . Is there a corresponding Mongolian method?

+6
source share
1 answer
 profile.chart.nil? 

does not work?

0
source

Source: https://habr.com/ru/post/919150/


All Articles