palkan / n_plus_one_control

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

Using filter NPLUSONE_FILTER in rspec returns always success result #54

Open dmitriy-borowskiy opened 2 years ago

dmitriy-borowskiy commented 2 years ago

What did you do?

I have a following scenario

context "N+1", :n_plus_one do
      it "n+1" do
        audit_type_2 = create(:audit_type, account: org)
        audit_type_3 = create(:audit_type, account: org)
        audit_type_4 = create(:audit_type, account: another_org)

        expect { do_request(:get, "/api/v3/project_types?org_id=#{org.organization_id}", org_user) }.to perform_constant_number_of_queries
      end
    end

command running test

bundle exec rspec spec/controllers/api/v3/audit_types_controller_spec.rb:338

Failure/Error: expect { do_request(:get, "/api/v3/project_types?org_id=#{org.organization_id}", org_user) }.to perform_constant_number_of_queries

       Expected to make the same number of queries, but got:
         194 for N=2
         195 for N=3
       Unmatched query numbers by tables:
     # ./spec/controllers/api/v3/audit_types_controller_spec.rb:345:in `block (4 levels) in <top (required)>'
     # ./spec/spec_helper.rb:83:in

If I try to run test with filter, tests result returns success, but should return failure:

NPLUSONE_VERBOSE=1 NPLUSONE_FILTER=accounts bundle exec rspec spec/controllers/api/v3/audit_types_controller_spec.rb:338

returns: 200 with only specified fields

Finished in 2.42 seconds (files took 6.66 seconds to load)
1 example, 0 failures

What did you expect to happen?

Unmatched query numbers by tables: accounts (SELECT)

palkan commented 2 years ago

Hey!

Could you please show the output when running with the only NPLUSONE_VERBOSE=1 env var? (w/o filtering) I wonder, which queries have been collected (and why we filtered them all out).