Skip to content

Commit

Permalink
Add chain :matching
Browse files Browse the repository at this point in the history
  • Loading branch information
caalberts authored and palkan committed Nov 17, 2020
1 parent 203d8c7 commit aa1e54d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Expand Up @@ -8,6 +8,10 @@
@factors = factors
end

chain :matching do |pattern|
@pattern = pattern
end

chain :with_warming_up do
@warmup = true
end
Expand Down
Expand Up @@ -60,6 +60,30 @@
end
end

context "with matching", :n_plus_one do
populate { |n| create_list(:post, n) }

specify do
expect { Post.find_each { |p| p.user.name } }
.to perform_linear_number_of_queries.matching(/users/)
end

context "with matching is provided globally", :n_plus_one do
around(:each) do |ex|
NPlusOneControl.default_matching = "users"
ex.run
NPlusOneControl.default_matching = nil
end

populate { |n| create_list(:post, n) }

specify do
expect { Post.find_each { |p| p.user.name } }
.to perform_linear_number_of_queries
end
end
end

context "with warming up", :n_plus_one do
let(:cache) { double "cache" }

Expand Down

0 comments on commit aa1e54d

Please sign in to comment.