palkan / n_plus_one_control

RSpec and Minitest matchers to prevent N+1 queries problem
MIT License
553 stars 20 forks source link

add checking for exact number of queries #57

Closed akostadinov closed 1 year ago

akostadinov commented 2 years ago

fixes #56

Not doing the whole checklist to see if feature is accepted as it is now.

Checklist

palkan commented 2 years ago

I think, this one is very similar to constant queries matcher. Maybe we can extend it like this instead?

expect { subject }.to perform_constant_number_of_queries(exactly: 1)
akostadinov commented 1 year ago

There is some issue that I'll fix somehow, when I'm able to reproduce locally. But could you tell me if you like how code looks now?

I merged the rspec matchers. But left the minitest assertion because it doesn't seem to reuse much code. Is this fine with you or you want also minitest to use a parameter instead of a new assertion?

palkan commented 1 year ago

Finally merged and released (see 0.7.1, it also includes some other minor things we discussed a while ago).

I changed the final API for Minitest: similarly to RSpec, I extended the existing #assert_perform_constant_number_of_queries API to support passing the exact number: we just pass a positional argument

assert_perform_constant_number_of_queries(2, **options) do
  get :index
end