rapporteur 2.1.0 → 3.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 +8 -8
- data/.travis.yml +5 -0
- data/CHANGELOG.md +19 -0
- data/README.md +45 -20
- data/Rakefile +1 -1
- data/config/routes.rb +1 -1
- data/lib/rapporteur.rb +2 -0
- data/lib/rapporteur/check_list.rb +61 -0
- data/lib/rapporteur/checker.rb +18 -15
- data/lib/rapporteur/message_list.rb +129 -0
- data/lib/rapporteur/responder.rb +2 -2
- data/lib/rapporteur/rspec.rb +1 -1
- data/lib/rapporteur/version.rb +1 -1
- data/rapporteur.gemspec +2 -2
- data/spec/models/check_list_spec.rb +59 -0
- data/spec/models/message_list_spec.rb +82 -0
- data/spec/requests/revision_check_spec.rb +2 -3
- data/spec/requests/time_check_spec.rb +3 -7
- data/spec/routing/routes_spec.rb +7 -7
- metadata +29 -17
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjZhNjRmZjgwNmMyZjAxMWMzNTAyYTZlYzYxNzI4NmI5ZDFkZWRiMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Zjg4ZDViM2IwOTg3OTc3OWU5MmNkYTlmNjVhMjgxNDg5YWZlZWJiYg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODMxNTQ2ZjY1MjlmMTE1NDY2OTM3ZGZlYzIxMDY0MDE0ZGE3NDBhY2NmZWVl
|
10
|
+
YjFlMWU2Zjg5ZmMwNDZhNjBmODc4YTFlMDNlODhmZDI2Yjg3MmEwNjRkOGFm
|
11
|
+
ODkxZTM1MTJhMWJjMjI5NTU0MjU5ZWNlMzI1MmJkZjM0NjY0MzU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjU5MWUwNzA5YjYwNmE1OTc3NmQ1MTM0ZmYxMjNhYjdlN2NjY2JlMDYxODU1
|
14
|
+
YWJkMWU4YmRmZmE3ODJhZWYyZmE1ZjIwOWU5MDBiNmEwMTNjMDI2MjIwNWRj
|
15
|
+
YjU4MGU0ZmVmYTA5ODg4MzZlNzI5MjQwMGI0ODA2NTA5YjljZmE=
|
data/.travis.yml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
+
- 1.8.7
|
3
4
|
- 1.9.3
|
4
5
|
- 2.0.0
|
5
6
|
- jruby-19mode
|
@@ -7,6 +8,10 @@ gemfile:
|
|
7
8
|
- gemfiles/rails3.1.gemfile
|
8
9
|
- gemfiles/rails3.2.gemfile
|
9
10
|
- gemfiles/rails4.0.gemfile
|
11
|
+
matrix:
|
12
|
+
exclude:
|
13
|
+
- rvm: 1.8.7
|
14
|
+
gemfile: gemfiles/rails4.0.gemfile
|
10
15
|
notifications:
|
11
16
|
email: false
|
12
17
|
campfire:
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,25 @@
|
|
4
4
|
|
5
5
|
* No significant changes.
|
6
6
|
|
7
|
+
## [3.0.0][v3.0.0] / 2013-08-23
|
8
|
+
|
9
|
+
* Fix/add Ruby 1.8 compatibility. Because this library was built to work with
|
10
|
+
Rails 3.1 and 3.2 (as well as 4.0), not supporting Ruby 1.8 was dishonest.
|
11
|
+
That has now been rectified.
|
12
|
+
* Update message and error handling to allow for both I18n/Proc/String support
|
13
|
+
for both types of messages, by replacing ActiveModel::Errors with a local
|
14
|
+
message list. This provides better consistency between the error message and
|
15
|
+
success message implementations.
|
16
|
+
* Use a customized check list registry to ensure order persistence and object
|
17
|
+
uniqueness across Ruby versions.
|
18
|
+
* Upgrade Combustion development support gem to fix deprecations in Rails 4.0.
|
19
|
+
|
20
|
+
### :boom: Backward incompatible changes
|
21
|
+
|
22
|
+
* Attributes may now have multiple success messages bound to them for
|
23
|
+
reporting. This means that there are now, possibly, more than one message per
|
24
|
+
key.
|
25
|
+
|
7
26
|
## [2.1.0][v2.1.0] / 2013-06-28
|
8
27
|
|
9
28
|
* Update the gemspec to allow for Rails 4.0 environments.
|
data/README.md
CHANGED
@@ -32,11 +32,26 @@ validations:
|
|
32
32
|
|
33
33
|
## Installation
|
34
34
|
|
35
|
+
To install, add this line to your application's Gemfile:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
gem 'rapporteur'
|
39
|
+
```
|
40
|
+
|
41
|
+
And then execute:
|
42
|
+
|
43
|
+
```bash
|
44
|
+
$ bundle install
|
45
|
+
```
|
46
|
+
|
47
|
+
### Supported environments
|
48
|
+
|
35
49
|
Supported Ruby versions:
|
36
50
|
|
37
51
|
* MRI 2.0.0
|
38
52
|
* MRI 1.9.3
|
39
53
|
* MRI 1.9.2
|
54
|
+
* MRI 1.8.7
|
40
55
|
* JRuby 1.7.4
|
41
56
|
|
42
57
|
Supported Rails versions:
|
@@ -45,18 +60,6 @@ Supported Rails versions:
|
|
45
60
|
* Rails 3.2.x.
|
46
61
|
* Rails 3.1.x.
|
47
62
|
|
48
|
-
To install, add this line to your application's Gemfile:
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
gem 'rapporteur'
|
52
|
-
```
|
53
|
-
|
54
|
-
And then execute:
|
55
|
-
|
56
|
-
```bash
|
57
|
-
$ bundle
|
58
|
-
```
|
59
|
-
|
60
63
|
## Usage
|
61
64
|
|
62
65
|
Simply adding the gem requirement to your Gemfile is enough to install and
|
@@ -137,24 +140,25 @@ happy with it, add an error to the given `checker` instance:
|
|
137
140
|
```ruby
|
138
141
|
# config/initializers/rapporteur.rb
|
139
142
|
|
143
|
+
# Define a simple check as a block:
|
140
144
|
Rapporteur.add_check do |checker|
|
141
145
|
checker.add_message(:paid, "too much")
|
142
146
|
end
|
143
147
|
|
148
|
+
# Make and use a reusable Proc or lambda:
|
144
149
|
my_proc_check = lambda { |checker|
|
145
150
|
checker.add_error(:luck, :bad) if rand(2) > 0
|
146
151
|
checker.add_message(:luck, :good)
|
147
152
|
}
|
148
|
-
|
149
153
|
Rapporteur.add_check(my_proc_check)
|
150
154
|
|
155
|
+
# Package a check into a Class:
|
151
156
|
class MyClassCheck
|
152
157
|
def self.call(checker)
|
153
158
|
@@counter ||= 0
|
154
159
|
checker.add_error(:count, :exceeded) if @@counter > 50
|
155
160
|
end
|
156
161
|
end
|
157
|
-
|
158
162
|
Rapporteur.add_check(MyClassCheck)
|
159
163
|
```
|
160
164
|
|
@@ -199,23 +203,25 @@ Rapporteur::Revision.current = Rails.root.join("REVISION").read.strip
|
|
199
203
|
# Force a particular directory and use Git
|
200
204
|
Rapporteur::Revision.current = `cd "#{Rails.root}" && git rev-parse HEAD`.strip
|
201
205
|
|
202
|
-
# Use an ENV variable (Heroku)
|
206
|
+
# Use an ENV variable (Heroku Bamboo Stack)
|
203
207
|
Rapporteur::Revision.current = ENV["REVISION"]
|
204
208
|
|
205
209
|
# Do some crazy calculation
|
206
210
|
Rapporteur::Revision.current = lambda { MyRevisionCalculator.execute! }
|
207
211
|
```
|
208
212
|
|
209
|
-
### Customizing the
|
213
|
+
### Customizing the messages
|
210
214
|
|
211
|
-
The error messages displayed in the event that application
|
212
|
-
all
|
213
|
-
with the gem, but you may override them
|
214
|
-
|
215
|
+
The success and error messages displayed in the event that application
|
216
|
+
validations pass or fail are all optionally passed through I18n. There are
|
217
|
+
default localization strings provided with the gem, but you may override them
|
218
|
+
as necessary, by simply redefining the proper locale keys in a locale file
|
219
|
+
within your local application.
|
215
220
|
|
216
221
|
For example, to override the database check failure message:
|
217
222
|
|
218
223
|
```yaml
|
224
|
+
# /config/locales/en.yml
|
219
225
|
en:
|
220
226
|
rapporteur:
|
221
227
|
errors:
|
@@ -223,6 +229,25 @@ en:
|
|
223
229
|
unavailable: "Something went wrong"
|
224
230
|
```
|
225
231
|
|
232
|
+
If you created a custom checker which reports the current sky color, for
|
233
|
+
example, and wanted the success messages to be localized, you could do the
|
234
|
+
following:
|
235
|
+
|
236
|
+
```ruby
|
237
|
+
# /config/initializers/rapporteur.rb
|
238
|
+
sky_check = lambda { |checker| checker.add_message(:sky, :blue) }
|
239
|
+
Rapporteur.add_check(sky_check)
|
240
|
+
```
|
241
|
+
|
242
|
+
```yaml
|
243
|
+
# /config/locales/fr.yml
|
244
|
+
fr:
|
245
|
+
rapporteur:
|
246
|
+
messages:
|
247
|
+
sky:
|
248
|
+
blue: "bleu"
|
249
|
+
```
|
250
|
+
|
226
251
|
## Contributing
|
227
252
|
|
228
253
|
1. Fork it
|
data/Rakefile
CHANGED
data/config/routes.rb
CHANGED
data/lib/rapporteur.rb
CHANGED
@@ -5,9 +5,11 @@ require "rapporteur/version"
|
|
5
5
|
# application status endpoint.
|
6
6
|
#
|
7
7
|
module Rapporteur
|
8
|
+
autoload :CheckList, 'rapporteur/check_list'
|
8
9
|
autoload :Checker, 'rapporteur/checker'
|
9
10
|
autoload :CheckerDeprecations, 'rapporteur/checker_deprecations'
|
10
11
|
autoload :Checks, 'rapporteur/checks'
|
12
|
+
autoload :MessageList, 'rapporteur/message_list'
|
11
13
|
autoload :Responder, 'rapporteur/responder'
|
12
14
|
autoload :Revision, 'rapporteur/revision'
|
13
15
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Rapporteur
|
2
|
+
# Manages a list of checks.
|
3
|
+
#
|
4
|
+
# The goals of this object are to store and return the check objects given to
|
5
|
+
# it in the same order they were given (in Ruby 1.8 and newer). And, to
|
6
|
+
# ensure that the same check is not added twice to be run.
|
7
|
+
#
|
8
|
+
# Previously, a native Ruby Set was used. However, Sets do not guarantee
|
9
|
+
# order, particularly in Ruby 1.8. A simple Array is possible, but loses the
|
10
|
+
# uniqueness constraint of the objects added.
|
11
|
+
#
|
12
|
+
class CheckList
|
13
|
+
# Public: Returns a new, empty CheckList instance.
|
14
|
+
#
|
15
|
+
def initialize
|
16
|
+
@list = Array.new
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
# Public: Add a new check to the list.
|
21
|
+
#
|
22
|
+
# Returns the CheckList instance.
|
23
|
+
#
|
24
|
+
def add(check)
|
25
|
+
@list << check unless @list.include?(check)
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
# Public: Empties all checks from the list. This functionally resets the
|
30
|
+
# list to an initial state.
|
31
|
+
#
|
32
|
+
# Returns the CheckList instance.
|
33
|
+
#
|
34
|
+
def clear
|
35
|
+
@list.clear
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: Iterates over all of the contained objects and yields them out,
|
40
|
+
# individually.
|
41
|
+
#
|
42
|
+
# Returns the CheckList instance.
|
43
|
+
#
|
44
|
+
def each(&block)
|
45
|
+
@list.each(&block)
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
# Public: Returns true if the list is empty.
|
50
|
+
#
|
51
|
+
def empty?
|
52
|
+
@list.empty?
|
53
|
+
end
|
54
|
+
|
55
|
+
# Public: Returns the objects in the list in an Array.
|
56
|
+
#
|
57
|
+
def to_a
|
58
|
+
@list.dup
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/rapporteur/checker.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
1
|
module Rapporteur
|
4
2
|
# The center of the Rapporteur library, Checker manages holding and running
|
5
3
|
# the custom checks, holding any application error messages, and provides the
|
6
4
|
# controller with that data for rendering.
|
7
5
|
#
|
8
6
|
class Checker
|
9
|
-
include ActiveModel::Validations
|
10
7
|
extend CheckerDeprecations
|
11
8
|
|
12
9
|
|
13
10
|
def initialize
|
14
|
-
@messages =
|
15
|
-
@
|
11
|
+
@messages = MessageList.new(:messages)
|
12
|
+
@errors = MessageList.new(:errors)
|
13
|
+
@check_list = CheckList.new
|
16
14
|
reset
|
17
15
|
end
|
18
16
|
|
@@ -36,9 +34,9 @@ module Rapporteur
|
|
36
34
|
#
|
37
35
|
def add_check(object_or_nil_with_block=nil, &block)
|
38
36
|
if block_given?
|
39
|
-
@
|
37
|
+
@check_list.add(block)
|
40
38
|
elsif object_or_nil_with_block.respond_to?(:call)
|
41
|
-
@
|
39
|
+
@check_list.add(object_or_nil_with_block)
|
42
40
|
else
|
43
41
|
raise ArgumentError, "A check must respond to #call."
|
44
42
|
end
|
@@ -53,7 +51,7 @@ module Rapporteur
|
|
53
51
|
# Returns self.
|
54
52
|
#
|
55
53
|
def clear
|
56
|
-
@
|
54
|
+
@check_list.clear
|
57
55
|
self
|
58
56
|
end
|
59
57
|
|
@@ -78,7 +76,7 @@ module Rapporteur
|
|
78
76
|
#
|
79
77
|
def run
|
80
78
|
reset
|
81
|
-
@
|
79
|
+
@check_list.each do |object|
|
82
80
|
object.call(self)
|
83
81
|
break if @halted
|
84
82
|
end
|
@@ -106,9 +104,7 @@ module Rapporteur
|
|
106
104
|
# Returns self.
|
107
105
|
#
|
108
106
|
def add_error(key, message, options={})
|
109
|
-
|
110
|
-
options[:default] = [message, message.to_s.humanize]
|
111
|
-
errors.add(key, message, options)
|
107
|
+
@errors.add(key, message)
|
112
108
|
self
|
113
109
|
end
|
114
110
|
|
@@ -128,7 +124,7 @@ module Rapporteur
|
|
128
124
|
# Returns self.
|
129
125
|
#
|
130
126
|
def add_message(name, message)
|
131
|
-
@messages
|
127
|
+
@messages.add(name, message)
|
132
128
|
self
|
133
129
|
end
|
134
130
|
|
@@ -136,7 +132,14 @@ module Rapporteur
|
|
136
132
|
# Internal: Returns a hash of messages suitable for conversion into JSON.
|
137
133
|
#
|
138
134
|
def as_json(args={})
|
139
|
-
@messages
|
135
|
+
@messages.to_hash
|
136
|
+
end
|
137
|
+
|
138
|
+
##
|
139
|
+
# Internal: Used by Rails' JSON serialization to render error messages.
|
140
|
+
#
|
141
|
+
def errors
|
142
|
+
@errors
|
140
143
|
end
|
141
144
|
|
142
145
|
##
|
@@ -156,7 +159,7 @@ module Rapporteur
|
|
156
159
|
def reset
|
157
160
|
@halted = false
|
158
161
|
@messages.clear
|
159
|
-
errors.clear
|
162
|
+
@errors.clear
|
160
163
|
end
|
161
164
|
end
|
162
165
|
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
module Rapporteur
|
5
|
+
# A container of keys and one or more messages per key. This acts similarly
|
6
|
+
# to an ActiveModel::Errors collection from Ruby on Rails.
|
7
|
+
#
|
8
|
+
class MessageList
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
|
12
|
+
def_delegator :@messages, :clear
|
13
|
+
def_delegator :@messages, :empty?
|
14
|
+
|
15
|
+
|
16
|
+
# Public: Initialize a new MessageList instance.
|
17
|
+
#
|
18
|
+
# list_type - A Symbol representing the type of this list. This Symbol is
|
19
|
+
# used to determine the structure of the I18n key used when
|
20
|
+
# translating the given message Symbols.
|
21
|
+
# Allowed values: :messages or :errors.
|
22
|
+
#
|
23
|
+
# Returns a MessageList instance.
|
24
|
+
#
|
25
|
+
def initialize(list_type)
|
26
|
+
@list_type = list_type
|
27
|
+
@messages = Hash.new { |hash, key| hash[key] = Set.new }
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
# Public: Adds a new message to the list for the given attribute.
|
32
|
+
#
|
33
|
+
# attribute - A Symbol describing the category, attribute, or name to which
|
34
|
+
# the message pertains.
|
35
|
+
# message - A Symbol, String, or Proc which contains the message for the
|
36
|
+
# attribute.
|
37
|
+
#
|
38
|
+
# If a String is given, it is directly used for the message.
|
39
|
+
#
|
40
|
+
# If a Symbol is given, it is used to lookup the full message
|
41
|
+
# from I18n, under the "rapporteur.<list_type>.<message Symbol>"
|
42
|
+
# key. For instance, if this is a :messages list, and the
|
43
|
+
# attribute is :time, then I18n would be queried for
|
44
|
+
# "rapporteur.messages.time".
|
45
|
+
#
|
46
|
+
# If a Proc is given, it is `.call`'d with no parameters. The
|
47
|
+
# return value from the Proc is directly used for the message.
|
48
|
+
#
|
49
|
+
# Examples
|
50
|
+
#
|
51
|
+
# list.add(:time, '2013-08-23T12:34:00Z')
|
52
|
+
# list.add(:time, :too_late)
|
53
|
+
# list.add(:time, lambda { Time.now.iso8601 })
|
54
|
+
#
|
55
|
+
# Returns the MessageList instance.
|
56
|
+
#
|
57
|
+
def add(attribute, message)
|
58
|
+
@messages[attribute.to_sym].add(normalize_message(attribute, message))
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
# Public: Generates an Array containing the combination of all of the added
|
63
|
+
# attributes and their messages.
|
64
|
+
#
|
65
|
+
# Examples
|
66
|
+
#
|
67
|
+
# list.add(:time, 'is now')
|
68
|
+
# list.add(:time, 'is valuable')
|
69
|
+
# list.add(:day, 'is today')
|
70
|
+
# list.full_messages
|
71
|
+
# # => ["time is now", "time is valuable", "day is today"]
|
72
|
+
#
|
73
|
+
# Returns an Array containing Strings of messages.
|
74
|
+
#
|
75
|
+
def full_messages
|
76
|
+
@messages.map { |attribute, attribute_messages|
|
77
|
+
attribute_messages.collect { |message| "#{attribute} #{message}" }
|
78
|
+
}.flatten
|
79
|
+
end
|
80
|
+
|
81
|
+
# Public: Returns the added attributes and their messages as a Hash, keyed
|
82
|
+
# by the attribute, with either an Array containing all of the added
|
83
|
+
# messages or just the single attribute message.
|
84
|
+
#
|
85
|
+
# Examples
|
86
|
+
#
|
87
|
+
# list.add(:time, 'is now')
|
88
|
+
# list.add(:time, 'is valuable')
|
89
|
+
# list.add(:day, 'is today')
|
90
|
+
# list.full_messages
|
91
|
+
# # => {:time => ["is now", "is valuable"], :day => "is today"}
|
92
|
+
#
|
93
|
+
# Returns a Hash instance.
|
94
|
+
#
|
95
|
+
def to_hash
|
96
|
+
hash = Hash.new
|
97
|
+
@messages.each_pair do |key, value|
|
98
|
+
if value.size == 1
|
99
|
+
hash[key] = value.first
|
100
|
+
else
|
101
|
+
hash[key] = value.to_a
|
102
|
+
end
|
103
|
+
end
|
104
|
+
hash
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
|
111
|
+
def generate_message(key, type)
|
112
|
+
I18n.translate(type, {
|
113
|
+
:default => [type, type.to_s],
|
114
|
+
:scope => [:rapporteur, @list_type, key]
|
115
|
+
})
|
116
|
+
end
|
117
|
+
|
118
|
+
def normalize_message(attribute, message)
|
119
|
+
case message
|
120
|
+
when Symbol
|
121
|
+
generate_message(attribute, message)
|
122
|
+
when Proc
|
123
|
+
message.call
|
124
|
+
else
|
125
|
+
message
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/lib/rapporteur/responder.rb
CHANGED
@@ -21,11 +21,11 @@ module Rapporteur
|
|
21
21
|
|
22
22
|
if Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR == 1
|
23
23
|
def display_errors
|
24
|
-
controller.render format => {errors
|
24
|
+
controller.render format => {:errors => resource.errors}, :status => :internal_server_error
|
25
25
|
end
|
26
26
|
else
|
27
27
|
def display_errors
|
28
|
-
controller.render format => resource_errors, status
|
28
|
+
controller.render format => resource_errors, :status => :internal_server_error
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/lib/rapporteur/rspec.rb
CHANGED
@@ -59,7 +59,7 @@ end
|
|
59
59
|
RSpec::Matchers.define :include_status_message do |name, message|
|
60
60
|
match do |response|
|
61
61
|
@body = JSON.parse(response.body)
|
62
|
-
@body.has_key?(name) && @body.fetch(name)
|
62
|
+
@body.has_key?(name) && @body.fetch(name).include?(message)
|
63
63
|
end
|
64
64
|
|
65
65
|
failure_message_for_should do |actual|
|
data/lib/rapporteur/version.rb
CHANGED
data/rapporteur.gemspec
CHANGED
@@ -18,12 +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 'i18n', '~> 0.6'
|
21
22
|
spec.add_dependency 'railties', '>= 3.1', '< 4.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
|
-
spec.add_development_dependency "combustion", "~> 0.5"
|
26
|
+
spec.add_development_dependency "combustion", "~> 0.5", ">= 0.5.1"
|
27
27
|
spec.add_development_dependency "rails", ">= 3.1", "< 4.1"
|
28
28
|
spec.add_development_dependency "rspec-rails", "~> 2.11"
|
29
29
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rapporteur::CheckList do
|
4
|
+
let(:list) { described_class.new }
|
5
|
+
|
6
|
+
context '#add' do
|
7
|
+
it 'adds the given object to the list' do
|
8
|
+
list.add(check = double)
|
9
|
+
expect(list.to_a).to include(check)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'does not return duplicate entries' do
|
13
|
+
list.add(check = double)
|
14
|
+
list.add(check)
|
15
|
+
expect(list.to_a).to have(1).check
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context '#clear' do
|
20
|
+
it 'empties the list of objects' do
|
21
|
+
list.add(double)
|
22
|
+
expect { list.clear }.to change(list, :empty?).to(true)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context '#each' do
|
27
|
+
it 'yields each contained object in the order added' do
|
28
|
+
list.add(check0 = double)
|
29
|
+
list.add(check1 = double)
|
30
|
+
list.add(check2 = double)
|
31
|
+
returns = Array.new
|
32
|
+
|
33
|
+
list.each do |object|
|
34
|
+
returns << object
|
35
|
+
end
|
36
|
+
|
37
|
+
expect(returns[0]).to equal(check0)
|
38
|
+
expect(returns[1]).to equal(check1)
|
39
|
+
expect(returns[2]).to equal(check2)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns itself' do
|
43
|
+
expect(list.each).to equal(list)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context '#to_a' do
|
48
|
+
it 'returns an Array' do
|
49
|
+
expect(list.to_a).to be_an(Array)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns new different but equivalent Array instances' do
|
53
|
+
return1 = list.to_a
|
54
|
+
return2 = list.to_a
|
55
|
+
expect(return1).to_not equal(return2)
|
56
|
+
expect(return1).to eq(return2)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rapporteur::MessageList do
|
4
|
+
let(:list) { Rapporteur::MessageList.new(:errors) }
|
5
|
+
|
6
|
+
before { I18n.backend.reload! }
|
7
|
+
|
8
|
+
context '#add' do
|
9
|
+
it 'returns the MessageList instance.' do
|
10
|
+
expect(list.add(:test, 'message')).to equal(list)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'adds a String message to the #full_messages' do
|
14
|
+
list.add(:test, 'message')
|
15
|
+
expect(list.full_messages).to include('test message')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'adds unrecognized Symbols as Strings to the #full_messages' do
|
19
|
+
list.add(:test, :message)
|
20
|
+
expect(list.full_messages).to include('test message')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'adds multiple messages to an attribute' do
|
24
|
+
list.add(:test, 'message 1')
|
25
|
+
list.add(:test, 'message 2')
|
26
|
+
expect(list.full_messages).to include('test message 1')
|
27
|
+
expect(list.full_messages).to include('test message 2')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'translates and adds recognized I18n keys in the #full_messages' do
|
31
|
+
add_translation(:errors, :test, :i18n_message, 'translated')
|
32
|
+
list.add(:test, :i18n_message)
|
33
|
+
expect(list.full_messages).to include('test translated')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'translates based on the initialized list type' do
|
37
|
+
add_translation(:string, :test, :i18n_message, 'strings')
|
38
|
+
add_translation(:messages, :test, :i18n_message, 'messages')
|
39
|
+
add_translation(:errors, :test, :i18n_message, 'errors')
|
40
|
+
message_list = Rapporteur::MessageList.new(:messages)
|
41
|
+
error_list = Rapporteur::MessageList.new(:errors)
|
42
|
+
message_list.add(:test, :i18n_message)
|
43
|
+
error_list.add(:test, :i18n_message)
|
44
|
+
expect(message_list.full_messages).to include('test messages')
|
45
|
+
expect(message_list.full_messages).not_to include('test errors')
|
46
|
+
expect(error_list.full_messages).to include('test errors')
|
47
|
+
expect(error_list.full_messages).not_to include('test messages')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context '#to_hash' do
|
52
|
+
it 'flattens key/value pairs with only one value' do
|
53
|
+
list.add(:test, 'message')
|
54
|
+
expect(list.to_hash).to eq({:test => 'message'})
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'retains multiple values for a single key' do
|
58
|
+
list.add(:test, 'message1')
|
59
|
+
list.add(:test, 'message2')
|
60
|
+
result = list.to_hash
|
61
|
+
expect(result).to have_key(:test)
|
62
|
+
expect(result[:test]).to include('message1')
|
63
|
+
expect(result[:test]).to include('message2')
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns a new, unique, but equivalent Hash with each call' do
|
67
|
+
list.add(:test, 'message')
|
68
|
+
return1 = list.to_hash
|
69
|
+
return2 = list.to_hash
|
70
|
+
expect(return1).not_to equal(return2)
|
71
|
+
expect(return1).to eq(return2)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
|
79
|
+
def add_translation(type, key, message, string)
|
80
|
+
I18n.backend.store_translations('en', {:rapporteur => {type.to_sym => {key.to_sym => {message.to_sym => string}}}})
|
81
|
+
end
|
82
|
+
end
|
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'A status request with a RevisionCheck' do
|
4
4
|
before do
|
5
|
+
Rapporteur::Revision.stub(:current) { 'revisionidentifier' }
|
5
6
|
Rapporteur.add_check(Rapporteur::Checks::RevisionCheck)
|
6
7
|
end
|
7
8
|
|
@@ -10,10 +11,8 @@ describe 'A status request with a RevisionCheck' do
|
|
10
11
|
it_behaves_like 'a successful status response'
|
11
12
|
|
12
13
|
context 'the response payload' do
|
13
|
-
subject { get(status_path) ; JSON.parse(response.body) }
|
14
|
-
|
15
14
|
it 'contains the current application revision' do
|
16
|
-
expect(subject.
|
15
|
+
expect(subject).to include_status_message('revision', 'revisionidentifier')
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
@@ -10,13 +10,9 @@ describe 'A status request with a TimeCheck' do
|
|
10
10
|
it_behaves_like 'a successful status response'
|
11
11
|
|
12
12
|
context 'the response payload' do
|
13
|
-
|
14
|
-
|
15
|
-
|
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))
|
13
|
+
it 'contains the time in ISO8601' do
|
14
|
+
Time.stub(:now).and_return(Time.gm(2013,8,23))
|
15
|
+
expect(subject).to include_status_message('time', Time.gm(2013,8,23).iso8601)
|
20
16
|
end
|
21
17
|
end
|
22
18
|
end
|
data/spec/routing/routes_spec.rb
CHANGED
@@ -2,22 +2,22 @@ require 'spec_helper.rb'
|
|
2
2
|
|
3
3
|
describe "status routes" do
|
4
4
|
it 'routes /status.json to statuses#show' do
|
5
|
-
expect({ get
|
6
|
-
action
|
7
|
-
controller
|
8
|
-
format
|
5
|
+
expect({ :get => '/status.json'}).to route_to({
|
6
|
+
:action => 'show',
|
7
|
+
:controller => 'statuses',
|
8
|
+
:format => 'json',
|
9
9
|
})
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'does not route /status' do
|
13
|
-
expect({ get
|
13
|
+
expect({ :get => '/status'}).to_not be_routable
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'does not route /status.html' do
|
17
|
-
expect({ get
|
17
|
+
expect({ :get => '/status.html'}).to_not be_routable
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'does not route /status.xml' do
|
21
|
-
expect({ get
|
21
|
+
expect({ :get => '/status.xml'}).to_not be_routable
|
22
22
|
end
|
23
23
|
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:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Envy Labs
|
@@ -9,42 +9,42 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: i18n
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '3.1'
|
21
|
-
- - <
|
18
|
+
- - ~>
|
22
19
|
- !ruby/object:Gem::Version
|
23
|
-
version: '
|
20
|
+
version: '0.6'
|
24
21
|
type: :runtime
|
25
22
|
prerelease: false
|
26
23
|
version_requirements: !ruby/object:Gem::Requirement
|
27
24
|
requirements:
|
28
|
-
- -
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: '3.1'
|
31
|
-
- - <
|
25
|
+
- - ~>
|
32
26
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
27
|
+
version: '0.6'
|
34
28
|
- !ruby/object:Gem::Dependency
|
35
|
-
name:
|
29
|
+
name: railties
|
36
30
|
requirement: !ruby/object:Gem::Requirement
|
37
31
|
requirements:
|
38
32
|
- - ! '>='
|
39
33
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
34
|
+
version: '3.1'
|
35
|
+
- - <
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '4.1'
|
41
38
|
type: :runtime
|
42
39
|
prerelease: false
|
43
40
|
version_requirements: !ruby/object:Gem::Requirement
|
44
41
|
requirements:
|
45
42
|
- - ! '>='
|
46
43
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
44
|
+
version: '3.1'
|
45
|
+
- - <
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.1'
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: appraisal
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,9 @@ dependencies:
|
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.5'
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.5.1
|
83
86
|
type: :development
|
84
87
|
prerelease: false
|
85
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -87,6 +90,9 @@ dependencies:
|
|
87
90
|
- - ~>
|
88
91
|
- !ruby/object:Gem::Version
|
89
92
|
version: '0.5'
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.5.1
|
90
96
|
- !ruby/object:Gem::Dependency
|
91
97
|
name: rails
|
92
98
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,11 +151,13 @@ files:
|
|
145
151
|
- gemfiles/rails3.2.gemfile
|
146
152
|
- gemfiles/rails4.0.gemfile
|
147
153
|
- lib/rapporteur.rb
|
154
|
+
- lib/rapporteur/check_list.rb
|
148
155
|
- lib/rapporteur/checker.rb
|
149
156
|
- lib/rapporteur/checker_deprecations.rb
|
150
157
|
- lib/rapporteur/checks.rb
|
151
158
|
- lib/rapporteur/checks/active_record_check.rb
|
152
159
|
- lib/rapporteur/engine.rb
|
160
|
+
- lib/rapporteur/message_list.rb
|
153
161
|
- lib/rapporteur/responder.rb
|
154
162
|
- lib/rapporteur/revision.rb
|
155
163
|
- lib/rapporteur/rspec.rb
|
@@ -160,6 +168,8 @@ files:
|
|
160
168
|
- spec/internal/db/schema.rb
|
161
169
|
- spec/internal/log/.gitignore
|
162
170
|
- spec/internal/public/favicon.ico
|
171
|
+
- spec/models/check_list_spec.rb
|
172
|
+
- spec/models/message_list_spec.rb
|
163
173
|
- spec/requests/active_record_check_spec.rb
|
164
174
|
- spec/requests/halt_spec.rb
|
165
175
|
- spec/requests/messsage_addition_spec.rb
|
@@ -188,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
198
|
version: '0'
|
189
199
|
requirements: []
|
190
200
|
rubyforge_project:
|
191
|
-
rubygems_version: 2.0.
|
201
|
+
rubygems_version: 2.0.7
|
192
202
|
signing_key:
|
193
203
|
specification_version: 4
|
194
204
|
summary: An engine that provides common status polling endpoint.
|
@@ -198,6 +208,8 @@ test_files:
|
|
198
208
|
- spec/internal/db/schema.rb
|
199
209
|
- spec/internal/log/.gitignore
|
200
210
|
- spec/internal/public/favicon.ico
|
211
|
+
- spec/models/check_list_spec.rb
|
212
|
+
- spec/models/message_list_spec.rb
|
201
213
|
- spec/requests/active_record_check_spec.rb
|
202
214
|
- spec/requests/halt_spec.rb
|
203
215
|
- spec/requests/messsage_addition_spec.rb
|