status_cat 0.1.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -11
- data/app/controllers/status_cat/status_controller.rb +19 -18
- data/app/helpers/status_cat/status_helper.rb +69 -64
- data/app/mailers/status_cat/status_mailer.rb +9 -8
- data/app/views/status_cat/status/index.html.erb +1 -1
- data/app/views/status_cat/status_mailer/failure.html.erb +1 -1
- data/app/views/status_cat/status_mailer/failure.text.erb +1 -1
- data/lib/status_cat.rb +1 -1
- data/lib/status_cat/checkers/action_mailer.rb +33 -17
- data/lib/status_cat/checkers/active_record.rb +22 -7
- data/lib/status_cat/checkers/base.rb +16 -9
- data/lib/status_cat/checkers/delayed_job.rb +21 -16
- data/lib/status_cat/checkers/fitbit.rb +18 -9
- data/lib/status_cat/checkers/profilesio.rb +4 -1
- data/lib/status_cat/checkers/s3.rb +9 -10
- data/lib/status_cat/checkers/send_hub.rb +9 -3
- data/lib/status_cat/checkers/stripe.rb +15 -10
- data/lib/status_cat/checkers/twilio.rb +10 -4
- data/lib/status_cat/config.rb +3 -7
- data/lib/status_cat/status.rb +9 -11
- data/lib/status_cat/version.rb +1 -1
- data/lib/tasks/status_cat.rake +3 -4
- data/spec/controllers/status_cat/status_controller_spec.rb +9 -9
- data/spec/dummy/app/checkers/dummy.rb +2 -2
- data/spec/dummy/app/controllers/application_controller.rb +2 -1
- data/spec/dummy/app/controllers/root_controller.rb +6 -7
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/config/application.rb +2 -2
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/initializers/action_mailer.rb +2 -2
- data/spec/dummy/config/initializers/inflections.rb +1 -1
- data/spec/dummy/config/passwords.yml +5 -0
- data/spec/dummy/config/routes.rb +2 -2
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +0 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +36 -0
- data/spec/dummy/log/test.log +16588 -13366
- data/spec/helpers/status_cat/status_helper_spec.rb +33 -33
- data/spec/hygiene_spec.rb +14 -0
- data/spec/lib/status_cat/checkers/action_mailer_spec.rb +15 -18
- data/spec/lib/status_cat/checkers/active_record_spec.rb +10 -10
- data/spec/lib/status_cat/checkers/base_spec.rb +30 -14
- data/spec/lib/status_cat/checkers/delayed_job_spec.rb +14 -16
- data/spec/lib/status_cat/checkers/fitbit_spec.rb +14 -8
- data/spec/lib/status_cat/checkers/profilesio_spec.rb +12 -12
- data/spec/lib/status_cat/checkers/s3_spec.rb +17 -18
- data/spec/lib/status_cat/checkers/send_hub_spec.rb +14 -8
- data/spec/lib/status_cat/checkers/stripe_spec.rb +18 -24
- data/spec/lib/status_cat/checkers/twilio_spec.rb +14 -8
- data/spec/lib/status_cat/config_spec.rb +32 -33
- data/spec/lib/status_cat/engine_spec.rb +2 -2
- data/spec/lib/status_cat/status_spec.rb +31 -32
- data/spec/lib/status_cat/version_spec.rb +4 -4
- data/spec/lib/status_cat_spec.rb +3 -3
- data/spec/lib/tasks/status_cat.rake_spec.rb +6 -6
- data/spec/mailers/status_cat/status_mailer_spec.rb +11 -12
- data/spec/spec_helper.rb +35 -16
- data/spec/support/shared/checker.rb +5 -6
- data/spec/views/status_cat/status/index.html.erb_spec.rb +8 -9
- data/spec/views/status_cat/status_mailer/failure.html.erb_spec.rb +4 -6
- data/spec/views/status_cat/status_mailer/failure.text.erb_spec.rb +4 -4
- metadata +69 -117
- data/spec/coverage_spec.rb +0 -20
@@ -1,73 +1,73 @@
|
|
1
1
|
describe StatusCat::StatusHelper do
|
2
2
|
|
3
|
-
let(
|
4
|
-
let(
|
5
|
-
let(
|
6
|
-
let(
|
7
|
-
let(
|
3
|
+
let(:checker) { StatusCat::Checkers::ActiveRecord.new }
|
4
|
+
let(:name) { t(:name, scope: :status_cat).freeze }
|
5
|
+
let(:value) { t(:value, scope: :status_cat).freeze }
|
6
|
+
let(:status) { t(:status, scope: :status_cat).freeze }
|
7
|
+
let(:ok) { t(:ok, scope: :status_cat).freeze }
|
8
8
|
|
9
9
|
describe '#status_header' do
|
10
10
|
|
11
11
|
it 'generates a status table header' do
|
12
12
|
expected = "<tr><th>#{name}</th><th>#{value}</th><th>#{status}</th></tr>"
|
13
|
-
expect(
|
13
|
+
expect(helper.status_header).to eql(expected)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '#status_row' do
|
18
18
|
|
19
19
|
it 'generates a status table row' do
|
20
|
-
expected = "<tr><td style=\"#{helper.status_style(
|
21
|
-
expect(
|
20
|
+
expected = "<tr><td style=\"#{helper.status_style(checker)}\">#{checker.name}</td><td>#{checker.value}</td><td>#{ok}</td></tr>"
|
21
|
+
expect(helper.status_row(checker)).to eql(expected)
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'uses status_style to style the status column' do
|
25
25
|
style = :gangnam
|
26
|
-
expect(
|
26
|
+
expect(helper).to receive(:status_style).and_return(style)
|
27
27
|
expected = "<tr><td style=\"#{style}\">#{checker.name}</td><td>#{checker.value}</td><td>#{ok}</td></tr>"
|
28
|
-
expect(
|
28
|
+
expect(helper.status_row(checker)).to eql(expected)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe '#status_cell' do
|
33
33
|
|
34
34
|
it 'returns the status as a table cell' do
|
35
|
-
expected =
|
36
|
-
expect(
|
35
|
+
expected = '<td>foo</td>'
|
36
|
+
expect(helper.status_cell('foo')).to eql(expected)
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'converts array statuses into html lists' do
|
40
|
-
expected =
|
41
|
-
expect(
|
40
|
+
expected = '<td><ul><li>foo</li><li>bar</li></ul></td>'
|
41
|
+
expect(helper.status_cell(%w[foo bar])).to eql(expected)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe '#status_style' do
|
46
46
|
|
47
47
|
it 'returns a green background when the status is nil' do
|
48
|
-
expect(
|
49
|
-
expect(
|
48
|
+
expect(checker).to receive(:status).and_return(nil)
|
49
|
+
expect(helper.status_style(checker)).to eql('background-color: green')
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'returns a red background when the status is not nil' do
|
53
|
-
expect(
|
54
|
-
expect(
|
53
|
+
expect(checker).to receive(:status).and_return(:fail)
|
54
|
+
expect(helper.status_style(checker)).to eql('background-color: red')
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
describe '#status_table' do
|
59
59
|
|
60
60
|
it 'generates a status table' do
|
61
|
-
expected = "<table border=\"1\">#{helper.status_header}#{helper.status_row(
|
62
|
-
expect(
|
61
|
+
expected = "<table border=\"1\">#{helper.status_header}#{helper.status_row(checker)}</table>"
|
62
|
+
expect(helper.status_table([checker])).to eql(expected)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
describe '#status_title' do
|
67
67
|
|
68
68
|
it 'generates a page title' do
|
69
|
-
expected = "<h1>#{t(
|
70
|
-
expect(
|
69
|
+
expected = "<h1>#{t(:h1, scope: :status_cat)}</h1>"
|
70
|
+
expect(helper.status_title).to eql(expected)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -75,10 +75,10 @@ describe StatusCat::StatusHelper do
|
|
75
75
|
|
76
76
|
it 'generates a text status report' do
|
77
77
|
all = StatusCat::Status.all
|
78
|
-
all.each { |s| allow(
|
78
|
+
all.each { |s| allow(s).to receive(:status).and_return(nil) }
|
79
79
|
|
80
|
-
actual = helper.status_report(
|
81
|
-
all.each { |s| expect(
|
80
|
+
actual = helper.status_report(all)
|
81
|
+
all.each { |s| expect(actual).to match(/#{s}/) }
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -86,24 +86,24 @@ describe StatusCat::StatusHelper do
|
|
86
86
|
|
87
87
|
it 'generates a format string and length based on the max length of the given checkers' do
|
88
88
|
all = StatusCat::Status.all
|
89
|
-
all.each { |s| allow(
|
89
|
+
all.each { |s| allow(s).to receive(:status).and_return(nil) }
|
90
90
|
|
91
|
-
status_report_format = helper.status_report_format(
|
92
|
-
expect(
|
91
|
+
status_report_format = helper.status_report_format(all).to_s
|
92
|
+
expect(status_report_format).to match(/\["%\d+s | %\d+s | %\d+s\n", \d+\]/)
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
96
|
describe '#status_report_header' do
|
97
97
|
|
98
98
|
it 'generates a header' do
|
99
|
-
expected =
|
100
|
-
expect(
|
99
|
+
expected = format(StatusCat::Checkers::Base::FORMAT, name, value, status)
|
100
|
+
expect(helper.status_report_header).to eql(expected)
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'accepts a format string' do
|
104
104
|
format = '%s * %s * %s'
|
105
|
-
expected =
|
106
|
-
expect(
|
105
|
+
expected = format(format, name, value, status)
|
106
|
+
expect(helper.status_report_header(format)).to eql(expected)
|
107
107
|
end
|
108
108
|
end
|
109
|
-
end
|
109
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe 'hygiene' do
|
2
|
+
|
3
|
+
it('passes rubocop') { is_expected.to pass_rubocop }
|
4
|
+
|
5
|
+
it 'has a spec for every file' do
|
6
|
+
%w[app lib].each do |dir|
|
7
|
+
Dir.glob(File.join(ENGINE_ROOT, dir, '**', '*.{rb,erb,rake}')) do |path|
|
8
|
+
path = path.sub(%r{#{ENGINE_ROOT}/}, '')
|
9
|
+
expect(path).to have_a_spec
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -1,66 +1,63 @@
|
|
1
1
|
describe StatusCat::Checkers::ActionMailer do
|
2
2
|
|
3
|
-
let(
|
3
|
+
let(:checker) { StatusCat::Checkers::ActionMailer.new.freeze }
|
4
4
|
|
5
5
|
it_should_behave_like 'a status checker'
|
6
6
|
|
7
7
|
it 'provides configuration' do
|
8
|
-
expect(
|
8
|
+
expect(checker.config).to eql(::ActionMailer::Base.smtp_settings)
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'constructs a value from the configuration' do
|
12
|
-
expected = "#{checker.
|
13
|
-
expect(
|
12
|
+
expected = "#{checker.address}:#{checker.port}"
|
13
|
+
expect(checker.value).to eql(expected)
|
14
14
|
end
|
15
15
|
|
16
16
|
#############################################################################
|
17
17
|
# status
|
18
|
-
#############################################################################
|
19
18
|
|
20
19
|
describe '#status' do
|
21
20
|
|
22
|
-
before(
|
21
|
+
before(:each) do
|
23
22
|
::ActionMailer::Base.delivery_method = :smtp
|
24
23
|
end
|
25
24
|
|
26
|
-
after(
|
25
|
+
after(:each) do
|
27
26
|
::ActionMailer::Base.delivery_method = :test
|
28
27
|
end
|
29
28
|
|
30
29
|
#############################################################################
|
31
30
|
# pass
|
32
|
-
#############################################################################
|
33
31
|
|
34
32
|
context 'pass' do
|
35
33
|
|
36
34
|
it 'passes if it can make an SMTP connection' do
|
37
|
-
expect(
|
35
|
+
expect(Net::SMTP).to receive(:start)
|
38
36
|
checker = StatusCat::Checkers::ActionMailer.new
|
39
|
-
expect(
|
37
|
+
expect(checker.status).to be_nil
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
43
41
|
#############################################################################
|
44
42
|
# fail
|
45
|
-
#############################################################################
|
46
43
|
|
47
44
|
context 'fail' do
|
48
45
|
|
49
|
-
let(
|
46
|
+
let(:exception) { Net::SMTPAuthenticationError.new }
|
50
47
|
|
51
48
|
it 'returns an error message if it can not make an SMTP connection' do
|
52
|
-
expect(
|
49
|
+
expect(Net::SMTP).to receive(:start).and_raise(exception)
|
53
50
|
checker = StatusCat::Checkers::ActionMailer.new
|
54
|
-
expect(
|
51
|
+
expect(checker.status).to be(exception)
|
55
52
|
end
|
56
53
|
|
57
54
|
it 'returns an error message if it can not send a message' do
|
58
55
|
smtp = Object.new
|
59
|
-
allow(
|
60
|
-
allow(
|
56
|
+
allow(smtp).to receive(:helo).and_raise(exception)
|
57
|
+
allow(Net::SMTP).to receive(:start).and_yield(smtp)
|
61
58
|
checker = StatusCat::Checkers::ActionMailer.new
|
62
|
-
expect(
|
59
|
+
expect(checker.status).to be(exception)
|
63
60
|
end
|
64
61
|
end
|
65
62
|
end
|
66
|
-
end
|
63
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
describe StatusCat::Checkers::ActiveRecord do
|
2
2
|
|
3
|
-
let(
|
3
|
+
let(:checker) { StatusCat::Checkers::ActiveRecord.new.freeze }
|
4
4
|
|
5
5
|
it_should_behave_like 'a status checker'
|
6
6
|
|
7
7
|
it 'constructs a value from the configuration' do
|
8
|
-
config = { :
|
9
|
-
|
10
|
-
expected = "#{config[
|
11
|
-
expect(
|
8
|
+
config = { adapter: 'postgres', username: 'dba', database: 'test' }
|
9
|
+
allow(::ActiveRecord::Base).to receive(:connection_config).and_return(config)
|
10
|
+
expected = "#{config[:adapter]}:#{config[:username]}@#{config[:database]}"
|
11
|
+
expect(checker.value).to eql(expected)
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '#status' do
|
@@ -16,9 +16,9 @@ describe StatusCat::Checkers::ActiveRecord do
|
|
16
16
|
context 'pass' do
|
17
17
|
|
18
18
|
it 'passes if it can execute a query against the database' do
|
19
|
-
allow(
|
19
|
+
allow(ActiveRecord::Base.connection).to receive(:execute)
|
20
20
|
checker = StatusCat::Checkers::ActiveRecord.new
|
21
|
-
expect(
|
21
|
+
expect(checker.status).to be_nil
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -26,10 +26,10 @@ describe StatusCat::Checkers::ActiveRecord do
|
|
26
26
|
|
27
27
|
it 'returns an error message if it fails to query the database' do
|
28
28
|
fail = 'This is only a test'
|
29
|
-
expect(
|
29
|
+
expect(ActiveRecord::Base.connection).to receive(:execute).and_raise(fail)
|
30
30
|
checker = StatusCat::Checkers::ActiveRecord.new
|
31
|
-
expect(
|
31
|
+
expect(checker.status.to_s).to eql(fail)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
-
end
|
35
|
+
end
|
@@ -1,35 +1,35 @@
|
|
1
1
|
describe StatusCat::Checkers::Base do
|
2
2
|
|
3
|
-
let(
|
3
|
+
let(:checker) { StatusCat::Checkers::Base.new }
|
4
4
|
|
5
5
|
describe '#name' do
|
6
6
|
|
7
7
|
it 'generates a symbolized class name' do
|
8
|
-
expect(
|
8
|
+
expect(checker.name).to be(:base)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
describe 'attributes' do
|
13
13
|
|
14
14
|
it 'has value and status readers' do
|
15
|
-
expect(
|
16
|
-
expect(
|
15
|
+
expect(checker.value).to be_nil
|
16
|
+
expect(checker.status).to be_nil
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe '#to_s' do
|
21
21
|
|
22
|
-
before(
|
23
|
-
allow(
|
24
|
-
allow(
|
22
|
+
before(:each) do
|
23
|
+
allow(checker).to receive(:value).and_return('secret')
|
24
|
+
allow(checker).to receive(:status).and_return('fail')
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'generates a string' do
|
28
|
-
expect(
|
28
|
+
expect(checker.to_s).to eql("base | secret | fail\n")
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'accepts a format' do
|
32
|
-
expect(
|
32
|
+
expect(checker.to_s('%s * %s * %s')).to eql('base * secret * fail')
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -37,13 +37,29 @@ describe StatusCat::Checkers::Base do
|
|
37
37
|
|
38
38
|
it 'returns an exception if raised from the block given' do
|
39
39
|
error = 'test'
|
40
|
-
status = checker.send(
|
41
|
-
expect(
|
40
|
+
status = checker.send(:fail_on_exception) { raise error }
|
41
|
+
expect(status.to_s).to eql(error)
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'returns the results of the block when there is no exception' do
|
45
|
-
status = checker.send(
|
46
|
-
expect(
|
45
|
+
status = checker.send(:fail_on_exception) { true }
|
46
|
+
expect(status).to be(true)
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
|
+
describe '#gem_missing?' do
|
51
|
+
|
52
|
+
it 'returns false when present is true' do
|
53
|
+
expect(checker.send(:gem_missing?, 'foo', true)).to be(false)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns true when present is false' do
|
57
|
+
expect(checker.send(:gem_missing?, 'foo', false)).to be(true)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'sets status when present is false' do
|
61
|
+
checker.send(:gem_missing?, 'foo', false)
|
62
|
+
expect(checker.status).to eql('foo gem is not installed')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -1,34 +1,32 @@
|
|
1
|
-
require 'delayed_job_active_record'
|
2
|
-
|
3
1
|
describe StatusCat::Checkers::DelayedJob do
|
4
2
|
|
5
|
-
let(
|
3
|
+
let(:checker) { StatusCat::Checkers::DelayedJob.new.freeze }
|
6
4
|
|
7
5
|
it_should_behave_like 'a status checker'
|
8
6
|
|
9
|
-
it 'tolerates
|
10
|
-
|
11
|
-
expect(
|
12
|
-
Object.const_set(
|
7
|
+
it 'tolerates the gem missing' do
|
8
|
+
gem = Object.send(:remove_const, :Delayed)
|
9
|
+
expect(checker.status).to eql('delayed_job gem is not installed')
|
10
|
+
Object.const_set(:Delayed, gem)
|
13
11
|
end
|
14
12
|
|
15
13
|
it 'fails if there is an exception' do
|
16
|
-
expect(
|
17
|
-
expect(
|
14
|
+
expect(ActiveRecord::Base.connection).to receive(:execute).and_raise(:error)
|
15
|
+
expect(checker.status).to_not be_nil
|
18
16
|
end
|
19
17
|
|
20
18
|
it 'fails if there are expired jobs' do
|
21
|
-
expect(
|
22
|
-
expect(
|
19
|
+
expect(ActiveRecord::Base.connection).to receive(:execute).and_return([1], [1])
|
20
|
+
expect(checker.status).to_not be_nil
|
23
21
|
end
|
24
22
|
|
25
23
|
it 'passes if there are no expired jobs' do
|
26
|
-
expect(
|
27
|
-
expect(
|
24
|
+
expect(ActiveRecord::Base.connection).to receive(:execute).and_return([1], [0])
|
25
|
+
expect(checker.status).to be_nil
|
28
26
|
end
|
29
27
|
|
30
28
|
it 'uses the job count as the value' do
|
31
|
-
expect(
|
32
|
-
expect(
|
29
|
+
expect(ActiveRecord::Base.connection).to receive(:execute).and_return([1], [0])
|
30
|
+
expect(checker.value).to eql(1)
|
33
31
|
end
|
34
|
-
end
|
32
|
+
end
|
@@ -1,33 +1,39 @@
|
|
1
1
|
describe StatusCat::Checkers::Fitbit do
|
2
2
|
|
3
|
-
let(
|
3
|
+
let(:checker) { StatusCat::Checkers::Fitbit.new.freeze }
|
4
4
|
|
5
5
|
it_should_behave_like 'a status checker'
|
6
6
|
|
7
7
|
describe '#initialize' do
|
8
8
|
|
9
|
+
it 'tolerates the gem missing' do
|
10
|
+
gem = Object.send(:remove_const, :Fitgem)
|
11
|
+
expect(checker.status).to eql('fitgem gem is not installed')
|
12
|
+
Object.const_set(:Fitgem, gem)
|
13
|
+
end
|
14
|
+
|
9
15
|
it 'sets the value' do
|
10
|
-
expect(
|
16
|
+
expect(checker.value).to eql(StatusCat::Checkers::Fitbit.consumer_key)
|
11
17
|
end
|
12
18
|
|
13
19
|
context 'pass' do
|
14
20
|
|
15
21
|
it 'passes if it can connect to Fitbit' do
|
16
|
-
expect(
|
22
|
+
expect(checker.status).to be_nil
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
20
26
|
context 'fail' do
|
21
27
|
|
22
28
|
it 'fails if it receives errors' do
|
23
|
-
expect(
|
24
|
-
expect(
|
29
|
+
expect(@fitgem).to receive(:user_info).and_return('errors' => 'this is only a test')
|
30
|
+
expect(checker.status).to_not be_nil
|
25
31
|
end
|
26
32
|
|
27
33
|
it 'fails if there is an exception' do
|
28
|
-
expect(
|
29
|
-
expect(
|
34
|
+
expect(@fitgem).to receive(:user_info).and_raise('This is only a test')
|
35
|
+
expect(checker.status).to_not be_nil
|
30
36
|
end
|
31
37
|
end
|
32
38
|
end
|
33
|
-
end
|
39
|
+
end
|