2022-03-02 08:16:31 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
require 'fast_spec_helper'
|
2022-03-02 08:16:31 +05:30
|
|
|
require_relative '../../../../rubocop/cop/database/establish_connection'
|
|
|
|
|
|
|
|
RSpec.describe RuboCop::Cop::Database::EstablishConnection do
|
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
it 'flags the use of ActiveRecord::Base.establish_connection' do
|
|
|
|
expect_offense(<<~CODE)
|
|
|
|
ActiveRecord::Base.establish_connection
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't establish new database [...]
|
|
|
|
CODE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags the use of ActiveRecord::Base.establish_connection with arguments' do
|
|
|
|
expect_offense(<<~CODE)
|
|
|
|
ActiveRecord::Base.establish_connection(:foo)
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't establish new database [...]
|
|
|
|
CODE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags the use of SomeModel.establish_connection' do
|
|
|
|
expect_offense(<<~CODE)
|
|
|
|
SomeModel.establish_connection
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't establish new database [...]
|
|
|
|
CODE
|
|
|
|
end
|
|
|
|
end
|