Commit e5b89f0f authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'pl-rubocop-leaky-constant-declaration' into 'master'

Use `stub_const` to avoid disabling cop RSpec/LeakyConstantDeclaration

See merge request gitlab-org/gitlab!54847
parents 01b6b9f8 88b50ab3
...@@ -51,7 +51,7 @@ RSpec.describe Gitlab::Database::BulkUpdate do ...@@ -51,7 +51,7 @@ RSpec.describe Gitlab::Database::BulkUpdate do
it 'is possible to update all objects in a single query' do it 'is possible to update all objects in a single query' do
users = create_list(:user, 3) users = create_list(:user, 3)
mapping = users.zip(%w(foo bar baz)).to_h do |u, name| mapping = users.zip(%w[foo bar baz]).to_h do |u, name|
[u, { username: name, admin: true }] [u, { username: name, admin: true }]
end end
...@@ -61,13 +61,13 @@ RSpec.describe Gitlab::Database::BulkUpdate do ...@@ -61,13 +61,13 @@ RSpec.describe Gitlab::Database::BulkUpdate do
# We have optimistically updated the values # We have optimistically updated the values
expect(users).to all(be_admin) expect(users).to all(be_admin)
expect(users.map(&:username)).to eq(%w(foo bar baz)) expect(users.map(&:username)).to eq(%w[foo bar baz])
users.each(&:reset) users.each(&:reset)
# The values are correct on reset # The values are correct on reset
expect(users).to all(be_admin) expect(users).to all(be_admin)
expect(users.map(&:username)).to eq(%w(foo bar baz)) expect(users.map(&:username)).to eq(%w[foo bar baz])
end end
it 'is possible to update heterogeneous sets' do it 'is possible to update heterogeneous sets' do
...@@ -113,23 +113,19 @@ RSpec.describe Gitlab::Database::BulkUpdate do ...@@ -113,23 +113,19 @@ RSpec.describe Gitlab::Database::BulkUpdate do
include_examples 'basic functionality' include_examples 'basic functionality'
context 'when prepared statements are configured differently to the normal test environment' do context 'when prepared statements are configured differently to the normal test environment' do
# rubocop: disable RSpec/LeakyConstantDeclaration before do
# This cop is disabled because you cannot call establish_connection on klass = Class.new(ActiveRecord::Base) do
# an anonymous class.
class ActiveRecordBasePreparedStatementsInverted < ActiveRecord::Base
def self.abstract_class? def self.abstract_class?
true # So it gets its own connection true # So it gets its own connection
end end
end end
# rubocop: enable RSpec/LeakyConstantDeclaration
before_all do stub_const('ActiveRecordBasePreparedStatementsInverted', klass)
c = ActiveRecord::Base.connection.instance_variable_get(:@config) c = ActiveRecord::Base.connection.instance_variable_get(:@config)
inverted = c.merge(prepared_statements: !ActiveRecord::Base.connection.prepared_statements) inverted = c.merge(prepared_statements: !ActiveRecord::Base.connection.prepared_statements)
ActiveRecordBasePreparedStatementsInverted.establish_connection(inverted) ActiveRecordBasePreparedStatementsInverted.establish_connection(inverted)
end
before do
allow(ActiveRecord::Base).to receive(:connection_specification_name) allow(ActiveRecord::Base).to receive(:connection_specification_name)
.and_return(ActiveRecordBasePreparedStatementsInverted.connection_specification_name) .and_return(ActiveRecordBasePreparedStatementsInverted.connection_specification_name)
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