summaryrefslogtreecommitdiff
path: root/spec/rubocop/cop/performance/active_record_subtransaction_methods_spec.rb
blob: df18121e2df24a40c126b796748edb4f6ae6809a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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
  subject(:cop) { described_class.new }

  let(:message) { described_class::MSG }

  shared_examples 'a method that uses a subtransaction' do |method_name|
    it 'registers an offense' do
      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
    where(:method) { described_class::DISALLOWED_METHODS.to_a }

    with_them do
      include_examples 'a method that uses a subtransaction', params[:method]
    end
  end
end