vanity 1.9.3 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/.travis.yml +2 -53
- data/Appraisals +3 -12
- data/CHANGELOG +1 -5
- data/Gemfile +0 -10
- data/Gemfile.lock +3 -38
- data/README.rdoc +2 -13
- data/Rakefile +7 -13
- data/bin/vanity +0 -1
- data/doc/rails.textile +0 -12
- data/gemfiles/rails32.gemfile +2 -4
- data/gemfiles/rails32.gemfile.lock +6 -14
- data/gemfiles/rails4.gemfile +1 -4
- data/gemfiles/rails4.gemfile.lock +5 -15
- data/lib/vanity/adapters/active_record_adapter.rb +14 -10
- data/lib/vanity/experiment/ab_test.rb +1 -1
- data/lib/vanity/frameworks/rails.rb +11 -17
- data/lib/vanity/frameworks.rb +3 -10
- data/lib/vanity/metric/active_record.rb +20 -19
- data/lib/vanity/playground.rb +1 -3
- data/lib/vanity/version.rb +1 -1
- data/test/adapters/redis_adapter_test.rb +26 -27
- data/test/autoconnect_test.rb +19 -17
- data/test/cli_test.rb +19 -26
- data/test/experiment/ab_test.rb +2 -15
- data/test/experiment/base_test.rb +18 -22
- data/test/frameworks/rails/action_controller_test.rb +184 -0
- data/test/frameworks/rails/action_mailer_test.rb +65 -0
- data/test/{rails_helper_test.rb → frameworks/rails/action_view_test.rb} +1 -1
- data/test/frameworks/rails/rails_test.rb +285 -0
- data/test/helper_test.rb +13 -10
- data/test/metric/active_record_test.rb +50 -66
- data/test/metric/base_test.rb +39 -41
- data/test/metric/google_analytics_test.rb +13 -16
- data/test/metric/remote_test.rb +18 -19
- data/test/playground_test.rb +1 -1
- data/test/test_helper.rb +25 -43
- data/test/{rails_dashboard_test.rb → web/rails/dashboard_test.rb} +2 -1
- data/vanity.gemspec +3 -2
- metadata +33 -33
- data/gemfiles/rails3.gemfile +0 -32
- data/gemfiles/rails3.gemfile.lock +0 -172
- data/gemfiles/rails31.gemfile +0 -32
- data/gemfiles/rails31.gemfile.lock +0 -181
- data/generators/templates/vanity_migration.rb +0 -54
- data/generators/vanity_generator.rb +0 -8
- data/test/myapp/app/controllers/application_controller.rb +0 -2
- data/test/myapp/app/controllers/main_controller.rb +0 -7
- data/test/myapp/config/boot.rb +0 -110
- data/test/myapp/config/environment.rb +0 -10
- data/test/myapp/config/environments/production.rb +0 -0
- data/test/myapp/config/routes.rb +0 -3
- data/test/passenger_test.rb +0 -52
- data/test/rails_test.rb +0 -554
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
class Sky < ActiveRecord::Base
|
4
4
|
if connected?
|
@@ -9,18 +9,20 @@ class Sky < ActiveRecord::Base
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
scope :high, lambda { { :conditions=>"height >= 4" } }
|
14
|
-
else
|
15
|
-
named_scope :high, lambda { { :conditions=>"height >= 4" } }
|
16
|
-
end
|
12
|
+
scope :high, lambda { { :conditions=>"height >= 4" } }
|
17
13
|
end
|
18
14
|
|
19
15
|
if ActiveRecord::Base.connected?
|
20
16
|
|
21
|
-
|
17
|
+
describe "ActiveRecord Metric" do
|
18
|
+
|
19
|
+
after do
|
20
|
+
Sky.delete_all
|
21
|
+
Sky.reset_callbacks(:create)
|
22
|
+
Sky.reset_callbacks(:save)
|
23
|
+
end
|
22
24
|
|
23
|
-
|
25
|
+
it "record count" do
|
24
26
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
25
27
|
f.write <<-RUBY
|
26
28
|
metric "Sky is limit" do
|
@@ -34,7 +36,7 @@ context "ActiveRecord Metric" do
|
|
34
36
|
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
35
37
|
end
|
36
38
|
|
37
|
-
|
39
|
+
it "record sum" do
|
38
40
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
39
41
|
f.write <<-RUBY
|
40
42
|
metric "Sky is limit" do
|
@@ -48,7 +50,7 @@ context "ActiveRecord Metric" do
|
|
48
50
|
assert_equal 6, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
49
51
|
end
|
50
52
|
|
51
|
-
|
53
|
+
it "record average" do
|
52
54
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
53
55
|
f.write <<-RUBY
|
54
56
|
metric "Sky is limit" do
|
@@ -62,7 +64,7 @@ context "ActiveRecord Metric" do
|
|
62
64
|
assert_equal 5, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
63
65
|
end
|
64
66
|
|
65
|
-
|
67
|
+
it "record minimum" do
|
66
68
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
67
69
|
f.write <<-RUBY
|
68
70
|
metric "Sky is limit" do
|
@@ -76,7 +78,7 @@ context "ActiveRecord Metric" do
|
|
76
78
|
assert_equal 2, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
77
79
|
end
|
78
80
|
|
79
|
-
|
81
|
+
it "record maximum" do
|
80
82
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
81
83
|
f.write <<-RUBY
|
82
84
|
metric "Sky is limit" do
|
@@ -90,7 +92,7 @@ context "ActiveRecord Metric" do
|
|
90
92
|
assert_equal 4, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
91
93
|
end
|
92
94
|
|
93
|
-
|
95
|
+
it "with conditions" do
|
94
96
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
95
97
|
f.write <<-RUBY
|
96
98
|
metric "Sky is limit" do
|
@@ -111,7 +113,7 @@ context "ActiveRecord Metric" do
|
|
111
113
|
assert_equal 11, high_skies
|
112
114
|
end
|
113
115
|
|
114
|
-
|
116
|
+
it "with scope" do
|
115
117
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
116
118
|
f.write <<-RUBY
|
117
119
|
metric "Sky is limit" do
|
@@ -130,7 +132,7 @@ context "ActiveRecord Metric" do
|
|
130
132
|
assert_equal 1, total
|
131
133
|
end
|
132
134
|
|
133
|
-
|
135
|
+
it "with timestamp" do
|
134
136
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
135
137
|
f.write <<-RUBY
|
136
138
|
metric "Sky is limit" do
|
@@ -144,7 +146,7 @@ context "ActiveRecord Metric" do
|
|
144
146
|
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
145
147
|
end
|
146
148
|
|
147
|
-
|
149
|
+
it "with timestamp and table" do
|
148
150
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
149
151
|
f.write <<-RUBY
|
150
152
|
metric "Sky is limit" do
|
@@ -158,7 +160,7 @@ context "ActiveRecord Metric" do
|
|
158
160
|
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
159
161
|
end
|
160
162
|
|
161
|
-
|
163
|
+
it "hooks" do
|
162
164
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
163
165
|
f.write <<-RUBY
|
164
166
|
metric "Sky is limit" do
|
@@ -177,7 +179,7 @@ context "ActiveRecord Metric" do
|
|
177
179
|
assert_equal 4, total
|
178
180
|
end
|
179
181
|
|
180
|
-
|
182
|
+
it "no hooks when metrics disabled" do
|
181
183
|
not_collecting!
|
182
184
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
183
185
|
f.write <<-RUBY
|
@@ -195,7 +197,7 @@ context "ActiveRecord Metric" do
|
|
195
197
|
assert_equal 0, total
|
196
198
|
end
|
197
199
|
|
198
|
-
|
200
|
+
it "after_create not after_save" do
|
199
201
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
200
202
|
f.write <<-RUBY
|
201
203
|
metric "Sky is limit" do
|
@@ -213,25 +215,14 @@ context "ActiveRecord Metric" do
|
|
213
215
|
Sky.last.update_attributes :height=>4
|
214
216
|
end
|
215
217
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
RUBY
|
225
|
-
end
|
226
|
-
else
|
227
|
-
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
228
|
-
f.write <<-RUBY
|
229
|
-
metric "Sky is limit" do
|
230
|
-
model Sky, :conditions=>["height > 3"]
|
231
|
-
Sky.after_save { |sky| track! if sky.height_changed? && sky.height > 3 }
|
232
|
-
end
|
233
|
-
RUBY
|
234
|
-
end
|
218
|
+
it "with after_save" do
|
219
|
+
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
220
|
+
f.write <<-RUBY
|
221
|
+
metric "Sky is limit" do
|
222
|
+
model Sky, :conditions=>["height > 3"]
|
223
|
+
Sky.after_save { |sky| track!(:sky_is_limit) if sky.height_changed? && sky.height > 3 }
|
224
|
+
end
|
225
|
+
RUBY
|
235
226
|
end
|
236
227
|
Vanity.playground.metrics
|
237
228
|
times = 0
|
@@ -245,23 +236,13 @@ context "ActiveRecord Metric" do
|
|
245
236
|
assert_equal 2, times
|
246
237
|
end
|
247
238
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
RUBY
|
256
|
-
end
|
257
|
-
else
|
258
|
-
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
259
|
-
f.write <<-RUBY
|
260
|
-
metric "Sky is limit" do
|
261
|
-
Sky.after_save { |sky| track! if sky.height_changed? && sky.height > 3 }
|
262
|
-
end
|
263
|
-
RUBY
|
264
|
-
end
|
239
|
+
it "do it youself" do
|
240
|
+
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
241
|
+
f.write <<-RUBY
|
242
|
+
metric "Sky is limit" do
|
243
|
+
Sky.after_save { |sky| track!(:sky_is_limit) if sky.height_changed? && sky.height > 3 }
|
244
|
+
end
|
245
|
+
RUBY
|
265
246
|
end
|
266
247
|
Vanity.playground.metrics
|
267
248
|
Sky.create!
|
@@ -272,7 +253,7 @@ context "ActiveRecord Metric" do
|
|
272
253
|
assert_equal 3, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
273
254
|
end
|
274
255
|
|
275
|
-
|
256
|
+
it "last update for new metric" do
|
276
257
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
277
258
|
f.write <<-RUBY
|
278
259
|
metric "Sky is limit" do
|
@@ -283,7 +264,7 @@ context "ActiveRecord Metric" do
|
|
283
264
|
assert_nil metric(:sky_is_limit).last_update_at
|
284
265
|
end
|
285
266
|
|
286
|
-
|
267
|
+
it "last update with records" do
|
287
268
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
288
269
|
f.write <<-RUBY
|
289
270
|
metric "Sky is limit" do
|
@@ -298,16 +279,19 @@ context "ActiveRecord Metric" do
|
|
298
279
|
assert_in_delta metric(:sky_is_limit).last_update_at.to_i, (Time.now + 1.day).to_i, 1
|
299
280
|
end
|
300
281
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
Sky.after_save.clear
|
282
|
+
it "metric is specifiable with a string" do
|
283
|
+
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
284
|
+
f.write <<-RUBY
|
285
|
+
metric "Sky is limit" do
|
286
|
+
model 'Sky'
|
287
|
+
end
|
288
|
+
RUBY
|
309
289
|
end
|
290
|
+
Vanity.playground.metrics
|
291
|
+
Sky.create!
|
292
|
+
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
310
293
|
end
|
294
|
+
|
311
295
|
end
|
312
296
|
|
313
|
-
end
|
297
|
+
end
|
data/test/metric/base_test.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
require "
|
1
|
+
require "test_helper"
|
2
2
|
|
3
|
+
describe "Metric via playground" do
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
test "knows all loaded metrics" do
|
5
|
+
it "knows all loaded metrics" do
|
7
6
|
metric "Yawns/sec", "Cheers/sec"
|
8
7
|
assert Vanity.playground.metrics.keys.include?(:yawns_sec)
|
9
8
|
assert Vanity.playground.metrics.keys.include?(:cheers_sec)
|
10
9
|
end
|
11
10
|
|
12
|
-
|
11
|
+
it "loads metric definitions" do
|
13
12
|
File.open "tmp/experiments/metrics/yawns_sec.rb", "w" do |f|
|
14
13
|
f.write <<-RUBY
|
15
14
|
metric "Yawns/sec" do
|
@@ -22,7 +21,7 @@ context "Metric via playground" do
|
|
22
21
|
assert_equal "x", Vanity.playground.metric(:yawns_sec).xmts
|
23
22
|
end
|
24
23
|
|
25
|
-
|
24
|
+
it "bubbles up loaded metrics" do
|
26
25
|
File.open "tmp/experiments/metrics/yawns_sec.rb", "w" do |f|
|
27
26
|
f.write "fail 'yawn!'"
|
28
27
|
end
|
@@ -31,7 +30,7 @@ context "Metric via playground" do
|
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
34
|
-
|
33
|
+
it "map identifier from file name" do
|
35
34
|
File.open "tmp/experiments/metrics/yawns_sec.rb", "w" do |f|
|
36
35
|
f.write <<-RUBY
|
37
36
|
metric "yawns/hour" do
|
@@ -41,13 +40,13 @@ context "Metric via playground" do
|
|
41
40
|
assert Vanity.playground.metric(:yawns_sec)
|
42
41
|
end
|
43
42
|
|
44
|
-
|
43
|
+
it "fails tracking unknown metric" do
|
45
44
|
assert_raises NameError do
|
46
45
|
Vanity.playground.track! :yawns_sec
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
50
|
-
|
49
|
+
it "reloading metrics" do
|
51
50
|
metric "Yawns/sec", "Cheers/sec"
|
52
51
|
Vanity.playground.metric(:yawns_sec)
|
53
52
|
Vanity.playground.metric(:cheers_sec)
|
@@ -55,10 +54,10 @@ context "Metric via playground" do
|
|
55
54
|
metrics = Vanity.playground.metrics.values
|
56
55
|
Vanity.playground.reload!
|
57
56
|
assert_equal 0, Vanity.playground.metrics.size
|
58
|
-
|
57
|
+
refute_equal metrics, Vanity.playground.metrics.values
|
59
58
|
end
|
60
59
|
|
61
|
-
|
60
|
+
it "ignores undefined metrics in database" do
|
62
61
|
metric "Yawns/sec"
|
63
62
|
Vanity.playground.reload!
|
64
63
|
assert Vanity.playground.metrics.empty?
|
@@ -67,15 +66,15 @@ context "Metric via playground" do
|
|
67
66
|
end
|
68
67
|
|
69
68
|
|
70
|
-
|
71
|
-
|
69
|
+
describe "Metric tracking" do
|
70
|
+
it "disabled when metrics are disabled" do
|
72
71
|
not_collecting!
|
73
72
|
metric "Yawns/sec", "Cheers/sec"
|
74
73
|
Vanity.playground.track! :yawns_sec
|
75
74
|
Vanity.playground.track! :cheers_sec
|
76
75
|
end
|
77
76
|
|
78
|
-
|
77
|
+
it "can count" do
|
79
78
|
metric "Yawns/sec", "Cheers/sec"
|
80
79
|
4.times { Vanity.playground.track! :yawns_sec }
|
81
80
|
2.times { Vanity.playground.track! :cheers_sec }
|
@@ -84,7 +83,7 @@ context "Metric tracking" do
|
|
84
83
|
assert yawns == 2 * cheers
|
85
84
|
end
|
86
85
|
|
87
|
-
|
86
|
+
it "can tell the time" do
|
88
87
|
metric "Yawns/sec"
|
89
88
|
Timecop.freeze((today - 4).to_time) { 4.times { Vanity.playground.track! :yawns_sec } }
|
90
89
|
Timecop.freeze((today - 2).to_time) { 2.times { Vanity.playground.track! :yawns_sec } }
|
@@ -93,7 +92,7 @@ context "Metric tracking" do
|
|
93
92
|
assert_equal [0,4,0,2,0,1], boredom
|
94
93
|
end
|
95
94
|
|
96
|
-
|
95
|
+
it "with no value" do
|
97
96
|
metric "Yawns/sec", "Cheers/sec", "Looks"
|
98
97
|
Vanity.playground.track! :yawns_sec, 0
|
99
98
|
Vanity.playground.track! :cheers_sec
|
@@ -101,7 +100,7 @@ context "Metric tracking" do
|
|
101
100
|
assert_equal 1, Vanity.playground.metric(:cheers_sec).values(today, today).sum
|
102
101
|
end
|
103
102
|
|
104
|
-
|
103
|
+
it "with count" do
|
105
104
|
metric "Yawns/sec"
|
106
105
|
Timecop.freeze((today - 4).to_time) { Vanity.playground.track! :yawns_sec, 4 }
|
107
106
|
Timecop.freeze((today - 2).to_time) { Vanity.playground.track! :yawns_sec, 2 }
|
@@ -110,7 +109,7 @@ context "Metric tracking" do
|
|
110
109
|
assert_equal [0,4,0,2,0,1], boredom
|
111
110
|
end
|
112
111
|
|
113
|
-
|
112
|
+
it "runs hook" do
|
114
113
|
metric "Many Happy Returns"
|
115
114
|
total = 0
|
116
115
|
Vanity.playground.metric(:many_happy_returns).hook do |metric_id, timestamp, count|
|
@@ -122,7 +121,7 @@ context "Metric tracking" do
|
|
122
121
|
assert_equal 6, total
|
123
122
|
end
|
124
123
|
|
125
|
-
|
124
|
+
it "doesn't runs hook when metrics disabled" do
|
126
125
|
not_collecting!
|
127
126
|
metric "Many Happy Returns"
|
128
127
|
total = 0
|
@@ -133,7 +132,7 @@ context "Metric tracking" do
|
|
133
132
|
assert_equal 0, total
|
134
133
|
end
|
135
134
|
|
136
|
-
|
135
|
+
it "runs multiple hooks" do
|
137
136
|
metric "Many Happy Returns"
|
138
137
|
returns = 0
|
139
138
|
Vanity.playground.metric(:many_happy_returns).hook { returns += 1 }
|
@@ -143,7 +142,7 @@ context "Metric tracking" do
|
|
143
142
|
assert_equal 3, returns
|
144
143
|
end
|
145
144
|
|
146
|
-
|
145
|
+
it "destroy wipes metrics" do
|
147
146
|
metric "Many Happy Returns"
|
148
147
|
Vanity.playground.track! :many_happy_returns, 3
|
149
148
|
assert_equal [3], Vanity.playground.metric(:many_happy_returns).values(today, today)
|
@@ -153,8 +152,8 @@ context "Metric tracking" do
|
|
153
152
|
end
|
154
153
|
|
155
154
|
|
156
|
-
|
157
|
-
|
155
|
+
describe "Metric name" do
|
156
|
+
it "can be whatever" do
|
158
157
|
File.open "tmp/experiments/metrics/yawns_sec.rb", "w" do |f|
|
159
158
|
f.write <<-RUBY
|
160
159
|
metric "Yawns per second" do
|
@@ -166,8 +165,8 @@ context "Metric name" do
|
|
166
165
|
end
|
167
166
|
|
168
167
|
|
169
|
-
|
170
|
-
|
168
|
+
describe "Metric description" do
|
169
|
+
it "metric with description" do
|
171
170
|
File.open "tmp/experiments/metrics/yawns_sec.rb", "w" do |f|
|
172
171
|
f.write <<-RUBY
|
173
172
|
metric "Yawns/sec" do
|
@@ -178,7 +177,7 @@ context "Metric description" do
|
|
178
177
|
assert_equal "Am I that boring?", Vanity::Metric.description(Vanity.playground.metric(:yawns_sec))
|
179
178
|
end
|
180
179
|
|
181
|
-
|
180
|
+
it "metric without description" do
|
182
181
|
File.open "tmp/experiments/metrics/yawns_sec.rb", "w" do |f|
|
183
182
|
f.write <<-RUBY
|
184
183
|
metric "Yawns/sec" do
|
@@ -188,15 +187,15 @@ context "Metric description" do
|
|
188
187
|
assert_nil Vanity::Metric.description(Vanity.playground.metric(:yawns_sec))
|
189
188
|
end
|
190
189
|
|
191
|
-
|
190
|
+
it "metric with no method description" do
|
192
191
|
metric = Object.new
|
193
192
|
assert_nil Vanity::Metric.description(metric)
|
194
193
|
end
|
195
194
|
end
|
196
195
|
|
197
196
|
|
198
|
-
|
199
|
-
|
197
|
+
describe "Metric bounds" do
|
198
|
+
it "metric with bounds" do
|
200
199
|
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
|
201
200
|
f.write <<-RUBY
|
202
201
|
metric "Sky is limit" do
|
@@ -209,26 +208,26 @@ context "Metric bounds" do
|
|
209
208
|
assert_equal [6,12], Vanity::Metric.bounds(Vanity.playground.metric(:sky_is_limit))
|
210
209
|
end
|
211
210
|
|
212
|
-
|
211
|
+
it "metric without bounds" do
|
213
212
|
metric "Sky is limit"
|
214
213
|
assert_equal [nil, nil], Vanity::Metric.bounds(Vanity.playground.metric(:sky_is_limit))
|
215
214
|
end
|
216
215
|
|
217
|
-
|
216
|
+
it "metric with no method bounds" do
|
218
217
|
metric = Object.new
|
219
218
|
assert_equal [nil, nil], Vanity::Metric.bounds(metric)
|
220
219
|
end
|
221
220
|
end
|
222
221
|
|
223
222
|
|
224
|
-
|
225
|
-
|
223
|
+
describe "Metric last_update_at" do
|
224
|
+
it "for new metric" do
|
226
225
|
metric "Coolness"
|
227
226
|
metric = Vanity.playground.metric(:coolness)
|
228
227
|
assert_nil metric.last_update_at
|
229
228
|
end
|
230
229
|
|
231
|
-
|
230
|
+
it "with data point" do
|
232
231
|
metric "Coolness"
|
233
232
|
metric = Vanity.playground.metric(:coolness)
|
234
233
|
metric.track!
|
@@ -240,8 +239,8 @@ context "Metric last_update_at" do
|
|
240
239
|
end
|
241
240
|
|
242
241
|
|
243
|
-
|
244
|
-
|
242
|
+
describe "Metric data" do
|
243
|
+
it "explicit dates" do
|
245
244
|
metric "Yawns/sec"
|
246
245
|
Timecop.freeze((today - 4).to_time) { Vanity.playground.track! :yawns_sec, 4 }
|
247
246
|
Timecop.freeze((today - 2).to_time) { Vanity.playground.track! :yawns_sec, 2 }
|
@@ -250,7 +249,7 @@ context "Metric data" do
|
|
250
249
|
assert_equal [[today - 5, 0], [today - 4, 4], [today - 3, 0], [today - 2, 2], [today - 1, 0], [today, 1]], boredom
|
251
250
|
end
|
252
251
|
|
253
|
-
|
252
|
+
it "start date only" do
|
254
253
|
metric "Yawns/sec"
|
255
254
|
Timecop.freeze((today - 4).to_time) { Vanity.playground.track! :yawns_sec, 4 }
|
256
255
|
Timecop.freeze((today - 2).to_time) { Vanity.playground.track! :yawns_sec, 2 }
|
@@ -259,7 +258,7 @@ context "Metric data" do
|
|
259
258
|
assert_equal [[today - 4, 4], [today - 3, 0], [today - 2, 2], [today - 1, 0], [today, 1]], boredom
|
260
259
|
end
|
261
260
|
|
262
|
-
|
261
|
+
it "start date and duration" do
|
263
262
|
metric "Yawns/sec"
|
264
263
|
Timecop.freeze((today - 4).to_time) { Vanity.playground.track! :yawns_sec, 4 }
|
265
264
|
Timecop.freeze((today - 2).to_time) { Vanity.playground.track! :yawns_sec, 2 }
|
@@ -268,7 +267,7 @@ context "Metric data" do
|
|
268
267
|
assert_equal [[today - 4, 4], [today - 3, 0], [today - 2, 2], [today - 1, 0], [today, 1]], boredom
|
269
268
|
end
|
270
269
|
|
271
|
-
|
270
|
+
it "no data" do
|
272
271
|
metric "Yawns/sec"
|
273
272
|
boredom = Vanity::Metric.data(Vanity.playground.metric(:yawns_sec))
|
274
273
|
assert_equal 90, boredom.size
|
@@ -276,7 +275,7 @@ context "Metric data" do
|
|
276
275
|
assert_equal [today, 0], boredom.last
|
277
276
|
end
|
278
277
|
|
279
|
-
|
278
|
+
it "using custom values method" do
|
280
279
|
File.open "tmp/experiments/metrics/hours_in_day.rb", "w" do |f|
|
281
280
|
f.write <<-RUBY
|
282
281
|
metric "Hours in day" do
|
@@ -289,5 +288,4 @@ context "Metric data" do
|
|
289
288
|
data = Vanity::Metric.data(Vanity.playground.metric(:hours_in_day))
|
290
289
|
assert_equal [24] * 90, data.map(&:last)
|
291
290
|
end
|
292
|
-
|
293
291
|
end
|
@@ -1,9 +1,7 @@
|
|
1
|
-
require "
|
1
|
+
require "test_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
setup do
|
3
|
+
describe "Google Analytics" do
|
4
|
+
before do
|
7
5
|
File.open "tmp/experiments/metrics/ga.rb", "w" do |f|
|
8
6
|
f.write <<-RUBY
|
9
7
|
metric "GA" do
|
@@ -16,7 +14,7 @@ context "Google Analytics" do
|
|
16
14
|
GA_RESULT = Struct.new(:date, :pageviews, :visits)
|
17
15
|
GA_PROFILE = Struct.new(:web_property_id)
|
18
16
|
|
19
|
-
|
17
|
+
it "fail if Garb not available" do
|
20
18
|
File.open "tmp/experiments/metrics/ga.rb", "w" do |f|
|
21
19
|
f.write <<-RUBY
|
22
20
|
metric "GA" do
|
@@ -25,28 +23,28 @@ context "Google Analytics" do
|
|
25
23
|
end
|
26
24
|
RUBY
|
27
25
|
end
|
28
|
-
|
26
|
+
assert_raises LoadError do
|
29
27
|
Vanity.playground.metrics
|
30
28
|
end
|
31
29
|
end
|
32
30
|
|
33
|
-
|
31
|
+
it "constructs a report" do
|
34
32
|
Vanity.playground.metrics
|
35
33
|
assert metric(:ga).report
|
36
34
|
end
|
37
35
|
|
38
|
-
|
36
|
+
it "default to pageviews metric" do
|
39
37
|
Vanity.playground.metrics
|
40
38
|
assert_equal [:pageviews], metric(:ga).report.metrics.elements
|
41
39
|
end
|
42
40
|
|
43
|
-
|
41
|
+
it "apply data dimension and sort" do
|
44
42
|
Vanity.playground.metrics
|
45
43
|
assert_equal [:date], metric(:ga).report.dimensions.elements
|
46
44
|
assert_equal [:date], metric(:ga).report.sort.elements
|
47
45
|
end
|
48
46
|
|
49
|
-
|
47
|
+
it "accept other metrics" do
|
50
48
|
File.open "tmp/experiments/metrics/ga.rb", "w" do |f|
|
51
49
|
f.write <<-RUBY
|
52
50
|
metric "GA" do
|
@@ -58,14 +56,14 @@ context "Google Analytics" do
|
|
58
56
|
assert_equal [:visitors], metric(:ga).report.metrics.elements
|
59
57
|
end
|
60
58
|
|
61
|
-
|
59
|
+
it "does not support hooks" do
|
62
60
|
Vanity.playground.metrics
|
63
61
|
assert_raises RuntimeError do
|
64
62
|
metric(:ga).hook
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
68
|
-
|
66
|
+
it "should find matching profile" do
|
69
67
|
Vanity.playground.metrics
|
70
68
|
Garb::Profile.expects(:all).returns(Array.new(3) { |i| GA_PROFILE.new("UA#{i + 1}") })
|
71
69
|
metric(:ga).report.stubs(:send_request_for_body).returns(nil)
|
@@ -74,7 +72,7 @@ context "Google Analytics" do
|
|
74
72
|
assert_equal "UA2", metric(:ga).report.profile.web_property_id
|
75
73
|
end
|
76
74
|
|
77
|
-
|
75
|
+
it "should map results from report" do
|
78
76
|
Vanity.playground.metrics
|
79
77
|
today = Date.today
|
80
78
|
response = mock(:results=>Array.new(3) { |i| GA_RESULT.new("2010021#{i}", i + 1) })
|
@@ -84,7 +82,7 @@ context "Google Analytics" do
|
|
84
82
|
assert_equal [1,2,3], metric(:ga).values(Date.parse("2010-02-10"), Date.parse("2010-02-12"))
|
85
83
|
end
|
86
84
|
|
87
|
-
|
85
|
+
it "mapping GA metrics to single value" do
|
88
86
|
File.open "tmp/experiments/metrics/ga.rb", "w" do |f|
|
89
87
|
f.write <<-RUBY
|
90
88
|
metric "GA" do
|
@@ -100,5 +98,4 @@ context "Google Analytics" do
|
|
100
98
|
metric(:ga).report.stubs(:send_request_for_body).returns(nil)
|
101
99
|
assert_equal [1,4,9], metric(:ga).values(Date.parse("2010-02-10"), Date.parse("2010-02-12"))
|
102
100
|
end
|
103
|
-
|
104
101
|
end
|