vanity 3.1.0 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/linting.yml +28 -0
- data/.github/workflows/test.yml +3 -6
- data/.rubocop.yml +114 -0
- data/.rubocop_todo.yml +67 -0
- data/Appraisals +9 -31
- data/CHANGELOG +15 -0
- data/Gemfile +7 -3
- data/Gemfile.lock +35 -7
- data/README.md +4 -9
- data/Rakefile +25 -24
- data/bin/vanity +1 -1
- data/doc/configuring.textile +1 -0
- data/gemfiles/rails52.gemfile +6 -3
- data/gemfiles/rails52.gemfile.lock +36 -11
- data/gemfiles/rails60.gemfile +6 -3
- data/gemfiles/rails60.gemfile.lock +36 -11
- data/gemfiles/rails61.gemfile +6 -3
- data/gemfiles/rails61.gemfile.lock +36 -11
- data/lib/generators/vanity/migration_generator.rb +5 -7
- data/lib/vanity/adapters/abstract_adapter.rb +43 -45
- data/lib/vanity/adapters/active_record_adapter.rb +30 -30
- data/lib/vanity/adapters/mock_adapter.rb +14 -18
- data/lib/vanity/adapters/mongodb_adapter.rb +73 -69
- data/lib/vanity/adapters/redis_adapter.rb +26 -28
- data/lib/vanity/adapters.rb +1 -1
- data/lib/vanity/autoconnect.rb +6 -7
- data/lib/vanity/commands/list.rb +7 -7
- data/lib/vanity/commands/report.rb +18 -22
- data/lib/vanity/configuration.rb +19 -19
- data/lib/vanity/connection.rb +12 -14
- data/lib/vanity/experiment/ab_test.rb +82 -70
- data/lib/vanity/experiment/alternative.rb +3 -5
- data/lib/vanity/experiment/base.rb +24 -19
- data/lib/vanity/experiment/bayesian_bandit_score.rb +7 -13
- data/lib/vanity/experiment/definition.rb +6 -6
- data/lib/vanity/frameworks/rails.rb +39 -39
- data/lib/vanity/frameworks.rb +2 -2
- data/lib/vanity/helpers.rb +1 -1
- data/lib/vanity/metric/active_record.rb +21 -19
- data/lib/vanity/metric/base.rb +22 -23
- data/lib/vanity/metric/google_analytics.rb +6 -9
- data/lib/vanity/metric/remote.rb +3 -5
- data/lib/vanity/playground.rb +3 -6
- data/lib/vanity/vanity.rb +8 -12
- data/lib/vanity/version.rb +1 -1
- data/test/adapters/active_record_adapter_test.rb +1 -5
- data/test/adapters/mock_adapter_test.rb +0 -2
- data/test/adapters/mongodb_adapter_test.rb +1 -5
- data/test/adapters/redis_adapter_test.rb +3 -4
- data/test/adapters/shared_tests.rb +9 -12
- data/test/autoconnect_test.rb +3 -3
- data/test/cli_test.rb +0 -1
- data/test/configuration_test.rb +18 -34
- data/test/connection_test.rb +3 -3
- data/test/dummy/Rakefile +1 -1
- data/test/dummy/app/controllers/use_vanity_controller.rb +12 -8
- data/test/dummy/app/mailers/vanity_mailer.rb +3 -3
- data/test/dummy/config/application.rb +1 -1
- data/test/dummy/config/boot.rb +3 -3
- data/test/dummy/config/environment.rb +1 -1
- data/test/dummy/config/environments/development.rb +0 -1
- data/test/dummy/config/environments/test.rb +1 -1
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/dummy/config/initializers/vanity.rb +3 -0
- data/test/dummy/config/vanity.yml +7 -0
- data/test/dummy/config.ru +1 -1
- data/test/dummy/script/rails +2 -2
- data/test/experiment/ab_test.rb +148 -154
- data/test/experiment/base_test.rb +48 -32
- data/test/frameworks/rails/action_controller_test.rb +25 -25
- data/test/frameworks/rails/action_mailer_test.rb +2 -2
- data/test/frameworks/rails/action_view_test.rb +5 -6
- data/test/frameworks/rails/rails_test.rb +147 -181
- data/test/helper_test.rb +2 -2
- data/test/metric/active_record_test.rb +174 -212
- data/test/metric/base_test.rb +21 -46
- data/test/metric/google_analytics_test.rb +17 -25
- data/test/metric/remote_test.rb +7 -10
- data/test/playground_test.rb +7 -14
- data/test/templates_test.rb +16 -20
- data/test/test_helper.rb +28 -29
- data/test/vanity_test.rb +4 -10
- data/test/web/rails/dashboard_test.rb +21 -21
- data/vanity.gemspec +8 -7
- metadata +32 -30
- data/gemfiles/rails42.gemfile +0 -33
- data/gemfiles/rails42.gemfile.lock +0 -265
- data/gemfiles/rails42_protected_attributes.gemfile +0 -34
- data/gemfiles/rails42_protected_attributes.gemfile.lock +0 -264
- data/gemfiles/rails51.gemfile +0 -33
- data/gemfiles/rails51.gemfile.lock +0 -285
@@ -5,233 +5,209 @@ class User < ActiveRecord::Base
|
|
5
5
|
|
6
6
|
attr_accessible :height if defined?(ProtectedAttributes)
|
7
7
|
end
|
8
|
+
|
8
9
|
class Sky < ActiveRecord::Base
|
9
10
|
belongs_to :user
|
10
|
-
scope :high,
|
11
|
+
scope :high, -> { where("height >= 4") }
|
11
12
|
|
12
13
|
attr_accessible :height if defined?(ProtectedAttributes)
|
13
14
|
end
|
14
15
|
|
15
16
|
if ENV["DB"] == "active_record"
|
16
17
|
|
17
|
-
describe Vanity::Metric::ActiveRecord do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
describe Vanity::Metric::ActiveRecord do
|
19
|
+
before do
|
20
|
+
User.connection.create_table(:users) do |t|
|
21
|
+
t.timestamps
|
22
|
+
end
|
23
|
+
Sky.connection.create_table(:skies) do |t|
|
24
|
+
t.integer :user_id
|
25
|
+
t.integer :height
|
26
|
+
t.timestamps
|
27
|
+
end
|
27
28
|
end
|
28
|
-
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
after do
|
31
|
+
User.connection.drop_table(:users) if User.connection.table_exists?(User.table_name)
|
32
|
+
User.reset_callbacks(:create)
|
33
|
+
User.reset_callbacks(:save)
|
34
|
+
Sky.connection.drop_table(:skies) if Sky.connection.table_exists?(Sky.table_name)
|
35
|
+
Sky.reset_callbacks(:create)
|
36
|
+
Sky.reset_callbacks(:save)
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
f.write <<-RUBY
|
39
|
+
it "record count" do
|
40
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
42
41
|
metric "Sky is limit" do
|
43
42
|
model Sky
|
44
43
|
end
|
45
44
|
RUBY
|
45
|
+
Vanity.playground.metrics
|
46
|
+
Sky.create!
|
47
|
+
assert_equal 1, Sky.count
|
48
|
+
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
46
49
|
end
|
47
|
-
Vanity.playground.metrics
|
48
|
-
Sky.create!
|
49
|
-
assert_equal 1, Sky.count
|
50
|
-
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
51
|
-
end
|
52
50
|
|
53
|
-
|
54
|
-
|
55
|
-
f.write <<-RUBY
|
51
|
+
it "record sum" do
|
52
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
56
53
|
metric "Sky is limit" do
|
57
54
|
model Sky, :sum=>:height
|
58
55
|
end
|
59
56
|
RUBY
|
57
|
+
Vanity.playground.metrics
|
58
|
+
Sky.create! height: 4
|
59
|
+
Sky.create! height: 2
|
60
|
+
assert_equal 6, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
60
61
|
end
|
61
|
-
Vanity.playground.metrics
|
62
|
-
Sky.create! :height=>4
|
63
|
-
Sky.create! :height=>2
|
64
|
-
assert_equal 6, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
65
|
-
end
|
66
62
|
|
67
|
-
|
68
|
-
|
69
|
-
f.write <<-RUBY
|
63
|
+
it "record average" do
|
64
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
70
65
|
metric "Sky is limit" do
|
71
66
|
model Sky, :average=>:height
|
72
67
|
end
|
73
68
|
RUBY
|
69
|
+
Vanity.playground.metrics
|
70
|
+
Sky.create! height: 8
|
71
|
+
Sky.create! height: 2
|
72
|
+
assert_equal 5, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
74
73
|
end
|
75
|
-
Vanity.playground.metrics
|
76
|
-
Sky.create! :height=>8
|
77
|
-
Sky.create! :height=>2
|
78
|
-
assert_equal 5, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
79
|
-
end
|
80
74
|
|
81
|
-
|
82
|
-
|
83
|
-
f.write <<-RUBY
|
75
|
+
it "record minimum" do
|
76
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
84
77
|
metric "Sky is limit" do
|
85
78
|
model Sky, :minimum=>:height
|
86
79
|
end
|
87
80
|
RUBY
|
81
|
+
Vanity.playground.metrics
|
82
|
+
Sky.create! height: 4
|
83
|
+
Sky.create! height: 2
|
84
|
+
assert_equal 2, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
88
85
|
end
|
89
|
-
Vanity.playground.metrics
|
90
|
-
Sky.create! :height=>4
|
91
|
-
Sky.create! :height=>2
|
92
|
-
assert_equal 2, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
93
|
-
end
|
94
86
|
|
95
|
-
|
96
|
-
|
97
|
-
f.write <<-RUBY
|
87
|
+
it "record maximum" do
|
88
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
98
89
|
metric "Sky is limit" do
|
99
90
|
model Sky, :maximum=>:height
|
100
91
|
end
|
101
92
|
RUBY
|
93
|
+
Vanity.playground.metrics
|
94
|
+
Sky.create! height: 4
|
95
|
+
Sky.create! height: 2
|
96
|
+
assert_equal 4, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
102
97
|
end
|
103
|
-
Vanity.playground.metrics
|
104
|
-
Sky.create! :height=>4
|
105
|
-
Sky.create! :height=>2
|
106
|
-
assert_equal 4, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
107
|
-
end
|
108
98
|
|
109
|
-
|
110
|
-
|
111
|
-
f.write <<-RUBY
|
99
|
+
it "with conditions" do
|
100
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
112
101
|
metric "Sky is limit" do
|
113
102
|
model Sky, :sum=>:height, :conditions=>["height > 4"]
|
114
103
|
end
|
115
104
|
RUBY
|
105
|
+
Vanity.playground.metrics
|
106
|
+
high_skies = 0
|
107
|
+
metric(:sky_is_limit).hook do |_metric_id, _timestamp, height|
|
108
|
+
assert height > 4
|
109
|
+
high_skies += height
|
110
|
+
end
|
111
|
+
[nil, 5, 3, 6].each do |height|
|
112
|
+
Sky.create! height: height
|
113
|
+
end
|
114
|
+
assert_equal 11, Vanity::Metric.data(metric(:sky_is_limit)).sum(&:last)
|
115
|
+
assert_equal 11, high_skies
|
116
116
|
end
|
117
|
-
Vanity.playground.metrics
|
118
|
-
high_skies = 0
|
119
|
-
metric(:sky_is_limit).hook do |metric_id, timestamp, height|
|
120
|
-
assert height > 4
|
121
|
-
high_skies += height
|
122
|
-
end
|
123
|
-
[nil,5,3,6].each do |height|
|
124
|
-
Sky.create! :height=>height
|
125
|
-
end
|
126
|
-
assert_equal 11, Vanity::Metric.data(metric(:sky_is_limit)).sum(&:last)
|
127
|
-
assert_equal 11, high_skies
|
128
|
-
end
|
129
117
|
|
130
|
-
|
131
|
-
|
132
|
-
f.write <<-RUBY
|
118
|
+
it "with scope" do
|
119
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
133
120
|
metric "Sky is limit" do
|
134
121
|
model Sky.high
|
135
122
|
end
|
136
123
|
RUBY
|
124
|
+
Vanity.playground.metrics
|
125
|
+
total = 0
|
126
|
+
metric(:sky_is_limit).hook do |_metric_id, _timestamp, count|
|
127
|
+
total += count
|
128
|
+
end
|
129
|
+
Sky.create! height: 4
|
130
|
+
Sky.create! height: 2
|
131
|
+
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
132
|
+
assert_equal 1, total
|
137
133
|
end
|
138
|
-
Vanity.playground.metrics
|
139
|
-
total = 0
|
140
|
-
metric(:sky_is_limit).hook do |metric_id, timestamp, count|
|
141
|
-
total += count
|
142
|
-
end
|
143
|
-
Sky.create! :height=>4
|
144
|
-
Sky.create! :height=>2
|
145
|
-
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
146
|
-
assert_equal 1, total
|
147
|
-
end
|
148
134
|
|
149
|
-
|
150
|
-
|
151
|
-
f.write <<-RUBY
|
135
|
+
it "with timestamp" do
|
136
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
152
137
|
metric "Sky is limit" do
|
153
138
|
model Sky, :timestamp => :created_at
|
154
139
|
end
|
155
140
|
RUBY
|
141
|
+
Vanity.playground.metrics
|
142
|
+
Sky.create!
|
143
|
+
assert_equal 1, Sky.count
|
144
|
+
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
156
145
|
end
|
157
|
-
Vanity.playground.metrics
|
158
|
-
Sky.create!
|
159
|
-
assert_equal 1, Sky.count
|
160
|
-
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
161
|
-
end
|
162
146
|
|
163
|
-
|
164
|
-
|
165
|
-
f.write <<-RUBY
|
147
|
+
it "with timestamp and table" do
|
148
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
166
149
|
metric "Sky is limit" do
|
167
150
|
model Sky, :timestamp => 'skies.created_at'
|
168
151
|
end
|
169
152
|
RUBY
|
153
|
+
Vanity.playground.metrics
|
154
|
+
Sky.create!
|
155
|
+
assert_equal 1, Sky.count
|
156
|
+
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
170
157
|
end
|
171
|
-
Vanity.playground.metrics
|
172
|
-
Sky.create!
|
173
|
-
assert_equal 1, Sky.count
|
174
|
-
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
175
|
-
end
|
176
158
|
|
177
|
-
|
178
|
-
|
179
|
-
f.write <<-RUBY
|
159
|
+
it "hooks" do
|
160
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
180
161
|
metric "Sky is limit" do
|
181
162
|
model Sky, :sum=>:height
|
182
163
|
end
|
183
164
|
RUBY
|
165
|
+
Vanity.playground.metrics
|
166
|
+
total = 0
|
167
|
+
metric(:sky_is_limit).hook do |metric_id, timestamp, count|
|
168
|
+
assert_equal :sky_is_limit, metric_id
|
169
|
+
assert_in_delta Time.now.to_i, timestamp.to_i, 1
|
170
|
+
total += count
|
171
|
+
end
|
172
|
+
Sky.create! height: 4
|
173
|
+
assert_equal 4, total
|
184
174
|
end
|
185
|
-
Vanity.playground.metrics
|
186
|
-
total = 0
|
187
|
-
metric(:sky_is_limit).hook do |metric_id, timestamp, count|
|
188
|
-
assert_equal :sky_is_limit, metric_id
|
189
|
-
assert_in_delta Time.now.to_i, timestamp.to_i, 1
|
190
|
-
total += count
|
191
|
-
end
|
192
|
-
Sky.create! :height=>4
|
193
|
-
assert_equal 4, total
|
194
|
-
end
|
195
175
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
f.write <<-RUBY
|
176
|
+
it "no hooks when metrics disabled" do
|
177
|
+
not_collecting!
|
178
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
200
179
|
metric "Sky is limit" do
|
201
180
|
model Sky, :sum=>:height
|
202
181
|
end
|
203
182
|
RUBY
|
183
|
+
Vanity.playground.metrics
|
184
|
+
total = 0
|
185
|
+
metric(:sky_is_limit).hook do |_metric_id, _timestamp, count|
|
186
|
+
total += count
|
187
|
+
end
|
188
|
+
Sky.create! height: 4
|
189
|
+
assert_equal 0, total
|
204
190
|
end
|
205
|
-
Vanity.playground.metrics
|
206
|
-
total = 0
|
207
|
-
metric(:sky_is_limit).hook do |metric_id, timestamp, count|
|
208
|
-
total += count
|
209
|
-
end
|
210
|
-
Sky.create! :height=>4
|
211
|
-
assert_equal 0, total
|
212
|
-
end
|
213
191
|
|
214
|
-
|
215
|
-
|
216
|
-
f.write <<-RUBY
|
192
|
+
it "after_create not after_save" do
|
193
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
217
194
|
metric "Sky is limit" do
|
218
195
|
model Sky
|
219
196
|
end
|
220
197
|
RUBY
|
198
|
+
Vanity.playground.metrics
|
199
|
+
once = nil
|
200
|
+
metric(:sky_is_limit).hook do
|
201
|
+
raise "Metric tracked twice" if once
|
202
|
+
|
203
|
+
once = true
|
204
|
+
end
|
205
|
+
Sky.create!
|
206
|
+
Sky.last.update_attributes height: 4
|
221
207
|
end
|
222
|
-
Vanity.playground.metrics
|
223
|
-
once = nil
|
224
|
-
metric(:sky_is_limit).hook do
|
225
|
-
fail "Metric tracked twice" if once
|
226
|
-
once = true
|
227
|
-
end
|
228
|
-
Sky.create!
|
229
|
-
Sky.last.update_attributes :height=>4
|
230
|
-
end
|
231
208
|
|
232
|
-
|
233
|
-
|
234
|
-
f.write <<-RUBY
|
209
|
+
it "with after_save" do
|
210
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
235
211
|
metric "Sky is limit" do
|
236
212
|
model Sky, :conditions=>["height > 3"]
|
237
213
|
Sky.after_save do |sky|
|
@@ -243,116 +219,102 @@ describe Vanity::Metric::ActiveRecord do
|
|
243
219
|
end
|
244
220
|
end
|
245
221
|
RUBY
|
222
|
+
Vanity.playground.metrics
|
223
|
+
times = 0
|
224
|
+
metric(:sky_is_limit).hook do
|
225
|
+
times += 1
|
226
|
+
end
|
227
|
+
Sky.create!
|
228
|
+
(1..5).each do |height|
|
229
|
+
Sky.last.update_attributes! height: height
|
230
|
+
end
|
231
|
+
assert_equal 2, times
|
246
232
|
end
|
247
|
-
Vanity.playground.metrics
|
248
|
-
times = 0
|
249
|
-
metric(:sky_is_limit).hook do
|
250
|
-
times += 1
|
251
|
-
end
|
252
|
-
Sky.create!
|
253
|
-
(1..5).each do |height|
|
254
|
-
Sky.last.update_attributes! :height=>height
|
255
|
-
end
|
256
|
-
assert_equal 2, times
|
257
|
-
end
|
258
233
|
|
259
|
-
|
260
|
-
|
261
|
-
f.write <<-RUBY
|
234
|
+
it "with model identity" do
|
235
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
262
236
|
metric "Sky is limit" do
|
263
237
|
model Sky, :identity => lambda { |record| record.user_id }
|
264
238
|
end
|
265
239
|
RUBY
|
266
|
-
end
|
267
240
|
|
268
|
-
|
269
|
-
f.write <<-RUBY
|
241
|
+
File.write("tmp/experiments/simple.rb", <<-RUBY)
|
270
242
|
ab_test "simple" do
|
271
243
|
metrics :sky_is_limit
|
272
244
|
alternatives :a, :b
|
273
245
|
identity { "me" }
|
274
246
|
end
|
275
247
|
RUBY
|
276
|
-
end
|
277
248
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
249
|
+
user = User.create
|
250
|
+
Vanity.context = stub(vanity_identity: user.id)
|
251
|
+
experiment = Vanity.playground.experiment(:simple)
|
252
|
+
experiment.choose
|
282
253
|
|
283
|
-
|
284
|
-
|
285
|
-
|
254
|
+
Vanity.context = nil
|
255
|
+
# Should count as a conversion for the user in the experiment.
|
256
|
+
user.skies.create
|
286
257
|
|
287
|
-
|
288
|
-
|
258
|
+
# Should count as a conversion for the newly created User.
|
259
|
+
User.create.skies.create
|
289
260
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
261
|
+
Vanity.context = stub(vanity_identity: "other")
|
262
|
+
experiment.choose
|
263
|
+
# Should count as a conversion for "other"
|
264
|
+
Sky.create
|
294
265
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
266
|
+
assert_equal 3, Sky.count
|
267
|
+
assert_equal 2, experiment.alternatives.map(&:participants).sum
|
268
|
+
assert_equal 3, experiment.alternatives.map(&:conversions).sum
|
269
|
+
end
|
299
270
|
|
300
|
-
|
301
|
-
|
302
|
-
f.write <<-RUBY
|
271
|
+
it "do it yourself" do
|
272
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
303
273
|
metric "Sky is limit" do
|
304
274
|
Sky.after_save { |sky| Vanity.track!(:sky_is_limit) if sky.height && sky.height > 3 }
|
305
275
|
end
|
306
276
|
RUBY
|
277
|
+
Vanity.playground.metrics
|
278
|
+
Sky.create!
|
279
|
+
(1..5).each do |height|
|
280
|
+
Sky.create! height: height
|
281
|
+
end
|
282
|
+
Sky.first.update_attributes! height: 4
|
283
|
+
assert_equal 3, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
307
284
|
end
|
308
|
-
Vanity.playground.metrics
|
309
|
-
Sky.create!
|
310
|
-
(1..5).each do |height|
|
311
|
-
Sky.create! :height=>height
|
312
|
-
end
|
313
|
-
Sky.first.update_attributes! :height=>4
|
314
|
-
assert_equal 3, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
315
|
-
end
|
316
285
|
|
317
|
-
|
318
|
-
|
319
|
-
f.write <<-RUBY
|
286
|
+
it "last update for new metric" do
|
287
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
320
288
|
metric "Sky is limit" do
|
321
289
|
model Sky
|
322
290
|
end
|
323
291
|
RUBY
|
292
|
+
assert_nil metric(:sky_is_limit).last_update_at
|
324
293
|
end
|
325
|
-
assert_nil metric(:sky_is_limit).last_update_at
|
326
|
-
end
|
327
294
|
|
328
|
-
|
329
|
-
|
330
|
-
f.write <<-RUBY
|
295
|
+
it "last update with records" do
|
296
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
331
297
|
metric "Sky is limit" do
|
332
298
|
model Sky
|
333
299
|
end
|
334
300
|
RUBY
|
301
|
+
Sky.create! height: 1
|
302
|
+
Timecop.freeze Time.now + 1.day do
|
303
|
+
Sky.create! height: 1
|
304
|
+
end
|
305
|
+
assert_in_delta metric(:sky_is_limit).last_update_at.to_i, (Time.now + 1.day).to_i, 1
|
335
306
|
end
|
336
|
-
Sky.create! :height=>1
|
337
|
-
Timecop.freeze Time.now + 1.day do
|
338
|
-
Sky.create! :height=>1
|
339
|
-
end
|
340
|
-
assert_in_delta metric(:sky_is_limit).last_update_at.to_i, (Time.now + 1.day).to_i, 1
|
341
|
-
end
|
342
307
|
|
343
|
-
|
344
|
-
|
345
|
-
f.write <<-RUBY
|
308
|
+
it "metric is specifiable with a string" do
|
309
|
+
File.write("tmp/experiments/metrics/sky_is_limit.rb", <<-RUBY)
|
346
310
|
metric "Sky is limit" do
|
347
311
|
model 'Sky'
|
348
312
|
end
|
349
313
|
RUBY
|
314
|
+
Vanity.playground.metrics
|
315
|
+
Sky.create!
|
316
|
+
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
350
317
|
end
|
351
|
-
Vanity.playground.metrics
|
352
|
-
Sky.create!
|
353
|
-
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
|
354
318
|
end
|
355
319
|
|
356
320
|
end
|
357
|
-
|
358
|
-
end
|