Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/issue_spec.rb')
-rw-r--r--spec/models/issue_spec.rb55
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