Commit b3b04181 authored by Peter Leitzen's avatar Peter Leitzen

Improve descriptions for Performance/ActiveRecordSubtransactionMethods

Prior this commit the example description did not show the method name
we were testing:

    RuboCop::Cop::Performance::ActiveRecordSubtransactionMethods
      when the method uses a subtransaction
        behaves like a method that uses a subtransaction
          registers an offense
        behaves like a method that uses a subtransaction
          registers an offense
        behaves like a method that uses a subtransaction
          registers an offense
        behaves like a method that uses a subtransaction
          registers an offense
        behaves like a method that uses a subtransaction
          registers an offense
        behaves like a method that uses a subtransaction
          registers an offense

This commit makes the example description more approachable:

    RuboCop::Cop::Performance::ActiveRecordSubtransactionMethods
      when the method uses a subtransaction
        method: :safe_ensure_unique
          behaves like a method that uses a subtransaction
            registers an offense
        method: :safe_find_or_create_by
          behaves like a method that uses a subtransaction
            registers an offense
        method: :safe_find_or_create_by!
          behaves like a method that uses a subtransaction
            registers an offense
        method: :with_fast_read_statement_timeout
          behaves like a method that uses a subtransaction
            registers an offense
        method: :create_or_find_by
          behaves like a method that uses a subtransaction
            registers an offense
        method: :create_or_find_by!
          behaves like a method that uses a subtransaction
            registers an offense

Also, use variables in `expect_offense` improving readability.
parent ed350e4a
# frozen_string_literal: true
require 'fast_spec_helper'
require 'rspec-parameterized'
require_relative '../../../../rubocop/cop/performance/active_record_subtransaction_methods'
RSpec.describe RuboCop::Cop::Performance::ActiveRecordSubtransactionMethods do
......@@ -10,16 +12,18 @@ RSpec.describe RuboCop::Cop::Performance::ActiveRecordSubtransactionMethods do
shared_examples 'a method that uses a subtransaction' do |method_name|
it 'registers an offense' do
expect_offense(<<~RUBY)
Project.#{method_name}
#{'^' * method_name.length} #{message}
expect_offense(<<~RUBY, method_name: method_name, message: message)
Project.%{method_name}
^{method_name} %{message}
RUBY
end
end
context 'when the method uses a subtransaction' do
described_class::DISALLOWED_METHODS.each do |method|
it_behaves_like 'a method that uses a subtransaction', method
where(:method) { described_class::DISALLOWED_METHODS.to_a }
with_them do
include_examples 'a method that uses a subtransaction', params[:method]
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment