Commit c27b91da authored by Adam Hegyi's avatar Adam Hegyi

Merge branch '341783-tidy-specs-for-cross-modification' into 'master'

Refactor specs prevent_cross_database_modification_spec

See merge request gitlab-org/gitlab!73451
parents 71488731 3b382796
......@@ -6,7 +6,7 @@ RSpec.describe 'Database::PreventCrossDatabaseModification' do
let_it_be(:pipeline, refind: true) { create(:ci_pipeline) }
let_it_be(:project, refind: true) { create(:project) }
shared_examples 'succeessful examples' do
shared_examples 'successful examples' do
context 'outside transaction' do
it { expect { run_queries }.not_to raise_error }
end
......@@ -36,7 +36,7 @@ RSpec.describe 'Database::PreventCrossDatabaseModification' do
project.reload
end
include_examples 'succeessful examples'
include_examples 'successful examples'
end
context 'when only CI data is modified' do
......@@ -45,7 +45,7 @@ RSpec.describe 'Database::PreventCrossDatabaseModification' do
project.reload
end
include_examples 'succeessful examples'
include_examples 'successful examples'
end
context 'when other data is modified' do
......@@ -54,34 +54,9 @@ RSpec.describe 'Database::PreventCrossDatabaseModification' do
project.touch
end
include_examples 'succeessful examples'
include_examples 'successful examples'
end
describe 'with_cross_database_modification_prevented block' do
it 'raises error when CI and other data is modified' do
expect do
with_cross_database_modification_prevented do
Project.transaction do
project.touch
pipeline.touch
end
end
end.to raise_error /Cross-database data modification/
end
it 'raises an error when an undefined gitlab_schema table is modified with another table' do
expect do
with_cross_database_modification_prevented do
Project.transaction do
project.touch
project.connection.execute('UPDATE foo_bars_undefined_table SET a=1 WHERE id = -1')
end
end
end.to raise_error /Cross-database data modification.*The gitlab_schema was undefined/
end
end
context 'when running tests with prevent_cross_database_modification', :prevent_cross_database_modification do
context 'when both CI and other data is modified' do
def run_queries
project.touch
......@@ -137,7 +112,6 @@ RSpec.describe 'Database::PreventCrossDatabaseModification' do
end
end
end
end
context 'when CI association is modified through project' do
def run_queries
......@@ -145,7 +119,7 @@ RSpec.describe 'Database::PreventCrossDatabaseModification' do
project.save!
end
include_examples 'succeessful examples'
include_examples 'successful examples'
end
describe '#allow_cross_database_modification_within_transaction' do
......@@ -171,4 +145,15 @@ RSpec.describe 'Database::PreventCrossDatabaseModification' do
end
end
end
context 'when some table with a defined schema and another table with undefined gitlab_schema is modified' do
it 'raises an error including including message about undefined schema' do
expect do
Project.transaction do
project.touch
project.connection.execute('UPDATE foo_bars_undefined_table SET a=1 WHERE id = -1')
end
end.to raise_error /Cross-database data modification.*The gitlab_schema was undefined/
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