Created
July 4, 2023 05:13
-
-
Save amitpatelx/85ab8634822e93a5db42b954e561a7d0 to your computer and use it in GitHub Desktop.
Test N+1 in Spec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: https://evilmartians.com/chronicles/squash-n-plus-one-queries-early-with-n-plus-one-control-test-matchers-for-ruby-and-rails | |
# Gemfile | |
gem 'n_plus_one_control', group: :test | |
# rails_helper.rb | |
require 'n_plus_one_control/rspec' | |
# spec.rb | |
context 'N+1', :n_plus_one do | |
populate { |n| create_list(:reservation_detail, n) } | |
specify do | |
expect { described_class.new(Date.current, Date.current.next_month).n1 }.to perform_constant_number_of_queries | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment