diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /spec/support/shared_examples/models | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'spec/support/shared_examples/models')
5 files changed, 100 insertions, 18 deletions
diff --git a/spec/support/shared_examples/models/concerns/analytics/cycle_analytics/stage_event_model_examples.rb b/spec/support/shared_examples/models/concerns/analytics/cycle_analytics/stage_event_model_examples.rb index d823e7ac221..8ff30021d6e 100644 --- a/spec/support/shared_examples/models/concerns/analytics/cycle_analytics/stage_event_model_examples.rb +++ b/spec/support/shared_examples/models/concerns/analytics/cycle_analytics/stage_event_model_examples.rb @@ -178,4 +178,22 @@ RSpec.shared_examples 'StageEventModel' do end end end + + describe '#total_time' do + it 'calcualtes total time from the start_event_timestamp and end_event_timestamp columns' do + model = described_class.new(start_event_timestamp: Time.new(2022, 1, 1, 12, 5, 0), end_event_timestamp: Time.new(2022, 1, 1, 12, 6, 30)) + + expect(model.total_time).to eq(90) + end + + context 'when total time is calculated in SQL as an extra column' do + it 'returns the SQL calculated time' do + create(stage_event_factory) # rubocop:disable Rails/SaveBang + + model = described_class.select('*, 5 AS total_time').first + + expect(model.total_time).to eq(5) + end + end + end end diff --git a/spec/support/shared_examples/models/member_shared_examples.rb b/spec/support/shared_examples/models/member_shared_examples.rb index 5b4b8c8fcc1..f7e09cfca62 100644 --- a/spec/support/shared_examples/models/member_shared_examples.rb +++ b/spec/support/shared_examples/models/member_shared_examples.rb @@ -301,8 +301,9 @@ RSpec.shared_examples_for "member creation" do end context 'when `tasks_to_be_done` and `tasks_project_id` are passed' do + let(:task_project) { source.is_a?(Group) ? create(:project, group: source) : source } + it 'creates a member_task with the correct attributes', :aggregate_failures do - task_project = source.is_a?(Group) ? create(:project, group: source) : source described_class.new(source, user, :developer, tasks_to_be_done: %w(ci code), tasks_project_id: task_project.id).execute member = source.members.last @@ -310,6 +311,43 @@ RSpec.shared_examples_for "member creation" do expect(member.tasks_to_be_done).to match_array([:ci, :code]) expect(member.member_task.project).to eq(task_project) end + + context 'with an already existing member' do + before do + source.add_user(user, :developer) + end + + it 'does not update tasks to be done if tasks already exist', :aggregate_failures do + member = source.members.find_by(user_id: user.id) + create(:member_task, member: member, project: task_project, tasks_to_be_done: %w(code ci)) + + expect do + described_class.new(source, + user, + :developer, + tasks_to_be_done: %w(issues), + tasks_project_id: task_project.id).execute + end.not_to change(MemberTask, :count) + + member.reset + expect(member.tasks_to_be_done).to match_array([:code, :ci]) + expect(member.member_task.project).to eq(task_project) + end + + it 'adds tasks to be done if they do not exist', :aggregate_failures do + expect do + described_class.new(source, + user, + :developer, + tasks_to_be_done: %w(issues), + tasks_project_id: task_project.id).execute + end.to change(MemberTask, :count).by(1) + + member = source.members.find_by(user_id: user.id) + expect(member.tasks_to_be_done).to match_array([:issues]) + expect(member.member_task.project).to eq(task_project) + end + end end end end @@ -393,14 +431,52 @@ RSpec.shared_examples_for "bulk member creation" do end context 'when `tasks_to_be_done` and `tasks_project_id` are passed' do + let(:task_project) { source.is_a?(Group) ? create(:project, group: source) : source } + it 'creates a member_task with the correct attributes', :aggregate_failures do - task_project = source.is_a?(Group) ? create(:project, group: source) : source members = described_class.add_users(source, [user1], :developer, tasks_to_be_done: %w(ci code), tasks_project_id: task_project.id) member = members.last expect(member.tasks_to_be_done).to match_array([:ci, :code]) expect(member.member_task.project).to eq(task_project) end + + context 'with an already existing member' do + before do + source.add_user(user1, :developer) + end + + it 'does not update tasks to be done if tasks already exist', :aggregate_failures do + member = source.members.find_by(user_id: user1.id) + create(:member_task, member: member, project: task_project, tasks_to_be_done: %w(code ci)) + + expect do + described_class.add_users(source, + [user1.id], + :developer, + tasks_to_be_done: %w(issues), + tasks_project_id: task_project.id) + end.not_to change(MemberTask, :count) + + member.reset + expect(member.tasks_to_be_done).to match_array([:code, :ci]) + expect(member.member_task.project).to eq(task_project) + end + + it 'adds tasks to be done if they do not exist', :aggregate_failures do + expect do + described_class.add_users(source, + [user1.id], + :developer, + tasks_to_be_done: %w(issues), + tasks_project_id: task_project.id) + end.to change(MemberTask, :count).by(1) + + member = source.members.find_by(user_id: user1.id) + expect(member.tasks_to_be_done).to match_array([:issues]) + expect(member.member_task.project).to eq(task_project) + end + end end end end diff --git a/spec/support/shared_examples/models/note_access_check_shared_examples.rb b/spec/support/shared_examples/models/note_access_check_shared_examples.rb index 44edafe9091..0c9992b832f 100644 --- a/spec/support/shared_examples/models/note_access_check_shared_examples.rb +++ b/spec/support/shared_examples/models/note_access_check_shared_examples.rb @@ -3,7 +3,7 @@ RSpec.shared_examples 'users with note access' do it 'returns true' do users.each do |user| - expect(note.system_note_with_references_visible_for?(user)).to be_truthy + expect(note.system_note_visible_for?(user)).to be_truthy expect(note.readable_by?(user)).to be_truthy end end @@ -12,7 +12,7 @@ end RSpec.shared_examples 'users without note access' do it 'returns false' do users.each do |user| - expect(note.system_note_with_references_visible_for?(user)).to be_falsy + expect(note.system_note_visible_for?(user)).to be_falsy expect(note.readable_by?(user)).to be_falsy end end diff --git a/spec/support/shared_examples/models/packages/debian/distribution_shared_examples.rb b/spec/support/shared_examples/models/packages/debian/distribution_shared_examples.rb index 3f8c3b8960b..6b0ae589efb 100644 --- a/spec/support/shared_examples/models/packages/debian/distribution_shared_examples.rb +++ b/spec/support/shared_examples/models/packages/debian/distribution_shared_examples.rb @@ -235,18 +235,6 @@ RSpec.shared_examples 'Debian Distribution' do |factory, container, can_freeze| it 'does not return them' do expect(subject.to_a).not_to include(package_file_pending_destruction) end - - context 'with packages_installable_package_files disabled' do - before do - stub_feature_flags(packages_installable_package_files: false) - end - - it 'returns them' do - subject - - expect(subject.to_a).to include(package_file_pending_destruction) - end - end end end end diff --git a/spec/support/shared_examples/models/update_project_statistics_shared_examples.rb b/spec/support/shared_examples/models/update_project_statistics_shared_examples.rb index 06326ffac97..ad0bbc0aeff 100644 --- a/spec/support/shared_examples/models/update_project_statistics_shared_examples.rb +++ b/spec/support/shared_examples/models/update_project_statistics_shared_examples.rb @@ -115,14 +115,14 @@ RSpec.shared_examples 'UpdateProjectStatistics' do |with_counter_attribute| expect(ProjectStatistics) .not_to receive(:increment_statistic) - expect(Projects::DestroyService.new(project, project.owner).execute).to eq(true) + expect(Projects::DestroyService.new(project, project.first_owner).execute).to eq(true) end it 'does not schedule a namespace statistics worker' do expect(Namespaces::ScheduleAggregationWorker) .not_to receive(:perform_async) - expect(Projects::DestroyService.new(project, project.owner).execute).to eq(true) + expect(Projects::DestroyService.new(project, project.first_owner).execute).to eq(true) end end end |