diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-05 18:08:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-05 18:08:05 +0300 |
commit | 4ba8ae97071935c39216afc53304c60386bbfa68 (patch) | |
tree | 452038ff8d19dcf69453dde0079b1db4870a3aae /spec/models | |
parent | 7120254aee218529320c061696a2af530494e6aa (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/concerns/routable_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/member_spec.rb | 54 | ||||
-rw-r--r-- | spec/models/members/group_member_spec.rb | 35 | ||||
-rw-r--r-- | spec/models/merge_request_diff_spec.rb | 47 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 32 |
5 files changed, 118 insertions, 58 deletions
diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb index c6135e769cc..84bff839d1b 100644 --- a/spec/models/concerns/routable_spec.rb +++ b/spec/models/concerns/routable_spec.rb @@ -130,14 +130,6 @@ RSpec.shared_examples 'routable resource' do end it_behaves_like '.where_full_path_in', :aggregate_failures - - context 'when the `optimize_where_full_path_in` feature flag is turned OFF' do - before do - stub_feature_flags(optimize_where_full_path_in: false) - end - - it_behaves_like '.where_full_path_in', :aggregate_failures - end end RSpec.shared_examples 'routable resource with parent' do diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 9ebff2a8886..9419bfa76a7 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -922,6 +922,40 @@ RSpec.describe Member, feature_category: :groups_and_projects do expect(member.invite_token).not_to be_nil expect_any_instance_of(described_class).not_to receive(:after_accept_invite) end + + context 'when after accepting invite' do + include NotificationHelpers + + let_it_be(:group) { create(:group, require_two_factor_authentication: true) } + let_it_be(:member, reload: true) { create(:group_member, :invited, source: group) } + let_it_be(:email) { member.invite_email } + let(:user) { build(:user, email: email) } + + it 'enqueues an email to user' do + member.accept_invite!(user) + + expect_enqueud_email(member.real_source_type, member.id, mail: 'member_invite_accepted_email') + end + + it 'calls updates the two factor requirement' do + expect(user).to receive(:require_two_factor_authentication_from_group).and_call_original + + member.accept_invite!(user) + + expect(user.require_two_factor_authentication_from_group).to be_truthy + end + + context 'when member source is a project' do + let_it_be(:project) { create(:project, namespace: group) } + let_it_be(:member) { create(:project_member, :invited, source: project, invite_email: email) } + + it 'calls updates the two factor requirement' do + expect(user).not_to receive(:require_two_factor_authentication_from_group) + + member.accept_invite!(user) + end + end + end end describe '#decline_invite!' do @@ -1201,6 +1235,26 @@ RSpec.describe Member, feature_category: :groups_and_projects do end end + context 'when after_create :update_two_factor_requirement' do + it 'calls update_two_factor_requirement after creation' do + user = create(:user) + + expect(user).to receive(:update_two_factor_requirement) + + create(:group_member, user: user) + end + end + + context 'when after_destroy :update_two_factor_requirement' do + it 'calls update_two_factor_requirement after deletion' do + group_member = create(:group_member) + + expect(group_member.user).to receive(:update_two_factor_requirement) + + group_member.destroy! + end + end + describe 'log_invitation_token_cleanup' do let_it_be(:project) { create :project } diff --git a/spec/models/members/group_member_spec.rb b/spec/models/members/group_member_spec.rb index 4df0b1e6af5..3b23f3661f8 100644 --- a/spec/models/members/group_member_spec.rb +++ b/spec/models/members/group_member_spec.rb @@ -33,10 +33,6 @@ RSpec.describe GroupMember, feature_category: :cell do end end - describe 'delegations' do - it { is_expected.to delegate_method(:update_two_factor_requirement).to(:user).allow_nil } - end - describe '.access_level_roles' do it 'returns Gitlab::Access.options_with_owner' do expect(described_class.access_level_roles).to eq(Gitlab::Access.options_with_owner) @@ -67,22 +63,6 @@ RSpec.describe GroupMember, feature_category: :cell do it { is_expected.to eq 'Group' } end - describe '#update_two_factor_requirement' do - it 'is called after creation and deletion' do - user = create :user - group = create :group - group_member = build :group_member, user: user, group: group - - expect(user).to receive(:update_two_factor_requirement) - - group_member.save! - - expect(user).to receive(:update_two_factor_requirement) - - group_member.destroy! - end - end - describe '#destroy' do context 'for an orphaned member' do let!(:orphaned_group_member) do @@ -95,21 +75,6 @@ RSpec.describe GroupMember, feature_category: :cell do end end - describe '#after_accept_invite' do - it 'calls #update_two_factor_requirement' do - email = 'foo@email.com' - user = build(:user, email: email) - group = create(:group, require_two_factor_authentication: true) - group_member = create(:group_member, group: group, invite_token: '1234', invite_email: email) - - expect(user).to receive(:require_two_factor_authentication_from_group).and_call_original - - group_member.accept_invite!(user) - - expect(user.require_two_factor_authentication_from_group).to be_truthy - end - end - describe '#last_owner_of_the_group?' do let_it_be(:parent_group) { create(:group) } let_it_be(:group) { create(:group, parent: parent_group) } diff --git a/spec/models/merge_request_diff_spec.rb b/spec/models/merge_request_diff_spec.rb index 5a77faaf750..005318d036a 100644 --- a/spec/models/merge_request_diff_spec.rb +++ b/spec/models/merge_request_diff_spec.rb @@ -933,11 +933,19 @@ RSpec.describe MergeRequestDiff, feature_category: :code_review_workflow do end context 'handling generated files' do - let(:project) { create(:project, :repository) } + let(:project) do + create(:project, :custom_repo, files: { + '.gitattributes' => '*.txt gitlab-generated' + }) + end + + let(:generated_file_name_manual) { 'generated.txt' } + let(:generated_file_name_auto) { 'package-lock.json' } + let(:regular_file_name) { 'regular.rb' } + let(:target_branch) { project.default_branch } let(:source_branch) { 'test-generated-diff-file' } - let(:generated_file_name) { 'generated.txt' } - let(:regular_file_name) { 'regular.rb' } + let(:merge_request) do create( :merge_request, @@ -953,20 +961,34 @@ RSpec.describe MergeRequestDiff, feature_category: :code_review_workflow do end before do - project.repository.update_file( + project.repository.create_branch(source_branch, target_branch) + + project.repository.create_file( project.creator, - '.gitattributes', - '*.txt gitlab-generated', - message: 'Update', - branch_name: target_branch) + generated_file_name_manual, + 'updated generated content', + message: 'Update generated file', + branch_name: source_branch) - create_file_in_repo(project, target_branch, source_branch, generated_file_name, "generated text\n") - create_file_in_repo(project, source_branch, source_branch, regular_file_name, "something else\n") + project.repository.create_file( + project.creator, + generated_file_name_auto, + 'updated generated content', + message: 'Update generated file', + branch_name: source_branch) + + project.repository.create_file( + project.creator, + regular_file_name, + 'updated regular content', + message: "Update regular file", + branch_name: source_branch) end context 'with collapse_generated_diff_files feature flag' do it 'sets generated field correctly' do - expect(diff_files.find_by(new_path: generated_file_name)).to be_generated + expect(diff_files.find_by(new_path: generated_file_name_manual)).to be_generated + expect(diff_files.find_by(new_path: generated_file_name_auto)).to be_generated expect(diff_files.find_by(new_path: regular_file_name)).not_to be_generated end end @@ -977,7 +999,8 @@ RSpec.describe MergeRequestDiff, feature_category: :code_review_workflow do end it 'sets generated field correctly' do - expect(diff_files.find_by(new_path: generated_file_name)).not_to be_generated + expect(diff_files.find_by(new_path: generated_file_name_auto)).not_to be_generated + expect(diff_files.find_by(new_path: generated_file_name_manual)).not_to be_generated expect(diff_files.find_by(new_path: regular_file_name)).not_to be_generated end end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index d9606b50bff..c30bbb3a134 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -5044,10 +5044,36 @@ RSpec.describe MergeRequest, factory_default: :keep, feature_category: :code_rev end describe '#should_be_rebased?' do - it 'returns false for the same source and target branches' do - merge_request = build_stubbed(:merge_request, source_project: project, target_project: project) + let(:merge_request) { build_stubbed(:merge_request) } + + subject { merge_request.should_be_rebased? } + + context 'when the same source and target branches' do + let(:merge_request) { build_stubbed(:merge_request, source_project: project, target_project: project) } + + it { is_expected.to be_falsey } + end + + context 'when the project is using ff merge method' do + before do + allow(merge_request.target_project).to receive(:ff_merge_must_be_possible?).and_return(true) + end + + context 'when the mr needs to be rebased to merge' do + before do + allow(merge_request).to receive(:ff_merge_possible?).and_return(false) + end + + it { is_expected.to be_truthy } + end - expect(merge_request.should_be_rebased?).to be_falsey + context 'when the MR can be merged without rebase' do + before do + allow(merge_request).to receive(:ff_merge_possible?).and_return(true) + end + + it { is_expected.to be_falsey } + end end end |