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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -11
  3. data/app/controllers/status_cat/status_controller.rb +19 -18
  4. data/app/helpers/status_cat/status_helper.rb +69 -64
  5. data/app/mailers/status_cat/status_mailer.rb +9 -8
  6. data/app/views/status_cat/status/index.html.erb +1 -1
  7. data/app/views/status_cat/status_mailer/failure.html.erb +1 -1
  8. data/app/views/status_cat/status_mailer/failure.text.erb +1 -1
  9. data/lib/status_cat.rb +1 -1
  10. data/lib/status_cat/checkers/action_mailer.rb +33 -17
  11. data/lib/status_cat/checkers/active_record.rb +22 -7
  12. data/lib/status_cat/checkers/base.rb +16 -9
  13. data/lib/status_cat/checkers/delayed_job.rb +21 -16
  14. data/lib/status_cat/checkers/fitbit.rb +18 -9
  15. data/lib/status_cat/checkers/profilesio.rb +4 -1
  16. data/lib/status_cat/checkers/s3.rb +9 -10
  17. data/lib/status_cat/checkers/send_hub.rb +9 -3
  18. data/lib/status_cat/checkers/stripe.rb +15 -10
  19. data/lib/status_cat/checkers/twilio.rb +10 -4
  20. data/lib/status_cat/config.rb +3 -7
  21. data/lib/status_cat/status.rb +9 -11
  22. data/lib/status_cat/version.rb +1 -1
  23. data/lib/tasks/status_cat.rake +3 -4
  24. data/spec/controllers/status_cat/status_controller_spec.rb +9 -9
  25. data/spec/dummy/app/checkers/dummy.rb +2 -2
  26. data/spec/dummy/app/controllers/application_controller.rb +2 -1
  27. data/spec/dummy/app/controllers/root_controller.rb +6 -7
  28. data/spec/dummy/config.ru +1 -1
  29. data/spec/dummy/config/application.rb +2 -2
  30. data/spec/dummy/config/environments/production.rb +1 -1
  31. data/spec/dummy/config/initializers/action_mailer.rb +2 -2
  32. data/spec/dummy/config/initializers/inflections.rb +1 -1
  33. data/spec/dummy/config/passwords.yml +5 -0
  34. data/spec/dummy/config/routes.rb +2 -2
  35. data/spec/dummy/db/development.sqlite3 +0 -0
  36. data/spec/dummy/db/schema.rb +0 -1
  37. data/spec/dummy/db/test.sqlite3 +0 -0
  38. data/spec/dummy/log/development.log +36 -0
  39. data/spec/dummy/log/test.log +16588 -13366
  40. data/spec/helpers/status_cat/status_helper_spec.rb +33 -33
  41. data/spec/hygiene_spec.rb +14 -0
  42. data/spec/lib/status_cat/checkers/action_mailer_spec.rb +15 -18
  43. data/spec/lib/status_cat/checkers/active_record_spec.rb +10 -10
  44. data/spec/lib/status_cat/checkers/base_spec.rb +30 -14
  45. data/spec/lib/status_cat/checkers/delayed_job_spec.rb +14 -16
  46. data/spec/lib/status_cat/checkers/fitbit_spec.rb +14 -8
  47. data/spec/lib/status_cat/checkers/profilesio_spec.rb +12 -12
  48. data/spec/lib/status_cat/checkers/s3_spec.rb +17 -18
  49. data/spec/lib/status_cat/checkers/send_hub_spec.rb +14 -8
  50. data/spec/lib/status_cat/checkers/stripe_spec.rb +18 -24
  51. data/spec/lib/status_cat/checkers/twilio_spec.rb +14 -8
  52. data/spec/lib/status_cat/config_spec.rb +32 -33
  53. data/spec/lib/status_cat/engine_spec.rb +2 -2
  54. data/spec/lib/status_cat/status_spec.rb +31 -32
  55. data/spec/lib/status_cat/version_spec.rb +4 -4
  56. data/spec/lib/status_cat_spec.rb +3 -3
  57. data/spec/lib/tasks/status_cat.rake_spec.rb +6 -6
  58. data/spec/mailers/status_cat/status_mailer_spec.rb +11 -12
  59. data/spec/spec_helper.rb +35 -16
  60. data/spec/support/shared/checker.rb +5 -6
  61. data/spec/views/status_cat/status/index.html.erb_spec.rb +8 -9
  62. data/spec/views/status_cat/status_mailer/failure.html.erb_spec.rb +4 -6
  63. data/spec/views/status_cat/status_mailer/failure.text.erb_spec.rb +4 -4
  64. metadata +69 -117
  65. data/spec/coverage_spec.rb +0 -20
@@ -5,24 +5,29 @@ module StatusCat
5
5
  include ActionView::Helpers::DateHelper
6
6
 
7
7
  def initialize
8
- if !defined?( ::Delayed )
9
- @status = 'delayed_job gem not installed'
10
- else
11
- @status = fail_on_exception do
12
- sql = 'select count(*) from delayed_jobs where failed_at is null'
13
- result = ::ActiveRecord::Base.connection.execute( sql ).first
14
- @value = result.is_a?( Hash ) ? result[ 'count' ] : result[ 0 ]
8
+ return if gem_missing?('delayed_job', defined?(::Delayed))
9
+ @status = fail_on_exception { test }
10
+ end
15
11
 
16
- expires = 1.day.ago
17
- sql = "select count(*) from delayed_jobs where created_at < '#{expires.to_s( :db )}' and failed_at is null"
18
- result = ::ActiveRecord::Base.connection.execute( sql ).first
19
- value = result.is_a?( Hash ) ? result[ 'count' ] : result[ 0 ]
12
+ def test
13
+ @value = count_jobs
20
14
 
21
- ( value.to_i == 0 ) ? nil : "#{value} jobs more than #{time_ago_in_words( expires )} old"
22
- end
23
- end
15
+ expires = 1.day.ago
16
+ expired = count_expired(expires)
17
+ expired.zero? ? nil : "#{expired} jobs more than #{time_ago_in_words(expires)} old"
18
+ end
19
+
20
+ def count_jobs
21
+ sql = 'select count(*) from delayed_jobs where failed_at is null'
22
+ result = ::ActiveRecord::Base.connection.execute(sql).first
23
+ return result.is_a?(Hash) ? result['count'] : result[0]
24
24
  end
25
- end
26
25
 
26
+ def count_expired(expires)
27
+ sql = "select count(*) from delayed_jobs where created_at < '#{expires.to_s(:db)}' and failed_at is null"
28
+ result = ::ActiveRecord::Base.connection.execute(sql).first
29
+ return result.is_a?(Hash) ? result['count'] : result[0]
30
+ end
31
+ end
27
32
  end
28
- end
33
+ end
@@ -1,20 +1,29 @@
1
1
  module StatusCat
2
2
  module Checkers
3
3
  class Fitbit < Base
4
+
5
+ cattr_accessor :consumer_key
6
+ cattr_accessor :consumer_secret
7
+ cattr_accessor :test_token
8
+ cattr_accessor :test_secret
9
+ cattr_accessor :test_user_id
10
+
4
11
  def initialize
5
- @value = ENV[ 'FITBIT_CONSUMER_KEY' ]
12
+ return if gem_missing?('fitgem', defined?(::Fitgem))
13
+
14
+ @value = consumer_key
6
15
  @status = fail_on_exception do
7
16
  user_info = ::Fitgem::Client.new(
8
- :consumer_key => ENV[ 'FITBIT_CONSUMER_KEY' ],
9
- :consumer_secret => ENV[ 'FITBIT_CONSUMER_SECRET' ],
10
- :token => ENV[ 'FITBIT_TEST_TOKEN' ],
11
- :secret => ENV[ 'FITBIT_TEST_SECRET' ],
12
- :user_id => ENV[ 'FITBIT_TEST_USER_ID' ]
13
- ).user_info
17
+ consumer_key: consumer_key,
18
+ consumer_secret: consumer_secret,
19
+ token: test_token,
20
+ secret: test_secret,
21
+ user_id: test_user_id
22
+ ).user_info
14
23
 
15
- user_info[ 'errors' ] ? user_info.inspect : nil
24
+ user_info['errors'] ? user_info.inspect : nil
16
25
  end
17
26
  end
18
27
  end
19
28
  end
20
- end
29
+ end
@@ -1,8 +1,11 @@
1
1
  module StatusCat
2
2
  module Checkers
3
3
  class Profilesio < Base
4
+
5
+ cattr_accessor :api_key
6
+
4
7
  def initialize
5
- @value = ENV['PROFILESIO_KEY']
8
+ @value = api_key
6
9
  @status = fail_on_exception do
7
10
  response = ::HTTParty.get('https://profiles.io/record/register')
8
11
  response.code == 200 ? nil : 'fail'
@@ -3,17 +3,16 @@ module StatusCat
3
3
  class S3 < Base
4
4
 
5
5
  def initialize
6
- if !defined?( ::AWS )
7
- @status = 'aws-sdk gem not installed'
8
- else
9
- @value = AWS.config.access_key_id
10
- @status = fail_on_exception do
11
- s3 = AWS::S3.new
12
- ( s3.buckets.count > 0 ) ? nil : 'no buckets'
13
- end
14
- end
6
+ return if gem_missing?('aws-sdk', defined?(::Aws))
7
+
8
+ @value = Aws.config[:credentials].access_key_id
9
+ @status = fail_on_exception { test }
15
10
  end
16
11
 
12
+ def test
13
+ s3 = Aws::S3::Resource.new
14
+ return s3.buckets.count.zero? ? 'no buckets' : nil
15
+ end
17
16
  end
18
17
  end
19
- end
18
+ end
@@ -1,13 +1,19 @@
1
1
  module StatusCat
2
2
  module Checkers
3
3
  class SendHub < Base
4
+
5
+ cattr_accessor :api_key
6
+ cattr_accessor :number
7
+
4
8
  def initialize
5
- @value = ENV[ 'SEND_HUB_NUMBER' ]
9
+ return if gem_missing?('ruby-sendhub', defined?(::SendHub))
10
+
11
+ @value = number
6
12
  @status = fail_on_exception do
7
- send_hub = ::SendHub.new( ENV[ 'SEND_HUB_API_KEY' ], ENV[ 'SEND_HUB_NUMBER' ] )
13
+ send_hub = ::SendHub.new(api_key, number)
8
14
  send_hub.get_contacts ? nil : 'fail'
9
15
  end
10
16
  end
11
17
  end
12
18
  end
13
- end
19
+ end
@@ -2,18 +2,23 @@ module StatusCat
2
2
  module Checkers
3
3
 
4
4
  class Stripe < Base
5
+
5
6
  def initialize
6
- if !defined?( ::Stripe )
7
- @status = 'stripe gem not installed'
8
- else
9
- @status = fail_on_exception do
10
- account = ::Stripe::Account.retrieve
11
- @value = account.email
12
- account.charge_enabled ? nil : 'Charge is not enabled'
13
- end
7
+ return if gem_missing?('stripe', defined?(::Stripe))
8
+
9
+ @status = fail_on_exception do
10
+ @value = account.email
11
+ test
14
12
  end
15
13
  end
16
- end
17
14
 
15
+ def test
16
+ return account.charge_enabled ? nil : 'Charge is not enabled'
17
+ end
18
+
19
+ def account
20
+ return ::Stripe::Account.retrieve
21
+ end
22
+ end
18
23
  end
19
- end
24
+ end
@@ -1,13 +1,19 @@
1
1
  module StatusCat
2
2
  module Checkers
3
3
  class Twilio < Base
4
+
5
+ cattr_accessor :sid
6
+ cattr_accessor :auth_token
7
+
4
8
  def initialize
5
- @value = ENV[ 'TWILIO_SID' ]
9
+ return if gem_missing?('twilio-ruby', defined?(::Twilio))
10
+
11
+ @value = sid
6
12
  @status = fail_on_exception do
7
- twilio = ::Twilio::REST::Client.new( ENV[ 'TWILIO_SID' ], ENV[ 'TWILIO_TOKEN' ] )
8
- twilio.account.messages.total ? nil : 'fail'
13
+ twilio = ::Twilio::REST::Client.new(sid, auth_token)
14
+ twilio.api.account.messages.total ? nil : 'fail'
9
15
  end
10
16
  end
11
17
  end
12
18
  end
13
- end
19
+ end
@@ -1,7 +1,6 @@
1
1
  require 'singleton'
2
2
 
3
3
  module StatusCat
4
-
5
4
  class Config
6
5
  include Singleton
7
6
 
@@ -13,9 +12,8 @@ module StatusCat
13
12
  attr_accessor :layout
14
13
 
15
14
  def initialize
16
- @enabled = StatusCat::Checkers::Base.descendants.map { |klass|
17
- StatusCat::Checkers::Base.class_to_name( klass )
18
- }.sort
15
+ descendants = StatusCat::Checkers::Base.descendants
16
+ @enabled = descendants.map { |klass| StatusCat::Checkers::Base.class_to_name(klass) }.sort
19
17
  end
20
18
 
21
19
  def authenticate_with(&blk)
@@ -27,7 +25,5 @@ module StatusCat
27
25
  @authorize = block if block
28
26
  @authorize || NIL_PROC
29
27
  end
30
-
31
28
  end
32
-
33
- end
29
+ end
@@ -4,34 +4,32 @@ module StatusCat
4
4
 
5
5
  # Returns an array of instances of StatusCat::Checkers::Base subclasses
6
6
  def self.all
7
- StatusCat::Config.instance.enabled.map { |name| factory( name ) }
7
+ StatusCat::Config.instance.enabled.map { |name| factory(name) }
8
8
  end
9
9
 
10
10
  # By default, returns all checkers
11
11
  # If given a list of checker names, returns an array of those checkers
12
12
  # If given a single checker name, just returns that checker
13
- def self.check( which = :all )
13
+ def self.check(which = :all)
14
14
  return all if which == :all
15
- return factory( which ) unless which.is_a?( Array )
16
- return which.map { |name| factory( name ) }
15
+ return factory(which) unless which.is_a?(Array)
16
+ return which.map { |name| factory(name) }
17
17
  end
18
18
 
19
19
  # Emails ::failed list if it is not empty
20
20
  def self.cron
21
- checkers = self.failed
22
- StatusCat::StatusMailer.failure( checkers ).deliver_now unless checkers.empty?
21
+ checkers = failed
22
+ StatusCat::StatusMailer.failure(checkers).deliver_now unless checkers.empty?
23
23
  end
24
24
 
25
25
  # Constructs a checker instance given it's name
26
- def self.factory( name )
27
- ( 'StatusCat::Checkers::' + name.to_s.classify ).constantize.new
26
+ def self.factory(name)
27
+ ('StatusCat::Checkers::' + name.to_s.classify).constantize.new
28
28
  end
29
29
 
30
30
  # Returns an array of failed instances of ::all
31
31
  def self.failed
32
- self.all.map { |checker| checker.status.nil? ? nil : checker }.compact
32
+ all.map { |checker| checker.status.nil? ? nil : checker }.compact
33
33
  end
34
-
35
34
  end
36
-
37
35
  end
@@ -1,3 +1,3 @@
1
1
  module StatusCat
2
- VERSION = '0.1.1'
2
+ VERSION = '5.0.0'.freeze
3
3
  end
@@ -1,14 +1,13 @@
1
1
  namespace :status_cat do
2
2
 
3
3
  desc 'Run all checkers and output results'
4
- task :check => :environment do
4
+ task check: :environment do
5
5
  include StatusCat::StatusHelper
6
- Kernel.puts status_report( StatusCat::Status.all )
6
+ Kernel.puts status_report(StatusCat::Status.all)
7
7
  end
8
8
 
9
9
  desc 'Run all checkers and email failures'
10
- task :cron => :environment do
10
+ task cron: :environment do
11
11
  StatusCat::Status.cron
12
12
  end
13
-
14
13
  end
@@ -6,29 +6,29 @@ describe StatusCat::StatusController do
6
6
 
7
7
  it 'gets successfully' do
8
8
  get :index
9
- expect( response ).to be_success
9
+ expect(response).to be_success
10
10
  end
11
11
 
12
12
  it 'assigns @checkers to StatusCat::Status.all' do
13
13
  get :index
14
14
 
15
- @checkers = assigns[ :checkers ]
16
- expect( @checkers ).to_not be( nil )
17
- expect( @checkers.length ).to eql( StatusCat::Status.all.length )
18
- @checkers.each { |checker| expect( checker ).to be_a_kind_of( StatusCat::Checkers::Base ) }
15
+ @checkers = assigns[:checkers]
16
+ expect(@checkers).to_not be(nil)
17
+ expect(@checkers.length).to eql(StatusCat::Status.all.length)
18
+ @checkers.each { |checker| expect(checker).to be_a_kind_of(StatusCat::Checkers::Base) }
19
19
  end
20
20
 
21
21
  it 'uses the configured before authentication filter' do
22
- allow( Rails.env ).to receive( :test? ).and_return( false )
23
- expect( controller ).to receive( :authenticate! )
24
- expect( controller ).to receive( :authorize! )
22
+ allow(Rails.env).to receive(:test?).and_return(false)
23
+ expect(controller).to receive(:authenticate!)
24
+ expect(controller).to receive(:authorize!)
25
25
 
26
26
  get :index
27
27
  end
28
28
 
29
29
  it 'renders with the configured layout' do
30
30
  get :index
31
- expect( response ).to render_template( StatusCat.config.layout )
31
+ expect(response).to render_template(StatusCat.config.layout)
32
32
  end
33
33
  end
34
34
  end
@@ -3,8 +3,8 @@ module StatusCat
3
3
  class Dummy < Base
4
4
  def initialize
5
5
  @value = 'dummy'
6
- @status = [ 'fail', 'fail', 'fail' ]
6
+ @status = %w[fail fail fail]
7
7
  end
8
8
  end
9
9
  end
10
- end
10
+ end
@@ -1,8 +1,9 @@
1
1
  class ApplicationController < ActionController::Base
2
+
2
3
  protect_from_forgery
3
4
 
4
5
  def authenticate!
5
- render :text => 'forbidden' unless cookies[ :login ]
6
+ render text: 'forbidden' unless cookies[:login]
6
7
  end
7
8
 
8
9
  def authorize!
@@ -4,17 +4,16 @@ class RootController < ApplicationController
4
4
  end
5
5
 
6
6
  def mail
7
- StatusCat::StatusMailer.failure( StatusCat::Status.all ).deliver
7
+ StatusCat::StatusMailer.failure(StatusCat::Status.all).deliver
8
8
  end
9
9
 
10
10
  def login
11
- cookies[ :login ] = { :value => true, :expires => 10.years.from_now }
12
- redirect_to :action => :index
11
+ cookies[:login] = { value: true, expires: 10.years.from_now }
12
+ redirect_to action: :index
13
13
  end
14
14
 
15
15
  def logout
16
- cookies.delete( :login )
17
- redirect_to :action => :index
16
+ cookies.delete(:login)
17
+ redirect_to action: :index
18
18
  end
19
-
20
- end
19
+ end
data/spec/dummy/config.ru CHANGED
@@ -1,4 +1,4 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
4
  run Dummy::Application
@@ -2,8 +2,8 @@ require File.expand_path('../boot', __FILE__)
2
2
 
3
3
  require 'rails/all'
4
4
 
5
- Bundler.require
6
- require "status_cat"
5
+ Bundler.require(*Rails.groups)
6
+ require 'status_cat'
7
7
 
8
8
  module Dummy
9
9
  class Application < Rails::Application
@@ -46,7 +46,7 @@ Dummy::Application.configure do
46
46
  # config.action_controller.asset_host = "http://assets.example.com"
47
47
 
48
48
  # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
49
- # config.assets.precompile += %w( search.js )
49
+ # config.assets.precompile += %w(search.js)
50
50
 
51
51
  # Disable delivery errors, bad email addresses will be ignored
52
52
  # config.action_mailer.raise_delivery_errors = false
@@ -1,8 +1,8 @@
1
1
  if Rails.env.test?
2
2
  ActionMailer::Base.delivery_method = :test
3
3
  else
4
- yaml = YAML::load( IO.read( File.join( Rails.root, 'config', 'passwords.yml' ) ) )
5
- passwords = HashWithIndifferentAccess.new( yaml[ Rails.env ] )
4
+ yaml = YAML::load(IO.read(File.join(Rails.root, 'config', 'passwords.yml')))
5
+ passwords = HashWithIndifferentAccess.new(yaml[ Rails.env ])
6
6
 
7
7
  ActionMailer::Base.delivery_method = :smtp
8
8
  ActionMailer::Base.smtp_settings = {
@@ -6,7 +6,7 @@
6
6
  # inflect.plural /^(ox)$/i, '\1en'
7
7
  # inflect.singular /^(ox)en/i, '\1'
8
8
  # inflect.irregular 'person', 'people'
9
- # inflect.uncountable %w( fish sheep )
9
+ # inflect.uncountable %w(fish sheep)
10
10
  # end
11
11
  #
12
12
  # These inflection rules are supported but not enabled by default: