rapporteur 1.0.1 → 1.1.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
- OWE5YTkzNGY2ZWI4NGU3YTI2ZjA1MWJmM2NjMzE0M2FjNmIyZDliYw==
4
+ MzI4YmEwOWRmNDc4MjQwNjVhNWI3MDNiZGM2MDg3NGZmYjYxODEwYw==
5
5
  data.tar.gz: !binary |-
6
- NzdhY2YxYmY3NDNhYTVhYzI5NDE4ZTgwMjk0NGNhZGE5ZmE1YzgzOQ==
6
+ NzdiMGZhZmFiODMyNTRiZGJmMjYxOWI0MTJhMjRjMzg0NWVhODM4Zg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MmMyMTFlNTRhODJkNTYyODY2ZjYwNjFjZmMyNzQ4NGY2YjFiYzE0ZTYwOTgx
10
- MDhlOGMzNTEzZTYyMWQ0Y2RlZGQ3NDIyNzhkNTRkYTA4MTFiZWRiZmVhOWRk
11
- NjMyMDZlYmE2NGFlZDcwOTYxMDEwYzdjN2MzZTk2ZDIxNGUyYTA=
9
+ ZGVkMTcyMzZhMWU0OGY3ZjNkZmUyNzI5MDJkYTc3ZWRkNzhlNWUzMzI0ZDdh
10
+ NDk1MzllN2Y0YWY0YWJjODYxMDFlNGJiYjE3MzczNjdkM2U0ZTUxY2Q1ZmM0
11
+ NTYyZWFiNzAwMjQ0MGU2MTdmMjhlZDQwM2I2NmY1YmQ5NDNhZDA=
12
12
  data.tar.gz: !binary |-
13
- YTk2ZDMyZmRkMDE1Y2ZiYTkxZWQ2ZDgzMTUzMDFjMGJhMGNkYWUzYTJhNDYy
14
- N2E0NzNmOGYxZmZjNTNmOTU1M2ZjYmEyZTgxYWI2Y2I5MzhiZDdhNWIyMGQ1
15
- YzE5N2JiN2NjYTA4ZjYxZmY5ZjgxZjUwNzlkNTY2ZTQ2MTQzNGI=
13
+ M2U4Y2IzYzhkYTQ3OTkzYTc0NGFhYmM2NjIwNTRhNjliN2JmMTc2MGUyMGJi
14
+ M2ViNDU4ZGQ1Y2M5Y2Q5MTI1YTRmNTk1OGIxNWZlOTQ3ZmIxMzFkNDIxM2I5
15
+ MDExN2YzNDc4NjVhZTZiYjEwN2VjYzk3OGU2ZDgyMzMxODFiODI=
data/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@
4
4
 
5
5
  * No significant changes.
6
6
 
7
+ ## [1.1.0][v1.1.0] / 2013-05-30
8
+
9
+ * Add the ability to define custom successful response messages via
10
+ add_message. This allows Check authors to relay automated information forward
11
+ to other external systems.
12
+
7
13
  ## [1.0.1][v1.0.1] / 2013-05-20
8
14
 
9
15
  * Improve the gemspec's minimum runtime- and development-dependency version
@@ -14,5 +20,6 @@
14
20
  * Initial public release.
15
21
 
16
22
 
17
- [unreleased]: https://github.com/codeschool/rapporteur/compare/v1.0.1...master
23
+ [unreleased]: https://github.com/codeschool/rapporteur/compare/v1.1.0...master
24
+ [v1.1.0]: https://github.com/codeschool/rapporteur/compare/v1.0.1...v1.1.0
18
25
  [v1.0.1]: https://github.com/codeschool/rapporteur/compare/v1.0.0...v1.0.1
data/README.md CHANGED
@@ -132,6 +132,7 @@ happy with it, add an error to the given `checker` instance:
132
132
 
133
133
  my_proc_check = lambda { |checker|
134
134
  checker.add_error("You have bad luck!") if rand(10) > 5
135
+ checker.add_message(:luck, "good")
135
136
  }
136
137
 
137
138
  Rapporteur::Checker.add_check(my_proc_check)
@@ -54,6 +54,7 @@ module Rapporteur
54
54
  # Returns a Rapporteur::Checker instance.
55
55
  #
56
56
  def self.run
57
+ instance.messages.clear
57
58
  instance.errors.clear
58
59
  instance.run
59
60
  end
@@ -78,12 +79,38 @@ module Rapporteur
78
79
  self
79
80
  end
80
81
 
82
+ ##
83
+ # Public: Adds a status message for inclusion in the success response.
84
+ #
85
+ # name - A String containing the name or identifier for your message. This
86
+ # is unique and may be overriden by other checks using the name
87
+ # message name key.
88
+ # message - A String or Numeric for the value of the message.
89
+ #
90
+ # Examples
91
+ #
92
+ # checker.add_message(:repository, 'git@github.com/user/repo.git')
93
+ # checker.add_message(:load, 0.934)
94
+ #
95
+ # Returns the Rapporteur::Checker instance.
96
+ #
97
+ def add_message(name, message)
98
+ messages[name] = message
99
+ self
100
+ end
101
+
81
102
  # Public: Returns the Set of checks currently configured.
82
103
  #
83
104
  def checks
84
105
  @checks ||= Set.new
85
106
  end
86
107
 
108
+ # Public: Returns the Hash of messages currently configured.
109
+ #
110
+ def messages
111
+ @messages ||= Hash.new
112
+ end
113
+
87
114
  # Public: Returns a String containing the current revision of the
88
115
  # application.
89
116
  #
@@ -66,3 +66,19 @@ RSpec::Matchers.define :include_status_error_message do |message|
66
66
  "expected #{@body.inspect} to not include a #{message.inspect} error message"
67
67
  end
68
68
  end
69
+
70
+ RSpec::Matchers.define :include_status_message do |name, message|
71
+ match do |response|
72
+ @body = JSON.parse(response.body)
73
+ messages = @body.fetch('messages', {})
74
+ messages.has_key?(name) && messages.fetch(name) == message
75
+ end
76
+
77
+ failure_message_for_should do |actual|
78
+ "expected #{@body.inspect} to include a #{name.inspect}: #{message.inspect} message"
79
+ end
80
+
81
+ failure_message_for_should_not do |actual|
82
+ "expected #{@body.inspect} to not include a #{name.inspect}: #{message.inspect} message"
83
+ end
84
+ end
@@ -6,7 +6,8 @@ module Rapporteur
6
6
  self.root = false
7
7
 
8
8
  attributes :revision,
9
- :time
9
+ :time,
10
+ :messages
10
11
 
11
12
  # Internal: Converts the checker instance time into UTC to provide a
12
13
  # consistent public representation.
@@ -16,5 +17,14 @@ module Rapporteur
16
17
  def time
17
18
  object.time.utc
18
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
19
29
  end
20
30
  end
@@ -1,3 +1,3 @@
1
1
  module Rapporteur
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'A status request with a check that modifies messages' do
4
+ subject { get(status_path) ; response }
5
+
6
+ context 'creating a message with a lambda' do
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') })
10
+ end
11
+
12
+ context 'with an unerring response' do
13
+ it_behaves_like 'a successful status response'
14
+
15
+ it 'responds with the check\'s messages' do
16
+ expect(subject).to include_status_message('git_repo', 'git@github.com:organization/repo.git')
17
+ end
18
+ end
19
+
20
+ context 'with an erring response' do
21
+ before do
22
+ Rapporteur::Checker.add_check(Proc.new { |checker| checker.add_error('failed') })
23
+ end
24
+
25
+ it_behaves_like 'an erred status response'
26
+
27
+ it 'does not respond with the check\'s messages' do
28
+ expect(subject).not_to include_status_message('git_repo', 'git@github.com:organization/repo.git')
29
+ end
30
+ end
31
+
32
+ context 'with no message-modifying checks' do
33
+ before { Rapporteur::Checker.clear }
34
+
35
+ it_behaves_like 'a successful status response'
36
+
37
+ it 'does not respond with a messages list' do
38
+ expect(JSON.parse(subject.body)).not_to(have_key('messages'))
39
+ end
40
+ end
41
+ end
42
+ 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.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Envy Labs
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-20 00:00:00.000000000 Z
12
+ date: 2013-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: active_model_serializers
@@ -162,6 +162,7 @@ files:
162
162
  - spec/internal/log/.gitignore
163
163
  - spec/internal/public/favicon.ico
164
164
  - spec/requests/active_record_check_spec.rb
165
+ - spec/requests/messsage_addition_spec.rb
165
166
  - spec/requests/no_checks_spec.rb
166
167
  - spec/routing/routes_spec.rb
167
168
  - spec/spec_helper.rb
@@ -196,6 +197,7 @@ test_files:
196
197
  - spec/internal/log/.gitignore
197
198
  - spec/internal/public/favicon.ico
198
199
  - spec/requests/active_record_check_spec.rb
200
+ - spec/requests/messsage_addition_spec.rb
199
201
  - spec/requests/no_checks_spec.rb
200
202
  - spec/routing/routes_spec.rb
201
203
  - spec/spec_helper.rb