forked from fractaledmind/solid_errors
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleaner_test.rb
More file actions
56 lines (45 loc) · 1.53 KB
/
cleaner_test.rb
File metadata and controls
56 lines (45 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require "test_helper"
class SolidErrors::CleanerTest < ActiveSupport::TestCase
setup do
assert_nil SolidErrors.destroy_after
end
test "not destroy if destroy_after is not set" do
simulate_99_old_exceptions(:resolved)
assert_difference -> { SolidErrors::Error.count }, +1 do
assert_difference -> { SolidErrors::Occurrence.count }, +1 do
Rails.error.report(dummy_exception)
end
end
end
test "destroy old occurrences every 100 insertions if destroy_after is set" do
set_destroy_after
simulate_99_old_exceptions(:resolved)
Rails.error.report(dummy_exception)
assert_equal 1, SolidErrors::Error.count
assert_equal 1, SolidErrors::Occurrence.count
end
test "not destroy if errors are unresolved" do
set_destroy_after
simulate_99_old_exceptions(:unresolved)
assert_difference -> { SolidErrors::Error.count }, +1 do
assert_difference -> { SolidErrors::Occurrence.count }, +1 do
assert_empty SolidErrors::Error.resolved
Rails.error.report(dummy_exception)
end
end
end
private
def simulate_99_old_exceptions(status)
Rails.error.report(dummy_exception("argh"))
SolidErrors::Error.update_all(resolved_at: Time.current) if status == :resolved
SolidErrors::Occurrence.last.update!(id: 99, created_at: 1.day.ago)
end
def set_destroy_after
SolidErrors.stubs(destroy_after: 1.day)
end
def dummy_exception(message = "oof")
exception = StandardError.new(message)
exception.set_backtrace(caller)
exception
end
end