diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-26 09:10:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-26 09:10:47 +0300 |
commit | b692f9afa047ef24c54ab185b499628d9873122a (patch) | |
tree | 8860b5c66c42791ddff2e231c4338f41b243e71f /spec/lib | |
parent | baaa5c45c022d394bf1478d462a3b1aea413b7ed (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/database/connection_spec.rb | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/spec/lib/gitlab/database/connection_spec.rb b/spec/lib/gitlab/database/connection_spec.rb index 5e0e6039afc..f6ecc7761d6 100644 --- a/spec/lib/gitlab/database/connection_spec.rb +++ b/spec/lib/gitlab/database/connection_spec.rb @@ -393,34 +393,28 @@ RSpec.describe Gitlab::Database::Connection do end describe '#cached_column_exists?' do - it 'only retrieves data once' do - expect(connection.scope.connection) - .to receive(:columns) - .once.and_call_original - - 2.times do - expect(connection.cached_column_exists?(:projects, :id)).to be_truthy - expect(connection.cached_column_exists?(:projects, :bogus_column)).to be_falsey + it 'only retrieves the data from the schema cache' do + queries = ActiveRecord::QueryRecorder.new do + 2.times do + expect(connection.cached_column_exists?(:projects, :id)).to be_truthy + expect(connection.cached_column_exists?(:projects, :bogus_column)).to be_falsey + end end + + expect(queries.count).to eq(0) end end describe '#cached_table_exists?' do - it 'only retrieves data once per table' do - expect(connection.scope.connection) - .to receive(:data_source_exists?) - .with(:projects) - .once.and_call_original - - expect(connection.scope.connection) - .to receive(:data_source_exists?) - .with(:bogus_table_name) - .once.and_call_original - - 2.times do - expect(connection.cached_table_exists?(:projects)).to be_truthy - expect(connection.cached_table_exists?(:bogus_table_name)).to be_falsey + it 'only retrieves the data from the schema cache' do + queries = ActiveRecord::QueryRecorder.new do + 2.times do + expect(connection.cached_table_exists?(:projects)).to be_truthy + expect(connection.cached_table_exists?(:bogus_table_name)).to be_falsey + end end + + expect(queries.count).to eq(0) end it 'returns false when database does not exist' do @@ -433,16 +427,14 @@ RSpec.describe Gitlab::Database::Connection do end describe '#exists?' do - it 'returns true if `ActiveRecord::Base.connection` succeeds' do - expect(connection.scope).to receive(:connection) - + it 'returns true if the database exists' do expect(connection.exists?).to be(true) end - it 'returns false if `ActiveRecord::Base.connection` fails' do - expect(connection.scope).to receive(:connection) do - raise ActiveRecord::NoDatabaseError, 'broken' - end + it "returns false if the database doesn't exist" do + expect(connection.scope.connection.schema_cache) + .to receive(:database_version) + .and_raise(ActiveRecord::NoDatabaseError) expect(connection.exists?).to be(false) end |