Skip to content

Commit

Permalink
Get rid of db-query-matchers gem
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroperea committed Jan 22, 2022
1 parent 74825da commit f7cdccc
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 52 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ group :test do
gem "cuprite"
gem "capybara"
gem "webrick"
gem "db-query-matchers"

gem "simplecov", require: false # Test coverage generator. Go to /coverage/ after running tests
gem "cucumber-rails", require: false
Expand Down
8 changes: 0 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ GEM
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
db-query-matchers (0.10.0)
activesupport (>= 4.0, < 7)
rspec (~> 3.0)
devise (4.8.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -374,10 +371,6 @@ GEM
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
Expand Down Expand Up @@ -483,7 +476,6 @@ DEPENDENCIES
cucumber-rails
cuprite
database_cleaner
db-query-matchers
devise
draper
i18n-spec
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_52/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ group :test do
gem "cuprite"
gem "capybara"
gem "webrick"
gem "db-query-matchers"

gem "simplecov", require: false # Test coverage generator. Go to /coverage/ after running tests
gem "cucumber-rails", require: false
Expand Down
8 changes: 0 additions & 8 deletions gemfiles/rails_52/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ GEM
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
db-query-matchers (0.10.0)
activesupport (>= 4.0, < 7)
rspec (~> 3.0)
devise (4.8.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -289,10 +286,6 @@ GEM
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
Expand Down Expand Up @@ -368,7 +361,6 @@ DEPENDENCIES
cucumber-rails
cuprite
database_cleaner
db-query-matchers
devise
draper
jasmine
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_60/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ group :test do
gem "cuprite"
gem "capybara"
gem "webrick"
gem "db-query-matchers"

gem "simplecov", require: false # Test coverage generator. Go to /coverage/ after running tests
gem "cucumber-rails", require: false
Expand Down
8 changes: 0 additions & 8 deletions gemfiles/rails_60/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ GEM
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
db-query-matchers (0.10.0)
activesupport (>= 4.0, < 7)
rspec (~> 3.0)
devise (4.8.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -304,10 +301,6 @@ GEM
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
Expand Down Expand Up @@ -384,7 +377,6 @@ DEPENDENCIES
cucumber-rails
cuprite
database_cleaner
db-query-matchers
devise
draper
jasmine
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_61_turbolinks/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ group :test do
gem "cuprite"
gem "capybara"
gem "webrick"
gem "db-query-matchers"

gem "simplecov", require: false # Test coverage generator. Go to /coverage/ after running tests
gem "cucumber-rails", require: false
Expand Down
8 changes: 0 additions & 8 deletions gemfiles/rails_61_turbolinks/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ GEM
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
db-query-matchers (0.10.0)
activesupport (>= 4.0, < 7)
rspec (~> 3.0)
devise (4.8.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -308,10 +305,6 @@ GEM
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
Expand Down Expand Up @@ -389,7 +382,6 @@ DEPENDENCIES
cucumber-rails
cuprite
database_cleaner
db-query-matchers
devise
draper
jasmine
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_61_webpacker/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ group :test do
gem "cuprite"
gem "capybara"
gem "webrick"
gem "db-query-matchers"

gem "simplecov", require: false # Test coverage generator. Go to /coverage/ after running tests
gem "cucumber-rails", require: false
Expand Down
8 changes: 0 additions & 8 deletions gemfiles/rails_61_webpacker/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ GEM
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
db-query-matchers (0.10.0)
activesupport (>= 4.0, < 7)
rspec (~> 3.0)
devise (4.8.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -310,10 +307,6 @@ GEM
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
Expand Down Expand Up @@ -385,7 +378,6 @@ DEPENDENCIES
cucumber-rails
cuprite
database_cleaner
db-query-matchers
devise
draper
jasmine
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true
require "simplecov" if ENV["COVERAGE"] == "true"

Dir[File.expand_path("#{File.dirname(__FILE__)}/support/matchers/*.rb")].each { |file| require file }

RSpec.configure do |config|
config.disable_monkey_patching!
config.filter_run focus: true
Expand Down
25 changes: 25 additions & 0 deletions spec/support/matchers/perform_database_query_matcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

RSpec::Matchers.define :perform_database_query do |query|
match do |block|
@match = nil

callback = lambda do |_name, _started, _finished, _unique_id, payload|
@match = Regexp.new(Regexp.escape(query)).match?(payload[:sql])
end

ActiveSupport::Notifications.subscribed(callback, "sql.active_record", &block)

@match
end

failure_message do |_|
"Expected queries like \"#{query}\" but none were made"
end

failure_message_when_negated do |_|
"Expected no queries like \"#{query}\" but at least one were made"
end

supports_block_expectations
end
16 changes: 9 additions & 7 deletions spec/unit/views/components/paginated_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,26 +229,28 @@ def paginated_collection(*args)
end

it "makes no expensive COUNT queries when pagination_total is false" do
require "db-query-matchers"

undecorated_collection = Post.all.page(1).per(30)

expect { paginated_collection(undecorated_collection, pagination_total: false) }
.not_to make_database_queries(matching: "SELECT COUNT(*) FROM \"posts\"")
.not_to perform_database_query("SELECT COUNT(*) FROM \"posts\"")

paginated_collection(undecorated_collection, pagination_total: false)

decorated_collection = controller_with_decorator("index", PostDecorator).apply_collection_decorator(undecorated_collection)

expect { paginated_collection(decorated_collection, pagination_total: false) }
.not_to make_database_queries(matching: "SELECT COUNT(*) FROM \"posts\"")
.not_to perform_database_query("SELECT COUNT(*) FROM \"posts\"")

paginated_collection(decorated_collection, pagination_total: false)
end

it "makes no COUNT queries to figure out the last element of each page" do
require "db-query-matchers"

undecorated_collection = Post.all.page(1).per(30)

expect { paginated_collection(undecorated_collection) }
.not_to make_database_queries(matching: "SELECT COUNT(*) FROM (SELECT")
.not_to perform_database_query("SELECT COUNT(*) FROM (SELECT")

paginated_collection(undecorated_collection)
end

context "when specifying per_page: array option" do
Expand Down

0 comments on commit f7cdccc

Please sign in to comment.