diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/models/issue_spec.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) | |
download | gitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/models/issue_spec.rb')
-rw-r--r-- | spec/models/issue_spec.rb | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index dd5ff3dbdde..291cccd72db 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -21,6 +21,9 @@ describe Issue do it { is_expected.to have_one(:alert_management_alert) } it { is_expected.to have_many(:resource_milestone_events) } it { is_expected.to have_many(:resource_state_events) } + it { is_expected.to have_and_belong_to_many(:prometheus_alert_events) } + it { is_expected.to have_and_belong_to_many(:self_managed_prometheus_alert_events) } + it { is_expected.to have_many(:prometheus_alerts) } describe 'versions.most_recent' do it 'returns the most recent version' do @@ -176,7 +179,7 @@ describe Issue do describe '#close' do subject(:issue) { create(:issue, state: 'opened') } - it 'sets closed_at to Time.now when an issue is closed' do + it 'sets closed_at to Time.current when an issue is closed' do expect { issue.close }.to change { issue.closed_at }.from(nil) end @@ -186,11 +189,40 @@ describe Issue do expect { issue.close }.to change { issue.state_id }.from(open_state).to(closed_state) end + + context 'when there is an associated Alert Management Alert' do + context 'when alert can be resolved' do + let!(:alert) { create(:alert_management_alert, project: issue.project, issue: issue) } + + it 'resolves an alert' do + expect { issue.close }.to change { alert.reload.resolved? }.to(true) + end + end + + context 'when alert cannot be resolved' do + let!(:alert) { create(:alert_management_alert, :with_validation_errors, project: issue.project, issue: issue) } + + before do + allow(Gitlab::AppLogger).to receive(:warn).and_call_original + end + + it 'writes a warning into the log' do + issue.close + + expect(Gitlab::AppLogger).to have_received(:warn).with( + message: 'Cannot resolve an associated Alert Management alert', + issue_id: issue.id, + alert_id: alert.id, + alert_errors: { hosts: ['hosts array is over 255 chars'] } + ) + end + end + end end describe '#reopen' do let(:user) { create(:user) } - let(:issue) { create(:issue, state: 'closed', closed_at: Time.now, closed_by: user) } + let(:issue) { create(:issue, state: 'closed', closed_at: Time.current, closed_by: user) } it 'sets closed_at to nil when an issue is reopend' do expect { issue.reopen }.to change { issue.closed_at }.to(nil) @@ -994,7 +1026,7 @@ describe Issue do it_behaves_like 'versioned description' describe "#previous_updated_at" do - let_it_be(:updated_at) { Time.new(2012, 01, 06) } + let_it_be(:updated_at) { Time.zone.local(2012, 01, 06) } let_it_be(:issue) { create(:issue, updated_at: updated_at) } it 'returns updated_at value if updated_at did not change at all' do @@ -1010,15 +1042,15 @@ describe Issue do end it 'returns updated_at value if previous updated_at value is not present' do - allow(issue).to receive(:previous_changes).and_return({ 'updated_at' => [nil, Time.new(2013, 02, 06)] }) + allow(issue).to receive(:previous_changes).and_return({ 'updated_at' => [nil, Time.zone.local(2013, 02, 06)] }) expect(issue.previous_updated_at).to eq(updated_at) end it 'returns previous updated_at when present' do - allow(issue).to receive(:previous_changes).and_return({ 'updated_at' => [Time.new(2013, 02, 06), Time.new(2013, 03, 06)] }) + allow(issue).to receive(:previous_changes).and_return({ 'updated_at' => [Time.zone.local(2013, 02, 06), Time.zone.local(2013, 03, 06)] }) - expect(issue.previous_updated_at).to eq(Time.new(2013, 02, 06)) + expect(issue.previous_updated_at).to eq(Time.zone.local(2013, 02, 06)) end end @@ -1085,4 +1117,15 @@ describe Issue do expect(subject).not_to include(labeled_issue) end end + + describe 'banzai_render_context' do + let(:project) { build(:project_empty_repo) } + let(:issue) { build :issue, project: project } + + subject(:context) { issue.banzai_render_context(:title) } + + it 'sets the label_url_method in the context' do + expect(context[:label_url_method]).to eq(:project_issues_url) + end + end end |