2020-03-13 15:09:21 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe ExceedQueryLimitHelpers do
|
2020-05-21 12:08:08 +00:00
|
|
|
before do
|
|
|
|
stub_const('TestQueries', Class.new(ActiveRecord::Base))
|
|
|
|
stub_const('TestMatcher', Class.new)
|
|
|
|
|
|
|
|
TestQueries.class_eval do
|
|
|
|
self.table_name = 'schema_migrations'
|
|
|
|
end
|
2020-03-13 15:09:21 +00:00
|
|
|
|
2020-05-21 12:08:08 +00:00
|
|
|
TestMatcher.class_eval do
|
|
|
|
include ExceedQueryLimitHelpers
|
2020-03-13 15:09:21 +00:00
|
|
|
|
2020-05-21 12:08:08 +00:00
|
|
|
def expected
|
|
|
|
ActiveRecord::QueryRecorder.new do
|
|
|
|
2.times { TestQueries.count }
|
|
|
|
end
|
2020-03-13 15:09:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not contain marginalia annotations' do
|
|
|
|
test_matcher = TestMatcher.new
|
|
|
|
test_matcher.verify_count do
|
|
|
|
2.times { TestQueries.count }
|
|
|
|
TestQueries.first
|
|
|
|
end
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(test_matcher.log_message)
|
|
|
|
.to match(%r{ORDER BY.*#{TestQueries.table_name}.*LIMIT 1})
|
|
|
|
expect(test_matcher.log_message)
|
|
|
|
.not_to match(%r{\/\*.*correlation_id.*\*\/})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|