rapporteur 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzI4YmEwOWRmNDc4MjQwNjVhNWI3MDNiZGM2MDg3NGZmYjYxODEwYw==
4
+ YzExOTM1MmZmNjFhYWY1MTRiN2QwMDcyOTMwMzNmZTk3MmY3MmZmMA==
5
5
  data.tar.gz: !binary |-
6
- NzdiMGZhZmFiODMyNTRiZGJmMjYxOWI0MTJhMjRjMzg0NWVhODM4Zg==
6
+ MjBjMDgxMGI1ZDg0NzY0YWUwZGVmOGFlNDY0MDBmN2IxMmNkNGZlNw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZGVkMTcyMzZhMWU0OGY3ZjNkZmUyNzI5MDJkYTc3ZWRkNzhlNWUzMzI0ZDdh
10
- NDk1MzllN2Y0YWY0YWJjODYxMDFlNGJiYjE3MzczNjdkM2U0ZTUxY2Q1ZmM0
11
- NTYyZWFiNzAwMjQ0MGU2MTdmMjhlZDQwM2I2NmY1YmQ5NDNhZDA=
9
+ MDNhMzI1ZWUyOTE3OTllOTA3NjVkZDQ1YjZmNGJiMGJmMzBhNDAwYjE2YWQ0
10
+ YWQ5NDliZTFkOGY4MzkyMWFiMWNiODZhNTI5OGY0OTYwYmNlMDRiZTUyZmQz
11
+ OGYzNmVhZjYxZTJiMmUzNmJiODY0NGQxYjhmMzI4NDkxMzRkNDI=
12
12
  data.tar.gz: !binary |-
13
- M2U4Y2IzYzhkYTQ3OTkzYTc0NGFhYmM2NjIwNTRhNjliN2JmMTc2MGUyMGJi
14
- M2ViNDU4ZGQ1Y2M5Y2Q5MTI1YTRmNTk1OGIxNWZlOTQ3ZmIxMzFkNDIxM2I5
15
- MDExN2YzNDc4NjVhZTZiYjEwN2VjYzk3OGU2ZDgyMzMxODFiODI=
13
+ YmNkYzlkYzQ2NTZlNTNiZmExNzM3Y2JiM2FiYTgxMDczZjdmNjI2YzA5MzZj
14
+ NTJiNzYxY2YxYjQ0OWM0ODRiZjA3YWU3MTdjNDllYzdjMTM0MjkyOTA2OTEz
15
+ NjcyMjg3OWI2NzMyZDkzYTE2ZGI1YjAwOTA1ZDVjNDkxYTZlNTE=
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
+ - jruby
5
6
  gemfile:
6
7
  - gemfiles/rails3.1.gemfile
7
8
  - gemfiles/rails3.2.gemfile
data/CHANGELOG.md CHANGED
@@ -4,6 +4,29 @@
4
4
 
5
5
  * No significant changes.
6
6
 
7
+ ## [2.0.0][v2.0.0] / 2013-05-31
8
+
9
+ * Removed active_model_serializers dependency.
10
+ * Extracted time and revision checks into Checks::TimeCheck and
11
+ Checks::RevisionCheck, and applied them as the default checks.
12
+ * Updated Checker#add_error to allow for I18n interpolated values.
13
+ * Updated Checker#add_check to take a block in addition to a lambda or object
14
+ that responds to #call.
15
+ * Added Checker#halt! which checks can call to short-circuit processing of any
16
+ further checks.
17
+
18
+ ### :boom: Backward incompatible changes
19
+
20
+ * Flattened the messages key in the JSON response. All messages are now
21
+ included at the top level of the hash.
22
+ * It's now possible to remove all checks by calling Checker#clear. This
23
+ includes the default TimeCheck and RevisionCheck checks.
24
+ * Simplified the I18n scope to "rapporteur.errors.{attribute}.{key}". This
25
+ means that Checker#add_error now takes at least 2 arguments, similarly to
26
+ ActiveModel::Errors#add.
27
+ * Added a facade for all Checker interaction. Clients should not use
28
+ Rapporteur::Checker.add_check et al, in favor of using Rapporteur.add_check.
29
+
7
30
  ## [1.1.0][v1.1.0] / 2013-05-30
8
31
 
9
32
  * Add the ability to define custom successful response messages via
@@ -20,6 +43,7 @@
20
43
  * Initial public release.
21
44
 
22
45
 
23
- [unreleased]: https://github.com/codeschool/rapporteur/compare/v1.1.0...master
46
+ [unreleased]: https://github.com/codeschool/rapporteur/compare/v2.0.0...master
47
+ [v2.0.0]: https://github.com/codeschool/rapporteur/compare/v1.1.0...v2.0.0
24
48
  [v1.1.0]: https://github.com/codeschool/rapporteur/compare/v1.0.1...v1.1.0
25
49
  [v1.0.1]: https://github.com/codeschool/rapporteur/compare/v1.0.0...v1.0.1
data/Gemfile CHANGED
@@ -1,2 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
+
4
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
5
+ gem "sqlite3", :platforms => :ruby
data/README.md CHANGED
@@ -36,6 +36,7 @@ Supported Ruby versions:
36
36
 
37
37
  * MRI 1.9.2
38
38
  * MRI 1.9.3
39
+ * JRuby 1.7.4
39
40
 
40
41
  Supported Rails versions:
41
42
 
@@ -106,7 +107,7 @@ environment or application configuration files or initializers, such as:
106
107
 
107
108
  ```ruby
108
109
  # config/initializers/rapporteur.rb
109
- Rapporteur::Checker.add_check(Rapporteur::Checks::ActiveRecordCheck)
110
+ Rapporteur.add_check(Rapporteur::Checks::ActiveRecordCheck)
110
111
  ```
111
112
 
112
113
  Or, make an environment specific check with:
@@ -115,7 +116,7 @@ Or, make an environment specific check with:
115
116
  # config/environments/production.rb
116
117
  MyApplication.configure do
117
118
  config.to_prepare do
118
- Rapporteur::Checker.add_check(Rapporteur::Checks::ActiveRecordCheck)
119
+ Rapporteur.add_check(Rapporteur::Checks::ActiveRecordCheck)
119
120
  end
120
121
  end
121
122
  ```
@@ -130,12 +131,16 @@ happy with it, add an error to the given `checker` instance:
130
131
  ```ruby
131
132
  # config/initializers/rapporteur.rb
132
133
 
134
+ Rapporteur.add_check do |checker|
135
+ checker.add_message(:paid, "too much")
136
+ end
137
+
133
138
  my_proc_check = lambda { |checker|
134
139
  checker.add_error("You have bad luck!") if rand(10) > 5
135
140
  checker.add_message(:luck, "good")
136
141
  }
137
142
 
138
- Rapporteur::Checker.add_check(my_proc_check)
143
+ Rapporteur.add_check(my_proc_check)
139
144
 
140
145
  class MyClassCheck
141
146
  def self.call(checker)
@@ -144,7 +149,7 @@ class MyClassCheck
144
149
  end
145
150
  end
146
151
 
147
- Rapporteur::Checker.add_check(MyClassCheck)
152
+ Rapporteur.add_check(MyClassCheck)
148
153
  ```
149
154
 
150
155
  Certainly, the definition and registration of the checks do not need to occur
@@ -3,8 +3,6 @@ class StatusesController < ActionController::Base
3
3
  respond_to :json
4
4
 
5
5
  def show
6
- respond_with(Rapporteur::Checker.run, {
7
- serializer: Rapporteur::Serializer
8
- })
6
+ respond_with(Rapporteur.run)
9
7
  end
10
8
  end
@@ -1,8 +1,5 @@
1
1
  en:
2
- activemodel:
2
+ rapporteur:
3
3
  errors:
4
- models:
5
- rapporteur/checker:
6
- attributes:
7
- base:
8
- database_unavailable: "The application database is inaccessible or unavailable"
4
+ database:
5
+ unavailable: "The application database is inaccessible or unavailable"
@@ -2,6 +2,8 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "activerecord-jdbcsqlite3-adapter", :platforms=>:jruby
6
+ gem "sqlite3", :platforms=>:ruby
5
7
  gem "railties", "~> 3.1.0"
6
8
 
7
9
  gemspec :path=>"../"
@@ -2,6 +2,8 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "activerecord-jdbcsqlite3-adapter", :platforms=>:jruby
6
+ gem "sqlite3", :platforms=>:ruby
5
7
  gem "railties", "~> 3.2.0"
6
8
 
7
9
  gemspec :path=>"../"
data/lib/rapporteur.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'active_model_serializers'
2
-
3
1
  require "rapporteur/engine" if defined?(Rails)
4
2
  require "rapporteur/version"
5
3
 
@@ -8,8 +6,63 @@ require "rapporteur/version"
8
6
  #
9
7
  module Rapporteur
10
8
  autoload :Checker, 'rapporteur/checker'
9
+ autoload :CheckerDeprecations, 'rapporteur/checker_deprecations'
11
10
  autoload :Checks, 'rapporteur/checks'
12
11
  autoload :Responder, 'rapporteur/responder'
13
12
  autoload :Revision, 'rapporteur/revision'
14
- autoload :Serializer, 'rapporteur/serializer'
13
+
14
+
15
+ # Public: Add a pre-built or custom check to your status endpoint. These
16
+ # checks are used to test the state of the world of the application, and
17
+ # need only respond to `#call`.
18
+ #
19
+ # Once added, the given check will be called and passed an instance of this
20
+ # checker. If everything is good, do nothing! If there is a problem, use
21
+ # `add_error` to add an error message to the checker.
22
+ #
23
+ # Examples
24
+ #
25
+ # Rapporteur.add_check { |checker|
26
+ # checker.add_error("Bad luck.") if rand(2) == 1
27
+ # }
28
+ #
29
+ # Returns the Checker instance.
30
+ # Raises ArgumentError if the given check does not respond to call.
31
+ #
32
+ def self.add_check(object_or_nil_with_block=nil, &block)
33
+ checker.add_check(object_or_nil_with_block, &block)
34
+ end
35
+
36
+ # Internal: The Checker instance. All toplevel calls on Rapporteur are
37
+ # delgated to this object.
38
+ #
39
+ def self.checker
40
+ unless @checker
41
+ @checker = Checker.new
42
+ add_check(Checks::RevisionCheck)
43
+ add_check(Checks::TimeCheck)
44
+ end
45
+ @checker
46
+ end
47
+
48
+ # Public: Empties all configured checks from the checker. This may be
49
+ # useful for testing and for cases where you might've built up some basic
50
+ # checks but for one reason or another (environment constraint) need to
51
+ # start from scratch.
52
+ #
53
+ # Returns the Checker instance.
54
+ #
55
+ def self.clear_checks
56
+ checker.clear
57
+ end
58
+
59
+ # Public: This is the primary execution point for this class. Use run to
60
+ # exercise the configured checker and collect any application errors or
61
+ # data for rendering.
62
+ #
63
+ # Returns the Checker instance.
64
+ #
65
+ def self.run
66
+ checker.run
67
+ end
15
68
  end
@@ -1,4 +1,3 @@
1
- require 'singleton'
2
1
  require 'set'
3
2
 
4
3
  module Rapporteur
@@ -7,9 +6,15 @@ module Rapporteur
7
6
  # controller with that data for rendering.
8
7
  #
9
8
  class Checker
10
- include Singleton
11
9
  include ActiveModel::Validations
12
- include ActiveModel::SerializerSupport
10
+ extend CheckerDeprecations
11
+
12
+
13
+ def initialize
14
+ @messages = Hash.new
15
+ @checks = Set.new
16
+ reset
17
+ end
13
18
 
14
19
 
15
20
  # Public: Add a pre-built or custom check to your status endpoint. These
@@ -22,16 +27,21 @@ module Rapporteur
22
27
  #
23
28
  # Examples
24
29
  #
25
- # Rapporteur::Checker.add_check(lambda { |checker|
30
+ # Rapporteur.add_check { |checker|
26
31
  # checker.add_error("Bad luck.") if rand(2) == 1
27
- # })
32
+ # }
28
33
  #
29
- # Returns Rapporteur::Checker.
34
+ # Returns self.
30
35
  # Raises ArgumentError if the given check does not respond to call.
31
36
  #
32
- def self.add_check(object)
33
- raise ArgumentError, "A check must respond to #call." unless object.respond_to?(:call)
34
- instance.checks << object
37
+ def add_check(object_or_nil_with_block=nil, &block)
38
+ if block_given?
39
+ @checks << block
40
+ elsif object_or_nil_with_block.respond_to?(:call)
41
+ @checks << object_or_nil_with_block
42
+ else
43
+ raise ArgumentError, "A check must respond to #call."
44
+ end
35
45
  self
36
46
  end
37
47
 
@@ -40,26 +50,41 @@ module Rapporteur
40
50
  # checks but for one reason or another (environment constraint) need to
41
51
  # start from scratch.
42
52
  #
43
- # Returns Rapporteur::Checker.
53
+ # Returns self.
44
54
  #
45
- def self.clear
46
- instance.checks.clear
55
+ def clear
56
+ @checks.clear
47
57
  self
48
58
  end
49
59
 
60
+ ##
61
+ # Public: Checks can call this method to halt any further processing. This
62
+ # is useful for critical or fatal check failures.
63
+ #
64
+ # For example, if load is too high on a machine you may not want to run any
65
+ # other checks.
66
+ #
67
+ # Returns true.
68
+ #
69
+ def halt!
70
+ @halted = true
71
+ end
72
+
50
73
  # Public: This is the primary execution point for this class. Use run to
51
74
  # exercise the configured checker and collect any application errors or
52
75
  # data for rendering.
53
76
  #
54
- # Returns a Rapporteur::Checker instance.
77
+ # Returns self.
55
78
  #
56
- def self.run
57
- instance.messages.clear
58
- instance.errors.clear
59
- instance.run
79
+ def run
80
+ reset
81
+ @checks.each do |object|
82
+ object.call(self)
83
+ break if @halted
84
+ end
85
+ self
60
86
  end
61
87
 
62
-
63
88
  # Public: Add an error message to the checker in order to have it rendered
64
89
  # in the status request.
65
90
  #
@@ -72,10 +97,12 @@ module Rapporteur
72
97
  # checker.add_error("You failed.")
73
98
  # checker.add_error(:i18n_key_is_better)
74
99
  #
75
- # Returns the Rapporteur::Checker instance.
100
+ # Returns self.
76
101
  #
77
- def add_error(message)
78
- errors.add(:base, message)
102
+ def add_error(key, message, options={})
103
+ options[:scope] = [:rapporteur, :errors, key]
104
+ options[:default] = [message, message.to_s.humanize]
105
+ errors.add(key, message, options)
79
106
  self
80
107
  end
81
108
 
@@ -92,47 +119,38 @@ module Rapporteur
92
119
  # checker.add_message(:repository, 'git@github.com/user/repo.git')
93
120
  # checker.add_message(:load, 0.934)
94
121
  #
95
- # Returns the Rapporteur::Checker instance.
122
+ # Returns self.
96
123
  #
97
124
  def add_message(name, message)
98
- messages[name] = message
125
+ @messages[name] = message
99
126
  self
100
127
  end
101
128
 
102
- # Public: Returns the Set of checks currently configured.
129
+ ##
130
+ # Internal: Returns a hash of messages suitable for conversion into JSON.
103
131
  #
104
- def checks
105
- @checks ||= Set.new
132
+ def as_json(args={})
133
+ @messages
106
134
  end
107
135
 
108
- # Public: Returns the Hash of messages currently configured.
136
+ ##
137
+ # Internal: Used by Rails' JSON serialization, specifically in
138
+ # ActionController::Responder.
109
139
  #
110
- def messages
111
- @messages ||= Hash.new
140
+ def read_attribute_for_serialization(key)
141
+ @messages[key]
112
142
  end
113
143
 
114
- # Public: Returns a String containing the current revision of the
115
- # application.
116
- #
117
- def revision
118
- Revision.current
119
- end
144
+ alias read_attribute_for_validation read_attribute_for_serialization
120
145
 
121
- # Public: Executes the configured checks.
122
- #
123
- # Returns the Rapporteur::Checker instance.
124
- #
125
- def run
126
- checks.each do |object|
127
- object.call(self)
128
- end
129
- self
130
- end
131
146
 
132
- # Public: Returns a Time instance containing the current system time.
133
- #
134
- def time
135
- Time.now
147
+ private
148
+
149
+
150
+ def reset
151
+ @halted = false
152
+ @messages.clear
153
+ errors.clear
136
154
  end
137
155
  end
138
156
  end
@@ -0,0 +1,20 @@
1
+ require 'active_support/deprecation'
2
+
3
+ module Rapporteur
4
+ module CheckerDeprecations
5
+ def add_check(*args, &block)
6
+ ActiveSupport::Deprecation.warn("use Rapporteur.add_check", caller)
7
+ Rapporteur.add_check(*args, &block)
8
+ end
9
+
10
+ def clear
11
+ ActiveSupport::Deprecation.warn("use Rapporteur.clear", caller)
12
+ Rapporteur.clear
13
+ end
14
+
15
+ def run
16
+ ActiveSupport::Deprecation.warn("use Rapporteur.run", caller)
17
+ Rapporteur.run
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,8 @@
1
1
  module Rapporteur
2
2
  module Checks
3
3
  autoload :ActiveRecordCheck, 'rapporteur/checks/active_record_check'
4
+
5
+ TimeCheck = lambda { |checker| checker.add_message(:time, Time.now.utc) }
6
+ RevisionCheck = lambda { |checker| checker.add_message(:revision, Revision.current) }
4
7
  end
5
8
  end
@@ -4,7 +4,7 @@ module Rapporteur
4
4
  def self.call(checker)
5
5
  ActiveRecord::Base.connection.execute("SELECT current_time AS time").first.fetch('time')
6
6
  rescue
7
- checker.add_error(:database_unavailable)
7
+ checker.add_error(:database, :unavailable)
8
8
  end
9
9
  end
10
10
  end
@@ -19,17 +19,6 @@ shared_examples_for 'a successful status response' do
19
19
  it 'does not contain errors' do
20
20
  expect(subject).not_to(have_key('errors'))
21
21
  end
22
-
23
- it 'contains the current application revision' do
24
- expect(subject.fetch('revision')).to(match(/^[a-f0-9]{40}$/))
25
- end
26
-
27
- it 'contains the current time in ISO8601' do
28
- time = Time.now
29
- Time.stub(:now).and_return(time)
30
- expect(subject.fetch('time')).to(match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/))
31
- expect(subject.fetch('time')).to(eq(time.utc.iso8601))
32
- end
33
22
  end
34
23
  end
35
24
 
@@ -52,26 +41,25 @@ shared_examples_for 'an erred status response' do
52
41
  end
53
42
  end
54
43
 
55
- RSpec::Matchers.define :include_status_error_message do |message|
44
+ RSpec::Matchers.define :include_status_error_message do |attribute, message|
56
45
  match do |response|
57
46
  @body = JSON.parse(response.body)
58
- @body.fetch('errors', {}).fetch('base').include?(message)
47
+ @body.fetch('errors', {}).fetch(attribute.to_s).include?(message)
59
48
  end
60
49
 
61
50
  failure_message_for_should do |actual|
62
- "expected #{@body.inspect} to include a #{message.inspect} error message"
51
+ "expected #{@body.inspect} to include a #{attribute}:#{message.inspect} error message"
63
52
  end
64
53
 
65
54
  failure_message_for_should_not do |actual|
66
- "expected #{@body.inspect} to not include a #{message.inspect} error message"
55
+ "expected #{@body.inspect} to not include a #{attribute}:#{message.inspect} error message"
67
56
  end
68
57
  end
69
58
 
70
59
  RSpec::Matchers.define :include_status_message do |name, message|
71
60
  match do |response|
72
61
  @body = JSON.parse(response.body)
73
- messages = @body.fetch('messages', {})
74
- messages.has_key?(name) && messages.fetch(name) == message
62
+ @body.has_key?(name) && @body.fetch(name) == message
75
63
  end
76
64
 
77
65
  failure_message_for_should do |actual|
@@ -1,3 +1,3 @@
1
1
  module Rapporteur
2
- VERSION = "1.1.0"
2
+ VERSION = "2.0.0"
3
3
  end
data/rapporteur.gemspec CHANGED
@@ -18,13 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'active_model_serializers', '~> 0.7'
22
21
  spec.add_dependency 'railties', '~> 3.1'
22
+ spec.add_dependency 'activesupport'
23
23
 
24
24
  spec.add_development_dependency "appraisal", "~> 0.5"
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
26
  spec.add_development_dependency "combustion", "~> 0.5"
27
27
  spec.add_development_dependency "rails", "~> 3.1"
28
28
  spec.add_development_dependency "rspec-rails", "~> 2.11"
29
- spec.add_development_dependency "sqlite3"
30
29
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe 'A status request with an ActiveRecordCheck' do
4
4
  before do
5
- Rapporteur::Checker.add_check(Rapporteur::Checks::ActiveRecordCheck)
5
+ Rapporteur.add_check(Rapporteur::Checks::ActiveRecordCheck)
6
6
  end
7
7
 
8
8
  subject { get(status_path) ; response }
@@ -20,7 +20,7 @@ describe 'A status request with an ActiveRecordCheck' do
20
20
  it_behaves_like 'an erred status response'
21
21
 
22
22
  it 'contains a message regarding the database failure' do
23
- expect(subject).to include_status_error_message(I18n.t('activemodel.errors.models.rapporteur/checker.attributes.base.database_unavailable'))
23
+ expect(subject).to include_status_error_message(:database, I18n.t('rapporteur.errors.database.unavailable'))
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'A check calling #halt!' do
4
+ before do
5
+ Rapporteur.add_check { |checker| checker.add_message(:one, 1) }
6
+ Rapporteur.add_check { |checker| checker.add_message(:two, 2).halt! }
7
+ Rapporteur.add_check { |checker| checker.add_message(:three, 3) }
8
+ end
9
+
10
+ subject { get(status_path) ; JSON.parse(response.body) }
11
+
12
+ it 'runs the first check' do
13
+ expect(subject).to include('one')
14
+ end
15
+
16
+ it 'runs the second check' do
17
+ expect(subject).to include('two')
18
+ end
19
+
20
+ it 'does not run any checks after #halt! is called' do
21
+ expect(subject).not_to include('three')
22
+ end
23
+ end
@@ -3,10 +3,9 @@ require 'spec_helper'
3
3
  describe 'A status request with a check that modifies messages' do
4
4
  subject { get(status_path) ; response }
5
5
 
6
- context 'creating a message with a lambda' do
6
+ context 'creating a message with a block' do
7
7
  before do
8
- Rapporteur::Checker.clear
9
- Rapporteur::Checker.add_check(Proc.new { |checker| checker.add_message('git_repo', 'git@github.com:organization/repo.git') })
8
+ Rapporteur.add_check { |checker| checker.add_message('git_repo', 'git@github.com:organization/repo.git') }
10
9
  end
11
10
 
12
11
  context 'with an unerring response' do
@@ -19,7 +18,7 @@ describe 'A status request with a check that modifies messages' do
19
18
 
20
19
  context 'with an erring response' do
21
20
  before do
22
- Rapporteur::Checker.add_check(Proc.new { |checker| checker.add_error('failed') })
21
+ Rapporteur.add_check { |checker| checker.add_error(:base, 'failed') }
23
22
  end
24
23
 
25
24
  it_behaves_like 'an erred status response'
@@ -30,8 +29,6 @@ describe 'A status request with a check that modifies messages' do
30
29
  end
31
30
 
32
31
  context 'with no message-modifying checks' do
33
- before { Rapporteur::Checker.clear }
34
-
35
32
  it_behaves_like 'a successful status response'
36
33
 
37
34
  it 'does not respond with a messages list' do
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'A status request with no checks' do
4
- before { Rapporteur::Checker.clear }
5
-
6
4
  subject { get(status_path) ; response }
7
5
 
8
6
  it_behaves_like 'a successful status response'
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'A status request with a RevisionCheck' do
4
+ before do
5
+ Rapporteur.add_check(Rapporteur::Checks::RevisionCheck)
6
+ end
7
+
8
+ subject { get(status_path) ; response }
9
+
10
+ it_behaves_like 'a successful status response'
11
+
12
+ context 'the response payload' do
13
+ subject { get(status_path) ; JSON.parse(response.body) }
14
+
15
+ it 'contains the current application revision' do
16
+ expect(subject.fetch('revision')).to(match(/^[a-f0-9]{40}$/))
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'A status request with a TimeCheck' do
4
+ before do
5
+ Rapporteur.add_check(Rapporteur::Checks::TimeCheck)
6
+ end
7
+
8
+ subject { get(status_path) ; response }
9
+
10
+ it_behaves_like 'a successful status response'
11
+
12
+ context 'the response payload' do
13
+ subject { get(status_path) ; JSON.parse(response.body) }
14
+
15
+ it 'contains the current time in ISO8601' do
16
+ time = Time.now
17
+ Time.stub(:now).and_return(time)
18
+ expect(subject.fetch('time')).to(match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/))
19
+ expect(subject.fetch('time')).to(eq(time.utc.iso8601))
20
+ end
21
+ end
22
+ end
23
+
data/spec/spec_helper.rb CHANGED
@@ -15,5 +15,5 @@ RSpec.configure do |config|
15
15
 
16
16
  config.order = 'random'
17
17
 
18
- config.before { Rapporteur::Checker.clear }
18
+ config.before { Rapporteur.clear_checks }
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapporteur
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Envy Labs
@@ -9,36 +9,36 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-30 00:00:00.000000000 Z
12
+ date: 2013-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: active_model_serializers
15
+ name: railties
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - ~>
19
19
  - !ruby/object:Gem::Version
20
- version: '0.7'
20
+ version: '3.1'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
- version: '0.7'
27
+ version: '3.1'
28
28
  - !ruby/object:Gem::Dependency
29
- name: railties
29
+ name: activesupport
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ~>
32
+ - - ! '>='
33
33
  - !ruby/object:Gem::Version
34
- version: '3.1'
34
+ version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ~>
39
+ - - ! '>='
40
40
  - !ruby/object:Gem::Version
41
- version: '3.1'
41
+ version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: appraisal
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -109,20 +109,6 @@ dependencies:
109
109
  - - ~>
110
110
  - !ruby/object:Gem::Version
111
111
  version: '2.11'
112
- - !ruby/object:Gem::Dependency
113
- name: sqlite3
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - ! '>='
117
- - !ruby/object:Gem::Version
118
- version: '0'
119
- type: :development
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
112
  description: An engine that provides common status polling endpoint.
127
113
  email:
128
114
  - ''
@@ -147,13 +133,13 @@ files:
147
133
  - gemfiles/rails3.2.gemfile
148
134
  - lib/rapporteur.rb
149
135
  - lib/rapporteur/checker.rb
136
+ - lib/rapporteur/checker_deprecations.rb
150
137
  - lib/rapporteur/checks.rb
151
138
  - lib/rapporteur/checks/active_record_check.rb
152
139
  - lib/rapporteur/engine.rb
153
140
  - lib/rapporteur/responder.rb
154
141
  - lib/rapporteur/revision.rb
155
142
  - lib/rapporteur/rspec.rb
156
- - lib/rapporteur/serializer.rb
157
143
  - lib/rapporteur/version.rb
158
144
  - rapporteur.gemspec
159
145
  - spec/internal/config/database.yml
@@ -162,8 +148,11 @@ files:
162
148
  - spec/internal/log/.gitignore
163
149
  - spec/internal/public/favicon.ico
164
150
  - spec/requests/active_record_check_spec.rb
151
+ - spec/requests/halt_spec.rb
165
152
  - spec/requests/messsage_addition_spec.rb
166
153
  - spec/requests/no_checks_spec.rb
154
+ - spec/requests/revision_check_spec.rb
155
+ - spec/requests/time_check_spec.rb
167
156
  - spec/routing/routes_spec.rb
168
157
  - spec/spec_helper.rb
169
158
  homepage: ''
@@ -197,7 +186,10 @@ test_files:
197
186
  - spec/internal/log/.gitignore
198
187
  - spec/internal/public/favicon.ico
199
188
  - spec/requests/active_record_check_spec.rb
189
+ - spec/requests/halt_spec.rb
200
190
  - spec/requests/messsage_addition_spec.rb
201
191
  - spec/requests/no_checks_spec.rb
192
+ - spec/requests/revision_check_spec.rb
193
+ - spec/requests/time_check_spec.rb
202
194
  - spec/routing/routes_spec.rb
203
195
  - spec/spec_helper.rb
@@ -1,30 +0,0 @@
1
- module Rapporteur
2
- # An ActiveModel::Serializer used to serialize the checker data for JSON
3
- # rendering.
4
- #
5
- class Serializer < ActiveModel::Serializer
6
- self.root = false
7
-
8
- attributes :revision,
9
- :time,
10
- :messages
11
-
12
- # Internal: Converts the checker instance time into UTC to provide a
13
- # consistent public representation.
14
- #
15
- # Returns a Time instance in UTC.
16
- #
17
- def time
18
- object.time.utc
19
- end
20
-
21
- # Internal: Used by ActiveModel::Serializer to determine whether or not to
22
- # include the messages attribute.
23
- #
24
- # Returns false if the messages are empty.
25
- #
26
- def include_messages?
27
- !object.messages.empty?
28
- end
29
- end
30
- end