Commit 1567fd8f authored by Alex Kalderimis's avatar Alex Kalderimis Committed by Alex Kalderimis

Add test for different DB connection parameters

parent ecfe340a
...@@ -45,20 +45,49 @@ RSpec.describe Gitlab::Database::SetAll do ...@@ -45,20 +45,49 @@ RSpec.describe Gitlab::Database::SetAll do
.to eq(['MR a', 'Issue a', 'Issue b']) .to eq(['MR a', 'Issue a', 'Issue b'])
end end
it 'works when not using a query-counter' do shared_examples 'basic functionality' do
create_default(:user) it 'sets multiple values' do
create_default(:project) create_default(:user)
create_default(:project)
i_a, i_b = create_list(:issue, 2) i_a, i_b = create_list(:issue, 2)
mapping = { mapping = {
i_a => { title: 'Issue a' }, i_a => { title: 'Issue a' },
i_b => { title: 'Issue b' } i_b => { title: 'Issue b' }
} }
described_class.set_all(%i[title], mapping)
described_class.set_all(%i[title], mapping) expect([i_a, i_b].map { |x| x.reset.title })
.to eq(['Issue a', 'Issue b'])
end
end
include_examples 'basic functionality'
context 'when prepared statements are configured differently to the normal test environment' do
# rubocop: disable RSpec/LeakyConstantDeclaration
# This cop is disabled because you cannot call establish_connection on
# an anonymous class.
class ActiveRecordBasePreparedStatementsInverted < ActiveRecord::Base
def self.abstract_class?
true # So it gets its own connection
end
end
# rubocop: enable RSpec/LeakyConstantDeclaration
before_all do
c = ActiveRecord::Base.connection.instance_variable_get(:@config)
inverted = c.merge(prepared_statements: !ActiveRecord::Base.connection.prepared_statements)
ActiveRecordBasePreparedStatementsInverted.establish_connection(inverted)
end
before do
allow(ActiveRecord::Base).to receive(:connection_specification_name)
.and_return(ActiveRecordBasePreparedStatementsInverted.connection_specification_name)
end
expect([i_a, i_b].map { |x| x.reset.title }) include_examples 'basic functionality'
.to eq(['Issue a', 'Issue b'])
end 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