diff options
Diffstat (limited to 'spec/services/issues/update_service_spec.rb')
-rw-r--r-- | spec/services/issues/update_service_spec.rb | 179 |
1 files changed, 157 insertions, 22 deletions
diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index 42452e95f6b..f0092c35fda 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -52,7 +52,8 @@ RSpec.describe Issues::UpdateService, :mailer do state_event: 'close', label_ids: [label.id], due_date: Date.tomorrow, - discussion_locked: true + discussion_locked: true, + severity: 'low' } end @@ -71,6 +72,51 @@ RSpec.describe Issues::UpdateService, :mailer do expect(issue.discussion_locked).to be_truthy end + context 'when issue type is not incident' do + it 'returns default severity' do + update_issue(opts) + + expect(issue.severity).to eq(IssuableSeverity::DEFAULT) + end + + it_behaves_like 'not an incident issue' do + before do + update_issue(opts) + end + end + end + + context 'when issue type is incident' do + let(:issue) { create(:incident, project: project) } + + it 'changes updates the severity' do + update_issue(opts) + + expect(issue.severity).to eq('low') + end + + it_behaves_like 'incident issue' do + before do + update_issue(opts) + end + end + + context 'with existing incident label' do + let_it_be(:incident_label) { create(:label, :incident, project: project) } + + before do + opts.delete(:label_ids) # don't override but retain existing labels + issue.labels << incident_label + end + + it_behaves_like 'incident issue' do + before do + update_issue(opts) + end + end + end + end + it 'refreshes the number of open issues when the issue is made confidential', :use_clean_rails_memory_store_caching do issue # make sure the issue is created first so our counts are correct. @@ -93,6 +139,40 @@ RSpec.describe Issues::UpdateService, :mailer do update_issue(confidential: false) end + context 'issue in incident type' do + let(:current_user) { user } + let(:incident_label_attributes) { attributes_for(:label, :incident) } + + before do + opts.merge!(issue_type: 'incident', confidential: true) + end + + subject { update_issue(opts) } + + it_behaves_like 'an incident management tracked event', :incident_management_incident_change_confidential + + it_behaves_like 'incident issue' do + before do + subject + end + end + + it 'does create an incident label' do + expect { subject } + .to change { Label.where(incident_label_attributes).count }.by(1) + end + + context 'when invalid' do + before do + opts.merge!(title: '') + end + + it 'does not create an incident label prematurely' do + expect { subject }.not_to change(Label, :count) + end + end + end + it 'updates open issue counter for assignees when issue is reassigned' do update_issue(assignee_ids: [user2.id]) @@ -106,7 +186,7 @@ RSpec.describe Issues::UpdateService, :mailer do [issue, issue1, issue2].each do |issue| issue.move_to_end - issue.save + issue.save! end opts[:move_between_ids] = [issue1.id, issue2.id] @@ -116,6 +196,66 @@ RSpec.describe Issues::UpdateService, :mailer do expect(issue.relative_position).to be_between(issue1.relative_position, issue2.relative_position) end + it 'does not rebalance even if needed if the flag is disabled' do + stub_feature_flags(rebalance_issues: false) + + range = described_class::NO_REBALANCING_NEEDED + issue1 = create(:issue, project: project, relative_position: range.first - 100) + issue2 = create(:issue, project: project, relative_position: range.first) + issue.update!(relative_position: RelativePositioning::START_POSITION) + + opts[:move_between_ids] = [issue1.id, issue2.id] + + expect(IssueRebalancingWorker).not_to receive(:perform_async) + + update_issue(opts) + expect(issue.relative_position).to be_between(issue1.relative_position, issue2.relative_position) + end + + it 'rebalances if needed if the flag is enabled for the project' do + stub_feature_flags(rebalance_issues: project) + + range = described_class::NO_REBALANCING_NEEDED + issue1 = create(:issue, project: project, relative_position: range.first - 100) + issue2 = create(:issue, project: project, relative_position: range.first) + issue.update!(relative_position: RelativePositioning::START_POSITION) + + opts[:move_between_ids] = [issue1.id, issue2.id] + + expect(IssueRebalancingWorker).to receive(:perform_async).with(nil, project.id) + + update_issue(opts) + expect(issue.relative_position).to be_between(issue1.relative_position, issue2.relative_position) + end + + it 'rebalances if needed on the left' do + range = described_class::NO_REBALANCING_NEEDED + issue1 = create(:issue, project: project, relative_position: range.first - 100) + issue2 = create(:issue, project: project, relative_position: range.first) + issue.update!(relative_position: RelativePositioning::START_POSITION) + + opts[:move_between_ids] = [issue1.id, issue2.id] + + expect(IssueRebalancingWorker).to receive(:perform_async).with(nil, project.id) + + update_issue(opts) + expect(issue.relative_position).to be_between(issue1.relative_position, issue2.relative_position) + end + + it 'rebalances if needed on the right' do + range = described_class::NO_REBALANCING_NEEDED + issue1 = create(:issue, project: project, relative_position: range.last) + issue2 = create(:issue, project: project, relative_position: range.last + 100) + issue.update!(relative_position: RelativePositioning::START_POSITION) + + opts[:move_between_ids] = [issue1.id, issue2.id] + + expect(IssueRebalancingWorker).to receive(:perform_async).with(nil, project.id) + + update_issue(opts) + expect(issue.relative_position).to be_between(issue1.relative_position, issue2.relative_position) + end + context 'when moving issue between issues from different projects' do let(:group) { create(:group) } let(:subgroup) { create(:group, parent: group) } @@ -294,7 +434,7 @@ RSpec.describe Issues::UpdateService, :mailer do end it 'does not update assignee_id with unauthorized users' do - project.update(visibility_level: Gitlab::VisibilityLevel::PUBLIC) + project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) update_issue(confidential: true) non_member = create(:user) original_assignees = issue.assignees @@ -382,13 +522,16 @@ RSpec.describe Issues::UpdateService, :mailer do expect(Todo.where(attributes).count).to eq(1) end - end - context 'when the milestone is removed' do - before do - stub_feature_flags(track_resource_milestone_change_events: false) + context 'issue is incident type' do + let(:issue) { create(:incident, project: project) } + let(:current_user) { user } + + it_behaves_like 'an incident management tracked event', :incident_management_incident_assigned end + end + context 'when the milestone is removed' do let!(:non_subscriber) { create(:user) } let!(:subscriber) do @@ -398,12 +541,10 @@ RSpec.describe Issues::UpdateService, :mailer do end end - it_behaves_like 'system notes for milestones' - it 'sends notifications for subscribers of changed milestone', :sidekiq_might_not_need_inline do issue.milestone = create(:milestone, project: project) - issue.save + issue.save! perform_enqueued_jobs do update_issue(milestone_id: "") @@ -416,7 +557,7 @@ RSpec.describe Issues::UpdateService, :mailer do it 'clears milestone issue counters cache' do issue.milestone = create(:milestone, project: project) - issue.save + issue.save! expect_next_instance_of(Milestones::IssuesCountService, issue.milestone) do |service| expect(service).to receive(:delete_cache).and_call_original @@ -430,10 +571,6 @@ RSpec.describe Issues::UpdateService, :mailer do end context 'when the milestone is assigned' do - before do - stub_feature_flags(track_resource_milestone_change_events: false) - end - let!(:non_subscriber) { create(:user) } let!(:subscriber) do @@ -449,8 +586,6 @@ RSpec.describe Issues::UpdateService, :mailer do expect(todo.reload.done?).to eq true end - it_behaves_like 'system notes for milestones' - it 'sends notifications for subscribers of changed milestone', :sidekiq_might_not_need_inline do perform_enqueued_jobs do update_issue(milestone: create(:milestone, project: project)) @@ -670,7 +805,7 @@ RSpec.describe Issues::UpdateService, :mailer do let(:params) { { label_ids: [label.id], add_label_ids: [label3.id] } } before do - issue.update(labels: [label2]) + issue.update!(labels: [label2]) end it 'replaces the labels with the ones in label_ids and adds those in add_label_ids' do @@ -682,7 +817,7 @@ RSpec.describe Issues::UpdateService, :mailer do let(:params) { { label_ids: [label.id, label2.id, label3.id], remove_label_ids: [label.id] } } before do - issue.update(labels: [label, label3]) + issue.update!(labels: [label, label3]) end it 'replaces the labels with the ones in label_ids and removes those in remove_label_ids' do @@ -694,7 +829,7 @@ RSpec.describe Issues::UpdateService, :mailer do let(:params) { { add_label_ids: [label3.id], remove_label_ids: [label.id] } } before do - issue.update(labels: [label]) + issue.update!(labels: [label]) end it 'adds the passed labels' do @@ -711,7 +846,7 @@ RSpec.describe Issues::UpdateService, :mailer do context 'for a label assigned to an issue' do it 'removes the label' do - issue.update(labels: [label]) + issue.update!(labels: [label]) expect(result.label_ids).to be_empty end @@ -760,7 +895,7 @@ RSpec.describe Issues::UpdateService, :mailer do levels.each do |level| it "does not update with unauthorized assignee when project is #{Gitlab::VisibilityLevel.level_name(level)}" do assignee = create(:user) - project.update(visibility_level: level) + project.update!(visibility_level: level) feature_visibility_attr = :"#{issue.model_name.plural}_access_level" project.project_feature.update_attribute(feature_visibility_attr, ProjectFeature::PRIVATE) |