blackbeard 0.0.2.0 → 0.0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -0
- data/Guardfile +8 -0
- data/README.md +162 -20
- data/Rakefile +6 -0
- data/TODO.md +13 -34
- data/blackbeard.gemspec +5 -1
- data/console.rb +3 -0
- data/dashboard/public/bootstrap3-editable/css/bootstrap-editable.css +663 -0
- data/dashboard/public/bootstrap3-editable/img/clear.png +0 -0
- data/dashboard/public/bootstrap3-editable/img/loading.gif +0 -0
- data/dashboard/public/bootstrap3-editable/js/bootstrap-editable.min.js +7 -0
- data/dashboard/public/fonts/glyphicons-halflings-regular.eot +0 -0
- data/dashboard/public/fonts/glyphicons-halflings-regular.svg +229 -0
- data/dashboard/public/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/dashboard/public/fonts/glyphicons-halflings-regular.woff +0 -0
- data/dashboard/public/javascripts/bootstrap.min.js +7 -0
- data/dashboard/public/javascripts/jquery-1.10.2.min.js +6 -0
- data/dashboard/public/stylesheets/application.css +28 -0
- data/dashboard/public/stylesheets/bootstrap-theme.css +7 -0
- data/dashboard/public/stylesheets/bootstrap.css +7 -0
- data/dashboard/routes/base.rb +19 -0
- data/dashboard/routes/groups.rb +22 -0
- data/dashboard/routes/home.rb +11 -0
- data/dashboard/routes/metrics.rb +30 -0
- data/dashboard/routes/tests.rb +23 -0
- data/dashboard/views/groups/index.erb +22 -0
- data/dashboard/views/groups/show.erb +58 -0
- data/dashboard/views/index.erb +4 -0
- data/dashboard/views/layout.erb +48 -0
- data/dashboard/views/metrics/_metric_data.erb +59 -0
- data/dashboard/views/metrics/index.erb +23 -0
- data/dashboard/views/metrics/show.erb +73 -0
- data/dashboard/views/tests/index.erb +21 -0
- data/dashboard/views/tests/show.erb +58 -0
- data/lib/blackbeard/configuration.rb +8 -1
- data/lib/blackbeard/configuration_methods.rb +24 -0
- data/lib/blackbeard/context.rb +33 -21
- data/lib/blackbeard/dashboard.rb +17 -21
- data/lib/blackbeard/dashboard_helpers.rb +29 -0
- data/lib/blackbeard/errors.rb +2 -2
- data/lib/blackbeard/group.rb +35 -0
- data/lib/blackbeard/metric.rb +34 -32
- data/lib/blackbeard/metric_data/base.rb +101 -0
- data/lib/blackbeard/metric_data/total.rb +39 -0
- data/lib/blackbeard/metric_data/unique.rb +58 -0
- data/lib/blackbeard/metric_date.rb +11 -0
- data/lib/blackbeard/metric_hour.rb +17 -0
- data/lib/blackbeard/pirate.rb +33 -22
- data/lib/blackbeard/redis_store.rb +46 -2
- data/lib/blackbeard/selected_variation.rb +13 -0
- data/lib/blackbeard/storable.rb +39 -27
- data/lib/blackbeard/storable_attributes.rb +54 -0
- data/lib/blackbeard/storable_has_many.rb +60 -0
- data/lib/blackbeard/storable_has_set.rb +59 -0
- data/lib/blackbeard/test.rb +21 -0
- data/lib/blackbeard/version.rb +1 -1
- data/lib/blackbeard.rb +0 -8
- data/spec/configuration_spec.rb +15 -0
- data/spec/context_spec.rb +94 -19
- data/spec/dashboard/groups_spec.rb +50 -0
- data/spec/dashboard/home_spec.rb +20 -0
- data/spec/dashboard/metrics_spec.rb +57 -0
- data/spec/dashboard/tests_spec.rb +43 -0
- data/spec/group_spec.rb +36 -0
- data/spec/metric_data/base_spec.rb +57 -0
- data/spec/metric_data/total_spec.rb +116 -0
- data/spec/metric_data/unique_spec.rb +91 -0
- data/spec/metric_spec.rb +52 -44
- data/spec/pirate_spec.rb +32 -15
- data/spec/redis_store_spec.rb +121 -0
- data/spec/spec_helper.rb +13 -1
- data/spec/storable_attributes_spec.rb +47 -0
- data/spec/storable_has_many_spec.rb +49 -0
- data/spec/storable_has_set_spec.rb +39 -0
- data/spec/storable_spec.rb +33 -0
- data/spec/test_spec.rb +25 -0
- metadata +133 -17
- data/lib/blackbeard/dashboard/helpers.rb +0 -8
- data/lib/blackbeard/dashboard/views/layout.erb +0 -15
- data/lib/blackbeard/dashboard/views/metrics/index.erb +0 -10
- data/lib/blackbeard/dashboard/views/metrics/show.erb +0 -16
- data/lib/blackbeard/feature.rb +0 -13
- data/lib/blackbeard/metric/total.rb +0 -17
- data/lib/blackbeard/metric/unique.rb +0 -18
- data/spec/dashboard_spec.rb +0 -38
- data/spec/total_metric_spec.rb +0 -65
- data/spec/unique_metric_spec.rb +0 -60
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blackbeard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Graff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 2.14.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 2.14.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rack-test
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,48 @@ dependencies:
|
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.2.5
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.2.5
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: terminal-notifier-guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: codeclimate-test-reporter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
112
|
name: sinatra-base
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +122,20 @@ dependencies:
|
|
80
122
|
- - ~>
|
81
123
|
- !ruby/object:Gem::Version
|
82
124
|
version: '1.4'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: sinatra-partial
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.4.0
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.4.0
|
83
139
|
- !ruby/object:Gem::Dependency
|
84
140
|
name: tzinfo
|
85
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,37 +199,85 @@ extensions: []
|
|
143
199
|
extra_rdoc_files: []
|
144
200
|
files:
|
145
201
|
- .gitignore
|
202
|
+
- .travis.yml
|
146
203
|
- Gemfile
|
204
|
+
- Guardfile
|
147
205
|
- LICENSE.txt
|
148
206
|
- README.md
|
149
207
|
- Rakefile
|
150
208
|
- TODO.md
|
151
209
|
- blackbeard.gemspec
|
210
|
+
- console.rb
|
211
|
+
- dashboard/public/bootstrap3-editable/css/bootstrap-editable.css
|
212
|
+
- dashboard/public/bootstrap3-editable/img/clear.png
|
213
|
+
- dashboard/public/bootstrap3-editable/img/loading.gif
|
214
|
+
- dashboard/public/bootstrap3-editable/js/bootstrap-editable.min.js
|
215
|
+
- dashboard/public/fonts/glyphicons-halflings-regular.eot
|
216
|
+
- dashboard/public/fonts/glyphicons-halflings-regular.svg
|
217
|
+
- dashboard/public/fonts/glyphicons-halflings-regular.ttf
|
218
|
+
- dashboard/public/fonts/glyphicons-halflings-regular.woff
|
219
|
+
- dashboard/public/javascripts/bootstrap.min.js
|
220
|
+
- dashboard/public/javascripts/jquery-1.10.2.min.js
|
221
|
+
- dashboard/public/stylesheets/application.css
|
222
|
+
- dashboard/public/stylesheets/bootstrap-theme.css
|
223
|
+
- dashboard/public/stylesheets/bootstrap.css
|
224
|
+
- dashboard/routes/base.rb
|
225
|
+
- dashboard/routes/groups.rb
|
226
|
+
- dashboard/routes/home.rb
|
227
|
+
- dashboard/routes/metrics.rb
|
228
|
+
- dashboard/routes/tests.rb
|
229
|
+
- dashboard/views/groups/index.erb
|
230
|
+
- dashboard/views/groups/show.erb
|
231
|
+
- dashboard/views/index.erb
|
232
|
+
- dashboard/views/layout.erb
|
233
|
+
- dashboard/views/metrics/_metric_data.erb
|
234
|
+
- dashboard/views/metrics/index.erb
|
235
|
+
- dashboard/views/metrics/show.erb
|
236
|
+
- dashboard/views/tests/index.erb
|
237
|
+
- dashboard/views/tests/show.erb
|
152
238
|
- lib/blackbeard.rb
|
153
239
|
- lib/blackbeard/configuration.rb
|
240
|
+
- lib/blackbeard/configuration_methods.rb
|
154
241
|
- lib/blackbeard/context.rb
|
155
242
|
- lib/blackbeard/dashboard.rb
|
156
|
-
- lib/blackbeard/
|
157
|
-
- lib/blackbeard/dashboard/views/layout.erb
|
158
|
-
- lib/blackbeard/dashboard/views/metrics/index.erb
|
159
|
-
- lib/blackbeard/dashboard/views/metrics/show.erb
|
243
|
+
- lib/blackbeard/dashboard_helpers.rb
|
160
244
|
- lib/blackbeard/errors.rb
|
161
|
-
- lib/blackbeard/
|
245
|
+
- lib/blackbeard/group.rb
|
162
246
|
- lib/blackbeard/metric.rb
|
163
|
-
- lib/blackbeard/
|
164
|
-
- lib/blackbeard/
|
247
|
+
- lib/blackbeard/metric_data/base.rb
|
248
|
+
- lib/blackbeard/metric_data/total.rb
|
249
|
+
- lib/blackbeard/metric_data/unique.rb
|
250
|
+
- lib/blackbeard/metric_date.rb
|
251
|
+
- lib/blackbeard/metric_hour.rb
|
165
252
|
- lib/blackbeard/pirate.rb
|
166
253
|
- lib/blackbeard/redis_store.rb
|
254
|
+
- lib/blackbeard/selected_variation.rb
|
167
255
|
- lib/blackbeard/storable.rb
|
256
|
+
- lib/blackbeard/storable_attributes.rb
|
257
|
+
- lib/blackbeard/storable_has_many.rb
|
258
|
+
- lib/blackbeard/storable_has_set.rb
|
259
|
+
- lib/blackbeard/test.rb
|
168
260
|
- lib/blackbeard/version.rb
|
169
261
|
- spec/blackbeard_spec.rb
|
262
|
+
- spec/configuration_spec.rb
|
170
263
|
- spec/context_spec.rb
|
171
|
-
- spec/
|
264
|
+
- spec/dashboard/groups_spec.rb
|
265
|
+
- spec/dashboard/home_spec.rb
|
266
|
+
- spec/dashboard/metrics_spec.rb
|
267
|
+
- spec/dashboard/tests_spec.rb
|
268
|
+
- spec/group_spec.rb
|
269
|
+
- spec/metric_data/base_spec.rb
|
270
|
+
- spec/metric_data/total_spec.rb
|
271
|
+
- spec/metric_data/unique_spec.rb
|
172
272
|
- spec/metric_spec.rb
|
173
273
|
- spec/pirate_spec.rb
|
274
|
+
- spec/redis_store_spec.rb
|
174
275
|
- spec/spec_helper.rb
|
175
|
-
- spec/
|
176
|
-
- spec/
|
276
|
+
- spec/storable_attributes_spec.rb
|
277
|
+
- spec/storable_has_many_spec.rb
|
278
|
+
- spec/storable_has_set_spec.rb
|
279
|
+
- spec/storable_spec.rb
|
280
|
+
- spec/test_spec.rb
|
177
281
|
homepage: https://github.com/goldstar/blackbeard
|
178
282
|
licenses:
|
179
283
|
- MIT
|
@@ -200,10 +304,22 @@ specification_version: 4
|
|
200
304
|
summary: Blackbeard is a Redis backed metrics collection system with a Rack dashboard
|
201
305
|
test_files:
|
202
306
|
- spec/blackbeard_spec.rb
|
307
|
+
- spec/configuration_spec.rb
|
203
308
|
- spec/context_spec.rb
|
204
|
-
- spec/
|
309
|
+
- spec/dashboard/groups_spec.rb
|
310
|
+
- spec/dashboard/home_spec.rb
|
311
|
+
- spec/dashboard/metrics_spec.rb
|
312
|
+
- spec/dashboard/tests_spec.rb
|
313
|
+
- spec/group_spec.rb
|
314
|
+
- spec/metric_data/base_spec.rb
|
315
|
+
- spec/metric_data/total_spec.rb
|
316
|
+
- spec/metric_data/unique_spec.rb
|
205
317
|
- spec/metric_spec.rb
|
206
318
|
- spec/pirate_spec.rb
|
319
|
+
- spec/redis_store_spec.rb
|
207
320
|
- spec/spec_helper.rb
|
208
|
-
- spec/
|
209
|
-
- spec/
|
321
|
+
- spec/storable_attributes_spec.rb
|
322
|
+
- spec/storable_has_many_spec.rb
|
323
|
+
- spec/storable_has_set_spec.rb
|
324
|
+
- spec/storable_spec.rb
|
325
|
+
- spec/test_spec.rb
|
@@ -1,10 +0,0 @@
|
|
1
|
-
<h2>Metrics</h2>
|
2
|
-
<% if @metrics.any? %>
|
3
|
-
<ul>
|
4
|
-
<% @metrics.each do |metric| %>
|
5
|
-
<li><a href="<%= url("metrics/#{metric.type}/#{metric.name}") %>"><%= metric.name.capitalize %> - <%= metric.type.capitalize %></a></li>
|
6
|
-
<% end %>
|
7
|
-
</ul>
|
8
|
-
<% else %>
|
9
|
-
No metrics recorded.
|
10
|
-
<% end %>
|
@@ -1,16 +0,0 @@
|
|
1
|
-
<h2><%= @metric.name.capitalize %> - <%= @metric.type.capitalize %></h2>
|
2
|
-
|
3
|
-
<table>
|
4
|
-
<tr>
|
5
|
-
<th>Hour</th>
|
6
|
-
<th>Count</th>
|
7
|
-
</tr>
|
8
|
-
|
9
|
-
<% @metric.hours.each do |metric_hour| %>
|
10
|
-
<tr>
|
11
|
-
<td><%= metric_hour[:hour] %></td>
|
12
|
-
<td><%= metric_hour[:result] %></td>
|
13
|
-
</tr>
|
14
|
-
<% end %>
|
15
|
-
|
16
|
-
</table>
|
data/lib/blackbeard/feature.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require "blackbeard/metric"
|
2
|
-
|
3
|
-
module Blackbeard
|
4
|
-
class Metric::Total < Metric
|
5
|
-
|
6
|
-
def add(uid, amount)
|
7
|
-
key = key_for_hour(tz.now)
|
8
|
-
db.set_add_member(hours_set_key, key)
|
9
|
-
db.increment_by_float(key, amount.to_f)
|
10
|
-
end
|
11
|
-
|
12
|
-
def result_for_hour_key(key)
|
13
|
-
db.get(key).to_f
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require "blackbeard/metric"
|
2
|
-
|
3
|
-
module Blackbeard
|
4
|
-
class Metric::Unique < Metric
|
5
|
-
|
6
|
-
def add(uid)
|
7
|
-
key = key_for_hour(tz.now)
|
8
|
-
db.set_add_member(hours_set_key, key)
|
9
|
-
db.set_add_member(key, uid)
|
10
|
-
end
|
11
|
-
|
12
|
-
def result_for_hour_key(key)
|
13
|
-
db.set_count(key)
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
data/spec/dashboard_spec.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
require 'rack/test'
|
4
|
-
require 'blackbeard/dashboard'
|
5
|
-
|
6
|
-
describe Blackbeard::Dashboard do
|
7
|
-
include Rack::Test::Methods
|
8
|
-
|
9
|
-
let(:app) { Blackbeard::Dashboard }
|
10
|
-
|
11
|
-
describe "/" do
|
12
|
-
it "should redirect" do
|
13
|
-
get "/"
|
14
|
-
last_response.should be_redirect
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "/metrics" do
|
19
|
-
it "should list all the metrics" do
|
20
|
-
Blackbeard::Metric::Total.new("Jostling")
|
21
|
-
get "/metrics"
|
22
|
-
|
23
|
-
last_response.should be_ok
|
24
|
-
last_response.body.should include('Jostling')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "/metrics/:type/:name" do
|
29
|
-
it "should show a metric" do
|
30
|
-
metric = Blackbeard::Metric::Total.new("Jostling")
|
31
|
-
get "/metrics/#{metric.type}/#{metric.name}"
|
32
|
-
|
33
|
-
last_response.should be_ok
|
34
|
-
last_response.body.should include("Jostling")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
data/spec/total_metric_spec.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe Blackbeard::Metric::Total do
|
4
|
-
|
5
|
-
let(:metric) { Blackbeard::Metric::Total.new("page views") }
|
6
|
-
let(:uid) { "unique identifier" }
|
7
|
-
let(:ouid) { "other unique identifier" }
|
8
|
-
|
9
|
-
describe "add" do
|
10
|
-
it "should create a new metric" do
|
11
|
-
expect{
|
12
|
-
metric.add(uid, 1)
|
13
|
-
}.to change{ Blackbeard::Metric.count }.by(1)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should not create a new metric if it already exists" do
|
17
|
-
metric.add(uid, 1)
|
18
|
-
expect{
|
19
|
-
metric.add(uid, 1)
|
20
|
-
}.to_not change{ Blackbeard::Metric.count }
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should increment the metric by the amount" do
|
24
|
-
expect{
|
25
|
-
metric.add(uid, 2)
|
26
|
-
}.to change{ metric.result_for_hour(Blackbeard.tz.now) }.by(2)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should increment an existing amount" do
|
30
|
-
metric.add(uid, 1)
|
31
|
-
expect{
|
32
|
-
metric.add(uid, 2)
|
33
|
-
}.to change{ metric.result_for_hour(Blackbeard.tz.now) }.from(1).to(3)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should handle negatives ok" do
|
37
|
-
metric.add(uid, 2)
|
38
|
-
expect{
|
39
|
-
metric.add(uid, -1)
|
40
|
-
}.to change{ metric.result_for_hour(Blackbeard.tz.now) }.from(2).to(1)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should handle floats" do
|
44
|
-
metric.add(uid, 2.5)
|
45
|
-
expect{
|
46
|
-
metric.add(uid, 1.25)
|
47
|
-
}.to change{ metric.result_for_hour(Blackbeard.tz.now) }.to(3.75)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
describe "result_for_hour" do
|
54
|
-
it "should return 0 if no metric has been recorded" do
|
55
|
-
metric.result_for_hour(Blackbeard.tz.now).should be_zero
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should return sum if metric called more than once" do
|
59
|
-
metric.add(uid, 2)
|
60
|
-
metric.add(uid, 4)
|
61
|
-
metric.result_for_hour(Blackbeard.tz.now).should == 6
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
data/spec/unique_metric_spec.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe Blackbeard::Metric::Unique do
|
4
|
-
|
5
|
-
let(:metric) { Blackbeard::Metric::Unique.new("join") }
|
6
|
-
let(:uid) { "unique identifier" }
|
7
|
-
let(:ouid) { "other unique identifier" }
|
8
|
-
|
9
|
-
describe "add" do
|
10
|
-
it "should create a new metric" do
|
11
|
-
expect{
|
12
|
-
metric.add(uid)
|
13
|
-
}.to change{ Blackbeard::Metric.count }.by(1)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should not create a new metric if it already exists" do
|
17
|
-
metric.add(uid)
|
18
|
-
expect{
|
19
|
-
metric.add(uid)
|
20
|
-
}.to_not change{ Blackbeard::Metric.count }
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should increment the metric for the uid" do
|
24
|
-
expect{
|
25
|
-
metric.add(uid)
|
26
|
-
}.to change{ metric.result_for_hour(Blackbeard.tz.now) }.by(1)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should not increment the metric for duplicate uids" do
|
30
|
-
metric.add(uid)
|
31
|
-
expect{
|
32
|
-
metric.add(uid)
|
33
|
-
}.to_not change{ metric.result_for_hour(Blackbeard.tz.now) }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "result_for_hour" do
|
38
|
-
it "should return 0 if no metric has been recorded" do
|
39
|
-
metric.result_for_hour(Blackbeard.tz.now).should be_zero
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return 1 if metric called once" do
|
43
|
-
metric.add(uid)
|
44
|
-
metric.result_for_hour(Blackbeard.tz.now).should == 1
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should return 1 if metric called more than once" do
|
48
|
-
3.times{ metric.add(uid) }
|
49
|
-
metric.result_for_hour(Blackbeard.tz.now).should == 1
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should return 2 if metric was called with 2 uniques" do
|
53
|
-
metric.add(uid)
|
54
|
-
metric.add(ouid)
|
55
|
-
metric.result_for_hour(Blackbeard.tz.now).should == 2
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|