diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-14 18:09:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-14 18:09:43 +0300 |
commit | 7a33080fff9a735cbe77968d67b13ffa92c0ffae (patch) | |
tree | 71a880649c8d3e551ec6bd94e93d08a9a9b5bde7 /spec/lib | |
parent | 9223573b85bcfdd21953f52e0d2c5cb587e366a1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/extracts_ref_spec.rb | 59 | ||||
-rw-r--r-- | spec/lib/gitlab/pagination/cursor_based_keyset_spec.rb | 9 | ||||
-rw-r--r-- | spec/lib/gitlab/project_authorizations_spec.rb | 50 |
3 files changed, 116 insertions, 2 deletions
diff --git a/spec/lib/extracts_ref_spec.rb b/spec/lib/extracts_ref_spec.rb index 93a09bf5a0a..ac403ad642a 100644 --- a/spec/lib/extracts_ref_spec.rb +++ b/spec/lib/extracts_ref_spec.rb @@ -57,5 +57,64 @@ RSpec.describe ExtractsRef do end end + describe '#ref_type' do + let(:params) { ActionController::Parameters.new(ref_type: 'heads') } + + it 'delegates to .ref_type' do + expect(described_class).to receive(:ref_type).with('heads') + ref_type + end + end + + describe '.ref_type' do + subject { described_class.ref_type(ref_type) } + + context 'when ref_type is nil' do + let(:ref_type) { nil } + + it { is_expected.to eq(nil) } + end + + context 'when ref_type is heads' do + let(:ref_type) { 'heads' } + + it { is_expected.to eq('heads') } + end + + context 'when ref_type is tags' do + let(:ref_type) { 'tags' } + + it { is_expected.to eq('tags') } + end + + context 'when ref_type is invalid' do + let(:ref_type) { 'invalid' } + + it { is_expected.to eq(nil) } + end + end + + describe '.qualify_ref' do + subject { described_class.qualify_ref(ref, ref_type) } + + context 'when ref_type is nil' do + let(:ref_type) { nil } + + it { is_expected.to eq(ref) } + end + + context 'when ref_type valid' do + let(:ref_type) { 'heads' } + + it { is_expected.to eq("refs/#{ref_type}/#{ref}") } + end + + context 'when ref_type is invalid' do + let(:ref_type) { 'invalid' } + + it { is_expected.to eq(ref) } + end + end + it_behaves_like 'extracts refs' end diff --git a/spec/lib/gitlab/pagination/cursor_based_keyset_spec.rb b/spec/lib/gitlab/pagination/cursor_based_keyset_spec.rb index dc62fcb4478..7cee65c13f7 100644 --- a/spec/lib/gitlab/pagination/cursor_based_keyset_spec.rb +++ b/spec/lib/gitlab/pagination/cursor_based_keyset_spec.rb @@ -14,6 +14,10 @@ RSpec.describe Gitlab::Pagination::CursorBasedKeyset do expect(subject.available_for_type?(Ci::Build.all)).to be_truthy end + it 'returns true for Packages::BuildInfo' do + expect(subject.available_for_type?(Packages::BuildInfo.all)).to be_truthy + end + it 'return false for other types of relations' do expect(subject.available_for_type?(User.all)).to be_falsey end @@ -56,6 +60,7 @@ RSpec.describe Gitlab::Pagination::CursorBasedKeyset do it 'return false for other types of relations' do expect(subject.available?(cursor_based_request_context, User.all)).to be_falsey expect(subject.available?(cursor_based_request_context, Ci::Build.all)).to be_falsey + expect(subject.available?(cursor_based_request_context, Packages::BuildInfo.all)).to be_falsey end end @@ -70,6 +75,10 @@ RSpec.describe Gitlab::Pagination::CursorBasedKeyset do it 'returns true for AuditEvent' do expect(subject.available?(cursor_based_request_context, AuditEvent.all)).to be_truthy end + + it 'returns true for Packages::BuildInfo' do + expect(subject.available?(cursor_based_request_context, Packages::BuildInfo.all)).to be_truthy + end end context 'with other order-by columns' do diff --git a/spec/lib/gitlab/project_authorizations_spec.rb b/spec/lib/gitlab/project_authorizations_spec.rb index b076bb65fb5..f3dcdfe2a9d 100644 --- a/spec/lib/gitlab/project_authorizations_spec.rb +++ b/spec/lib/gitlab/project_authorizations_spec.rb @@ -9,8 +9,10 @@ RSpec.describe Gitlab::ProjectAuthorizations, feature_category: :system_access d end end + let(:service) { described_class.new(user) } + subject(:authorizations) do - described_class.new(user).calculate + service.calculate end # Inline this shared example while cleaning up feature flag linear_project_authorization @@ -421,9 +423,53 @@ RSpec.describe Gitlab::ProjectAuthorizations, feature_category: :system_access d end end - context 'when feature_flag linear_project_authorization_is disabled' do + context 'it compares values for correctness' do + let_it_be(:user) { create(:user) } + + context 'when values returned by the queries are the same' do + it 'logs a message indicating that the values are the same' do + expect(Gitlab::AppJsonLogger).to receive(:info).with(event: 'linear_authorized_projects_check', + user_id: user.id, + matching_results: true) + service.calculate + end + end + + context 'when values returned by queries are diffrent' do + before do + create(:project_authorization) + allow(service).to receive(:calculate_with_linear_query).and_return(ProjectAuthorization.all) + end + + it 'logs a message indicating that the values are different' do + expect(Gitlab::AppJsonLogger).to receive(:warn).with(event: 'linear_authorized_projects_check', + user_id: user.id, + matching_results: false) + service.calculate + end + end + end + + context 'when feature_flag linear_project_authorization is disabled' do + before do + stub_feature_flags(linear_project_authorization: false) + end + + it_behaves_like 'project authorizations' + end + + context 'when feature_flag compare_project_authorization_linear_cte is disabled' do + before do + stub_feature_flags(compare_project_authorization_linear_cte: false) + end + + it_behaves_like 'project authorizations' + end + + context 'when feature_flag linear_project_authorization and compare_project_authorization_linear_cte are disabled' do before do stub_feature_flags(linear_project_authorization: false) + stub_feature_flags(compare_project_authorization_linear_cte: false) end it_behaves_like 'project authorizations' |