Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resend notifications when generating notices on resolved problems #1368

Merged
merged 1 commit into from Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/models/error_report.rb
Expand Up @@ -22,6 +22,7 @@ class ErrorReport
attr_reader :notice
attr_reader :notifier
attr_reader :problem
attr_reader :problem_was_resolved
attr_reader :request
attr_reader :server_environment
attr_reader :user_attributes
Expand Down Expand Up @@ -55,6 +56,7 @@ def generate_notice!
notice.err_id = error.id
notice.save!

retrieve_problem_was_resolved
cache_attributes_on_problem
email_notification
services_notification
Expand All @@ -75,13 +77,18 @@ def make_notice
)
end

def retrieve_problem_was_resolved
@problem_was_resolved = Problem.where('_id' => @error.problem_id, resolved: true).exists?
end

# Update problem cache with information about this notice
def cache_attributes_on_problem
@problem = Problem.cache_notice(@error.problem_id, @notice)
end

def should_email?
app.email_at_notices.include?(0) ||
problem_was_resolved ||
app.email_at_notices.include?(0) ||
app.email_at_notices.include?(@problem.notices_count)
end

Expand All @@ -94,7 +101,8 @@ def email_notification
end

def should_notify?
app.notification_service.notify_at_notices.include?(0) ||
problem_was_resolved ||
app.notification_service.notify_at_notices.include?(0) ||
app.notification_service.notify_at_notices.include?(@problem.notices_count)
end

Expand Down
8 changes: 8 additions & 0 deletions spec/models/error_report_spec.rb
Expand Up @@ -283,6 +283,14 @@ def framework
3.times { described_class.new(xml).generate_notice! }
expect(ActionMailer::Base.deliveries.length).to eq(2)
end

it "sends email on all occurrences when problem was resolved" do
3.times do
notice = described_class.new(xml).generate_notice!
notice.problem.resolve!
end
expect(ActionMailer::Base.deliveries.length).to eq(3)
end
end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/models/notice_observer_spec.rb
Expand Up @@ -192,5 +192,15 @@
to_not receive(:create_notification)
error_report.generate_notice! # three
end

it "should create a campfire notification when problem was resolved" do
ErrorReport.new(notice_attrs).generate_notice! # one
notice = ErrorReport.new(notice_attrs).generate_notice! # two
notice.problem.resolve!
error_report = ErrorReport.new(notice_attrs)
expect(error_report.app.notification_service).
to receive(:create_notification)
error_report.generate_notice! # three
end
end
end