diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-05 15:09:57 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-05 15:09:57 +0300 |
commit | 5147cd60f141434f82ce95cc9039afddf415f02b (patch) | |
tree | ece2297b7c363648f7f744bd45abc7f5be736030 /spec/support_specs | |
parent | 258cd2409347baa19566d8bf34207521c142d8b7 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support_specs')
-rw-r--r-- | spec/support_specs/database/prevent_cross_joins_spec.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/support_specs/database/prevent_cross_joins_spec.rb b/spec/support_specs/database/prevent_cross_joins_spec.rb new file mode 100644 index 00000000000..dd4ed9c40b8 --- /dev/null +++ b/spec/support_specs/database/prevent_cross_joins_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Database::PreventCrossJoins do + context 'when running in :prevent_cross_joins scope', :prevent_cross_joins do + context 'when only non-CI tables are used' do + it 'does not raise exception' do + expect { main_only_query }.not_to raise_error + end + end + + context 'when only CI tables are used' do + it 'does not raise exception' do + expect { ci_only_query }.not_to raise_error + end + end + + context 'when CI and non-CI tables are used' do + it 'raises exception' do + expect { main_and_ci_query }.to raise_error( + described_class::CrossJoinAcrossUnsupportedTablesError) + end + + context 'when allow_cross_joins_across_databases is used' do + it 'does not raise exception' do + Gitlab::Database.allow_cross_joins_across_databases(url: 'http://issue-url') + + expect { main_and_ci_query }.not_to raise_error + end + end + end + end + + context 'when running in a default scope' do + context 'when CI and non-CI tables are used' do + it 'does not raise exception' do + expect { main_and_ci_query }.not_to raise_error + end + end + end + + private + + def main_only_query + Issue.joins(:project).last + end + + def ci_only_query + Ci::Build.joins(:pipeline).last + end + + def main_and_ci_query + Ci::Build.joins(:project).last + end +end |