0

Is it possible to test includes in Rails query (Rails 5 / tests with rspec-rails) ?

I can see includes are ok in log files, but I would like to write a test for this. I looked in docs but I'm not able to find any solution.

My query :

def concepts_by_type(type_c)
  includes(var_concepts: [{domain: [:vals, :syms]}, :variable]).where(concept_types: {label: type_c}).order('ancestry ASC')
end
LiKaZ
  • 306
  • 3
  • 9
  • 2
    You shouldn't test that. The ActiveRecord team tests that the includes does what it's sopussed to, it's useless to test that by yourself. You could test that you actually call the `includes` methods, but then you'll be testing implementation and it's also not recommended (You should test behaviour, not implementation). – arieljuod Jan 25 '19 at 14:26
  • 1
    There is no sense to test that. What you should do is to test your `concepts_by_type` method that behaves as expected. – zauzaj Jan 25 '19 at 15:19
  • Ok. I am new to test, and I thought I could test this to be sure my function was including what I want. I already wrote the test to verify the result of the query. Thanks. – LiKaZ Jan 25 '19 at 16:19

0 Answers0