vanity 1.6.1 → 1.7.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.
Files changed (49) hide show
  1. data/CHANGELOG +28 -0
  2. data/Gemfile +1 -0
  3. data/README.rdoc +10 -3
  4. data/Rakefile +3 -3
  5. data/bin/b2json +16 -0
  6. data/bin/convert_to_should_syntax +16 -0
  7. data/bin/dw +16 -0
  8. data/bin/j2bson +16 -0
  9. data/bin/jekyll +16 -0
  10. data/bin/kramdown +16 -0
  11. data/bin/maruku +16 -0
  12. data/bin/marutex +16 -0
  13. data/bin/mongo_console +16 -0
  14. data/bin/passenger-config +16 -0
  15. data/bin/passenger-install-apache2-module +16 -0
  16. data/bin/passenger-install-nginx-module +16 -0
  17. data/bin/passenger-make-enterprisey +16 -0
  18. data/bin/passenger-memory-stats +16 -0
  19. data/bin/passenger-spawn-server +16 -0
  20. data/bin/passenger-status +16 -0
  21. data/bin/passenger-stress-test +16 -0
  22. data/bin/posix-spawn-benchmark +16 -0
  23. data/bin/rackup +16 -0
  24. data/bin/rails +16 -0
  25. data/bin/rake +16 -0
  26. data/bin/redcloth +16 -0
  27. data/bin/vanity +12 -65
  28. data/bin/yard +16 -0
  29. data/bin/yardoc +16 -0
  30. data/bin/yri +16 -0
  31. data/lib/generators/templates/vanity_migration.rb +53 -0
  32. data/lib/generators/vanity_generator.rb +15 -0
  33. data/lib/vanity/adapters/abstract_adapter.rb +5 -0
  34. data/lib/vanity/adapters/active_record_adapter.rb +10 -69
  35. data/lib/vanity/adapters/redis_adapter.rb +1 -1
  36. data/lib/vanity/frameworks/rails.rb +68 -7
  37. data/lib/vanity/images/x.gif +0 -0
  38. data/lib/vanity/playground.rb +0 -5
  39. data/lib/vanity/templates/vanity.css +1 -1
  40. data/lib/vanity/version.rb +1 -1
  41. data/test/adapters/redis_adapter_test.rb +1 -1
  42. data/test/experiment/ab_test.rb +0 -1
  43. data/test/myapp/log/production.log +522 -0
  44. data/test/myapp/log/test.log +304 -0
  45. data/test/passenger_test.rb +1 -1
  46. data/test/rails_helper_test.rb +8 -0
  47. data/test/rails_test.rb +23 -13
  48. data/test/test_helper.rb +23 -11
  49. metadata +40 -10
@@ -0,0 +1,304 @@
1
+ Processing by VanityController#add_participant as JS
2
+ Completed 404 Not Found in 253ms (Views: 252.4ms)
3
+ Processing by VanityController#chooses as JS
4
+ Parameters: {"e"=>"food", "a"=>0}
5
+ Completed 200 OK in 355ms (Views: 354.4ms)
6
+ Processing by VanityController#add_participant as JS
7
+ Parameters: {"e"=>"food", "a"=>0}
8
+ Rendered text template (0.0ms)
9
+ Completed 200 OK in 9ms (Views: 8.1ms | ActiveRecord: 0.0ms)
10
+ Processing by VanityController#add_participant as JS
11
+ Completed 404 Not Found in 0ms (Views: 0.3ms | ActiveRecord: 0.0ms)
12
+ Processing by VanityController#chooses as JS
13
+ Parameters: {"e"=>"food", "a"=>0}
14
+ Completed 200 OK in 16ms (Views: 14.7ms | ActiveRecord: 0.0ms)
15
+ Processing by VanityController#add_participant as JS
16
+ Parameters: {"e"=>"food", "a"=>0}
17
+ Rendered text template (0.0ms)
18
+ Completed 200 OK in 15ms (Views: 8.9ms | ActiveRecord: 0.0ms)
19
+ Processing by VanityController#add_participant as JS
20
+ Completed 404 Not Found in 0ms (Views: 0.3ms | ActiveRecord: 0.0ms)
21
+ Processing by VanityController#chooses as JS
22
+ Parameters: {"e"=>"food", "a"=>0}
23
+ Completed 200 OK in 26ms (Views: 25.3ms | ActiveRecord: 0.0ms)
24
+ Processing by UseVanityController#index as HTML
25
+ Completed 500 Internal Server Error in 18ms
26
+ Processing by UseVanityController#index as HTML
27
+ Completed 500 Internal Server Error in 1ms
28
+ Processing by UseVanityController#index as HTML
29
+ Parameters: {"foo"=>"bar", "_vanity"=>"aae9ff8081"}
30
+ Completed 500 Internal Server Error in 2ms
31
+ Processing by UseVanityController#index as HTML
32
+ Parameters: {"foo"=>"bar", "_vanity"=>"567"}
33
+ Redirected to http://test.host/use_vanity?foo=bar
34
+ Completed 302 Found in 2ms
35
+ Processing by UseVanityController#index as HTML
36
+ Parameters: {"_vanity"=>"aae9ff8081"}
37
+ Redirected to http://test.host/use_vanity
38
+ Completed 302 Found in 1ms
39
+ Processing by UseVanityController#index as HTML
40
+ Parameters: {"_identity"=>"123", "_track"=>"sugar_high"}
41
+ Completed 500 Internal Server Error in 1ms
42
+ Processing by UseVanityController#index as HTML
43
+ Completed 500 Internal Server Error in 0ms
44
+ Processing by UseVanityController#index as HTML
45
+ Completed 500 Internal Server Error in 2ms
46
+ Processing by UseVanityController#index as HTML
47
+ Completed 500 Internal Server Error in 0ms
48
+ Processing by UseVanityController#index as HTML
49
+ Completed 500 Internal Server Error in 0ms
50
+ Processing by UseVanityController#index as HTML
51
+ Completed 500 Internal Server Error in 1ms
52
+ Processing by UseVanityController#index as HTML
53
+ Completed 500 Internal Server Error in 0ms
54
+ Processing by UseVanityController#index as HTML
55
+ Parameters: {"_identity"=>"id_from_params"}
56
+ Completed 500 Internal Server Error in 0ms
57
+ Processing by UseVanityController#index as HTML
58
+ Completed 500 Internal Server Error in 0ms
59
+ Processing by UseVanityController#index as HTML
60
+ Completed 500 Internal Server Error in 2ms
61
+ Processing by UseVanityController#index as HTML
62
+ Completed 500 Internal Server Error in 0ms
63
+ Processing by UseVanityController#index as HTML
64
+ Parameters: {"foo"=>"bar", "_vanity"=>"aae9ff8081"}
65
+ Completed 500 Internal Server Error in 0ms
66
+ Processing by UseVanityController#index as HTML
67
+ Parameters: {"foo"=>"bar", "_vanity"=>"567"}
68
+ Redirected to http://test.host/use_vanity?foo=bar
69
+ Completed 302 Found in 1ms
70
+ Processing by UseVanityController#index as HTML
71
+ Parameters: {"_vanity"=>"aae9ff8081"}
72
+ Redirected to http://test.host/use_vanity
73
+ Completed 302 Found in 1ms
74
+ Processing by UseVanityController#index as HTML
75
+ Parameters: {"_identity"=>"123", "_track"=>"sugar_high"}
76
+ Completed 500 Internal Server Error in 0ms
77
+ Processing by UseVanityController#index as HTML
78
+ Completed 500 Internal Server Error in 0ms
79
+ Processing by UseVanityController#index as HTML
80
+ Completed 500 Internal Server Error in 0ms
81
+ Processing by UseVanityController#index as HTML
82
+ Completed 500 Internal Server Error in 0ms
83
+ Processing by UseVanityController#index as HTML
84
+ Completed 500 Internal Server Error in 0ms
85
+ Processing by UseVanityController#index as HTML
86
+ Completed 500 Internal Server Error in 0ms
87
+ Processing by UseVanityController#index as HTML
88
+ Completed 500 Internal Server Error in 0ms
89
+ Processing by UseVanityController#index as HTML
90
+ Parameters: {"_identity"=>"id_from_params"}
91
+ Completed 500 Internal Server Error in 0ms
92
+ Processing by UseVanityController#index as HTML
93
+ Completed 500 Internal Server Error in 0ms
94
+ Processing by UseVanityController#index as HTML
95
+ Completed 500 Internal Server Error in 3ms
96
+ Processing by UseVanityController#index as HTML
97
+ Completed 500 Internal Server Error in 1ms
98
+ Processing by UseVanityController#index as HTML
99
+ Completed 500 Internal Server Error in 6ms
100
+ Processing by UseVanityController#index as HTML
101
+ Completed 500 Internal Server Error in 1ms
102
+ Processing by UseVanityController#index as HTML
103
+ Completed 500 Internal Server Error in 2ms
104
+ Processing by UseVanityController#index as HTML
105
+ Completed 500 Internal Server Error in 5ms
106
+ Processing by UseVanityController#index as HTML
107
+ Completed 500 Internal Server Error in 1ms
108
+ Processing by UseVanityController#index as HTML
109
+ Completed 500 Internal Server Error in 1ms
110
+ Processing by UseVanityController#index as HTML
111
+ Completed 500 Internal Server Error in 1ms
112
+ Processing by UseVanityController#index as HTML
113
+ Completed 500 Internal Server Error in 1ms
114
+ Processing by UseVanityController#index as HTML
115
+ Completed 500 Internal Server Error in 1ms
116
+ Processing by UseVanityController#index as HTML
117
+ Completed 500 Internal Server Error in 1ms
118
+ Processing by UseVanityController#index as HTML
119
+ Completed 500 Internal Server Error in 1ms
120
+ Processing by UseVanityController#index as HTML
121
+ Completed 500 Internal Server Error in 1ms
122
+ Processing by UseVanityController#index as HTML
123
+ Completed 500 Internal Server Error in 1ms
124
+ Processing by UseVanityController#index as HTML
125
+ Completed 500 Internal Server Error in 2ms
126
+ Processing by UseVanityController#index as HTML
127
+ Completed 500 Internal Server Error in 1ms
128
+ Processing by UseVanityController#index as HTML
129
+ Completed 500 Internal Server Error in 1ms
130
+ Processing by UseVanityController#index as HTML
131
+ Completed 500 Internal Server Error in 1ms
132
+ Processing by UseVanityController#index as HTML
133
+ Completed 500 Internal Server Error in 1ms
134
+ Processing by UseVanityController#index as HTML
135
+ Completed 500 Internal Server Error in 3ms
136
+ Processing by AbTestController#test_render as HTML
137
+ Completed 500 Internal Server Error in 12ms
138
+ Processing by AbTestController#test_view as HTML
139
+ Completed 500 Internal Server Error in 36ms
140
+ Processing by AbTestController#track as HTML
141
+ Completed 500 Internal Server Error in 1ms
142
+ Processing by AbTestController#test_capture as HTML
143
+ Completed 500 Internal Server Error in 2ms
144
+ Processing by AbTestController#test_render as HTML
145
+ Completed 500 Internal Server Error in 1ms
146
+ Processing by AbTestController#test_render as HTML
147
+ Completed 500 Internal Server Error in 0ms
148
+ Processing by AbTestController#test_render as HTML
149
+ Completed 500 Internal Server Error in 0ms
150
+ Processing by VanityController#add_participant as JS
151
+ Parameters: {"e"=>"food", "a"=>0}
152
+ Completed 200 OK in 36ms (Views: 34.6ms | ActiveRecord: 0.0ms)
153
+ Processing by VanityController#add_participant as JS
154
+ Completed 404 Not Found in 1ms (Views: 0.5ms | ActiveRecord: 0.0ms)
155
+ Processing by VanityController#chooses as JS
156
+ Parameters: {"e"=>"food", "a"=>0}
157
+ Completed 200 OK in 139ms (Views: 136.6ms | ActiveRecord: 0.0ms)
158
+ Processing by UseVanityController#index as HTML
159
+ Completed 500 Internal Server Error in 1ms
160
+ Processing by UseVanityController#index as HTML
161
+ Completed 500 Internal Server Error in 0ms
162
+ Processing by UseVanityController#index as HTML
163
+ Parameters: {"foo"=>"bar", "_vanity"=>"aae9ff8081"}
164
+ Completed 500 Internal Server Error in 0ms
165
+ Processing by UseVanityController#index as HTML
166
+ Parameters: {"foo"=>"bar", "_vanity"=>"567"}
167
+ Redirected to http://test.host/use_vanity?foo=bar
168
+ Completed 302 Found in 1ms
169
+ Processing by UseVanityController#index as HTML
170
+ Parameters: {"_vanity"=>"aae9ff8081"}
171
+ Redirected to http://test.host/use_vanity
172
+ Completed 302 Found in 1ms
173
+ Processing by UseVanityController#index as HTML
174
+ Parameters: {"_identity"=>"123", "_track"=>"sugar_high"}
175
+ Completed 500 Internal Server Error in 1ms
176
+ Processing by UseVanityController#index as HTML
177
+ Completed 500 Internal Server Error in 0ms
178
+ Processing by UseVanityController#index as HTML
179
+ Completed 500 Internal Server Error in 0ms
180
+ Processing by UseVanityController#index as HTML
181
+ Completed 500 Internal Server Error in 0ms
182
+ Processing by UseVanityController#index as HTML
183
+ Completed 500 Internal Server Error in 0ms
184
+ Processing by UseVanityController#index as HTML
185
+ Completed 500 Internal Server Error in 0ms
186
+ Processing by UseVanityController#index as HTML
187
+ Completed 500 Internal Server Error in 0ms
188
+ Processing by UseVanityController#index as HTML
189
+ Parameters: {"_identity"=>"id_from_params"}
190
+ Completed 500 Internal Server Error in 0ms
191
+ Processing by UseVanityController#index as HTML
192
+ Completed 500 Internal Server Error in 0ms
193
+ Processing by AbTestController#test_render as HTML
194
+ Completed 500 Internal Server Error in 1ms
195
+ Processing by AbTestController#test_view as HTML
196
+ Completed 500 Internal Server Error in 28ms
197
+ Processing by AbTestController#track as HTML
198
+ Completed 500 Internal Server Error in 1ms
199
+ Processing by AbTestController#test_capture as HTML
200
+ Completed 500 Internal Server Error in 2ms
201
+ Processing by AbTestController#test_render as HTML
202
+ Completed 500 Internal Server Error in 0ms
203
+ Processing by AbTestController#test_render as HTML
204
+ Completed 500 Internal Server Error in 0ms
205
+ Processing by AbTestController#test_render as HTML
206
+ Completed 500 Internal Server Error in 0ms
207
+ Processing by VanityController#add_participant as JS
208
+ Parameters: {"e"=>"food", "a"=>0}
209
+ Completed 200 OK in 33ms (Views: 31.5ms | ActiveRecord: 0.0ms)
210
+ Processing by VanityController#add_participant as JS
211
+ Completed 404 Not Found in 1ms (Views: 0.4ms | ActiveRecord: 0.0ms)
212
+ Processing by VanityController#chooses as JS
213
+ Parameters: {"e"=>"food", "a"=>0}
214
+ Completed 200 OK in 17ms (Views: 15.3ms | ActiveRecord: 0.0ms)
215
+ Processing by UseVanityController#index as HTML
216
+ Completed 500 Internal Server Error in 1ms
217
+ Processing by UseVanityController#index as HTML
218
+ Completed 500 Internal Server Error in 0ms
219
+ Processing by UseVanityController#index as HTML
220
+ Parameters: {"foo"=>"bar", "_vanity"=>"aae9ff8081"}
221
+ Completed 500 Internal Server Error in 0ms
222
+ Processing by UseVanityController#index as HTML
223
+ Parameters: {"foo"=>"bar", "_vanity"=>"567"}
224
+ Redirected to http://test.host/use_vanity?foo=bar
225
+ Completed 302 Found in 1ms
226
+ Processing by UseVanityController#index as HTML
227
+ Parameters: {"_vanity"=>"aae9ff8081"}
228
+ Redirected to http://test.host/use_vanity
229
+ Completed 302 Found in 1ms
230
+ Processing by UseVanityController#index as HTML
231
+ Parameters: {"_identity"=>"123", "_track"=>"sugar_high"}
232
+ Completed 500 Internal Server Error in 1ms
233
+ Processing by UseVanityController#index as HTML
234
+ Completed 500 Internal Server Error in 0ms
235
+ Processing by UseVanityController#index as HTML
236
+ Completed 500 Internal Server Error in 0ms
237
+ Processing by UseVanityController#index as HTML
238
+ Completed 500 Internal Server Error in 0ms
239
+ Processing by UseVanityController#index as HTML
240
+ Completed 500 Internal Server Error in 0ms
241
+ Processing by UseVanityController#index as HTML
242
+ Completed 500 Internal Server Error in 1ms
243
+ Processing by UseVanityController#index as HTML
244
+ Completed 500 Internal Server Error in 0ms
245
+ Processing by UseVanityController#index as HTML
246
+ Parameters: {"_identity"=>"id_from_params"}
247
+ Completed 500 Internal Server Error in 0ms
248
+ Processing by UseVanityController#index as HTML
249
+ Completed 500 Internal Server Error in 0ms
250
+ Processing by AbTestController#test_render as HTML
251
+ Completed 500 Internal Server Error in 1ms
252
+ Processing by AbTestController#test_view as HTML
253
+ Completed 500 Internal Server Error in 30ms
254
+ Processing by AbTestController#track as HTML
255
+ Completed 500 Internal Server Error in 1ms
256
+ Processing by AbTestController#test_capture as HTML
257
+ Completed 500 Internal Server Error in 3ms
258
+ Processing by AbTestController#test_render as HTML
259
+ Completed 500 Internal Server Error in 0ms
260
+ Processing by AbTestController#test_render as HTML
261
+ Completed 500 Internal Server Error in 0ms
262
+ Processing by AbTestController#test_render as HTML
263
+ Completed 500 Internal Server Error in 0ms
264
+ Processing by VanityController#add_participant as JS
265
+ Parameters: {"e"=>"food", "a"=>0}
266
+ Completed 200 OK in 13ms (Views: 11.6ms | ActiveRecord: 0.0ms)
267
+ Processing by VanityController#add_participant as JS
268
+ Completed 404 Not Found in 1ms (Views: 0.4ms | ActiveRecord: 0.0ms)
269
+ Processing by VanityController#chooses as JS
270
+ Parameters: {"e"=>"food", "a"=>0}
271
+ Completed 200 OK in 16ms (Views: 15.0ms | ActiveRecord: 0.0ms)
272
+ Processing by UseVanityController#index as HTML
273
+ Completed 500 Internal Server Error in 1ms
274
+ Processing by UseVanityController#index as HTML
275
+ Completed 500 Internal Server Error in 1ms
276
+ Processing by UseVanityController#index as HTML
277
+ Parameters: {"foo"=>"bar", "_vanity"=>"aae9ff8081"}
278
+ Completed 500 Internal Server Error in 0ms
279
+ Processing by UseVanityController#index as HTML
280
+ Parameters: {"foo"=>"bar", "_vanity"=>"567"}
281
+ Redirected to http://test.host/use_vanity?foo=bar
282
+ Completed 302 Found in 1ms
283
+ Processing by UseVanityController#index as HTML
284
+ Parameters: {"_vanity"=>"aae9ff8081"}
285
+ Redirected to http://test.host/use_vanity
286
+ Completed 302 Found in 1ms
287
+ Processing by UseVanityController#index as HTML
288
+ Parameters: {"_identity"=>"123", "_track"=>"sugar_high"}
289
+ Completed 500 Internal Server Error in 0ms
290
+ Processing by UseVanityController#index as HTML
291
+ Completed 500 Internal Server Error in 0ms
292
+ Processing by UseVanityController#index as HTML
293
+ Completed 500 Internal Server Error in 0ms
294
+ Processing by UseVanityController#index as HTML
295
+ Completed 500 Internal Server Error in 0ms
296
+ Processing by UseVanityController#index as HTML
297
+ Completed 500 Internal Server Error in 0ms
298
+ Processing by UseVanityController#index as HTML
299
+ Completed 500 Internal Server Error in 0ms
300
+ Processing by UseVanityController#index as HTML
301
+ Parameters: {"_identity"=>"id_from_params"}
302
+ Completed 500 Internal Server Error in 0ms
303
+ Processing by UseVanityController#index as HTML
304
+ Completed 500 Internal Server Error in 0ms
@@ -8,7 +8,7 @@ class PassengerTest < Test::Unit::TestCase
8
8
  @original = Vanity.playground.connection
9
9
  File.unlink "test/myapp/config/vanity.yml" rescue nil
10
10
  File.open("test/myapp/config/vanity.yml", "w") do |io|
11
- io.write "production: #{Vanity.playground.connection}"
11
+ io.write YAML.dump({ "production"=>DATABASE })
12
12
  end
13
13
  @server = PhusionPassenger::SpawnManager.new
14
14
  @server.start
@@ -25,4 +25,12 @@ class RailsHelperTest < ActionView::TestCase
25
25
  assert result == ab_test(:pie_or_cake)
26
26
  end
27
27
  end
28
+
29
+ def test_vanity_track_url_for_returns_url_with_identity_and_metrics
30
+ assert_equal vanity_track_url_for("123", :sugar_high, :controller => "controller", :action => "action"), "/controller/action?_identity=123&amp;_track=sugar_high"
31
+ end
32
+
33
+ def test_vanity_tracking_image
34
+ assert_equal vanity_tracking_image("123", :sugar_high, options = {}), image_tag("/vanity/image?_identity=123&amp;_track=sugar_high", :width => "1px", :height => "1px", :alt => "")
35
+ end
28
36
  end
data/test/rails_test.rb CHANGED
@@ -85,7 +85,17 @@ class UseVanityTest < ActionController::TestCase
85
85
  get :index
86
86
  assert_equal "576", @controller.send(:vanity_identity)
87
87
  end
88
-
88
+
89
+ def test_vanity_identity_set_with_indentity_paramater
90
+ get :index, :_identity => "id_from_params"
91
+ assert_equal "id_from_params", @controller.send(:vanity_identity)
92
+
93
+ @request.cookies['vanity_id'] = "old_id"
94
+ get :index, :_identity => "id_from_params"
95
+ assert_equal "id_from_params", @controller.send(:vanity_identity)
96
+ assert cookies['vanity_id'], "id_from_params"
97
+ end
98
+
89
99
  # query parameter filter
90
100
 
91
101
  def test_redirects_and_loses_vanity_query_parameter
@@ -113,6 +123,11 @@ class UseVanityTest < ActionController::TestCase
113
123
  assert !experiment(:pie_or_cake).showing?(first)
114
124
  end
115
125
 
126
+ def test_track_param_tracks_a_metric
127
+ get :index, :_identity => "123", :_track => "sugar_high"
128
+ assert_equal experiment(:pie_or_cake).alternatives[0].converted, 1
129
+ end
130
+
116
131
  def test_cookie_domain_from_rails_configuration
117
132
  get :index
118
133
  assert_equal cookies["vanity_id"][:domain], '.foo.bar' if ::Rails.respond_to?(:application)
@@ -192,8 +207,7 @@ mongodb:
192
207
  YML
193
208
  end
194
209
 
195
- ENV["RAILS_ENV"] = "mongodb"
196
- assert_equal "mongodb://localhost:27017/vanity_test", load_rails(<<-RB)
210
+ assert_equal "mongodb://localhost:27017/vanity_test", load_rails(<<-RB, "mongodb")
197
211
  initializer.after_initialize
198
212
  $stdout << Vanity.playground.connection
199
213
  RB
@@ -214,14 +228,12 @@ mongodb:
214
228
  YML
215
229
  end
216
230
 
217
- ENV["RAILS_ENV"] = "mongodb"
218
- assert_equal "mongodb://localhost:27017/vanity_test", load_rails(<<-RB)
231
+ assert_equal "mongodb://localhost:27017/vanity_test", load_rails(<<-RB, "mongodb")
219
232
  initializer.after_initialize
220
233
  $stdout << Vanity.playground.connection
221
234
  RB
222
235
 
223
- ENV["RAILS_ENV"] = "mongodb"
224
- assert_equal "Mongo::ReplSetConnection", load_rails(<<-RB)
236
+ assert_equal "Mongo::ReplSetConnection", load_rails(<<-RB, "mongodb")
225
237
  initializer.after_initialize
226
238
  $stdout << Vanity.playground.connection.mongo.class
227
239
  RB
@@ -247,14 +259,13 @@ $stdout << Vanity.playground.connection
247
259
 
248
260
  def test_connection_from_yaml_missing
249
261
  FileUtils.mkpath "tmp/config"
250
- ENV["RAILS_ENV"] = "development"
251
262
  File.open("tmp/config/vanity.yml", "w") do |io|
252
263
  io.write <<-YML
253
264
  production:
254
265
  adapter: redis
255
266
  YML
256
267
  end
257
- assert_equal "No configuration for development", load_rails(<<-RB)
268
+ assert_equal "No configuration for development", load_rails(<<-RB, "development")
258
269
  initializer.after_initialize
259
270
  $stdout << (Vanity.playground.connection rescue $!.message)
260
271
  RB
@@ -283,7 +294,7 @@ $stdout << Vanity.playground.connection
283
294
  def test_connection_from_redis_yml
284
295
  FileUtils.mkpath "tmp/config"
285
296
  yml = File.open("tmp/config/redis.yml", "w")
286
- yml << "development: internal.local:6379\n"
297
+ yml << "production: internal.local:6379\n"
287
298
  yml.flush
288
299
  assert_equal "redis://internal.local:6379/0", load_rails(<<-RB)
289
300
  initializer.after_initialize
@@ -295,10 +306,9 @@ $stdout << Vanity.playground.connection
295
306
 
296
307
  def test_collection_from_vanity_yaml
297
308
  FileUtils.mkpath "tmp/config"
298
- ENV["RAILS_ENV"] = "development"
299
309
  File.open("tmp/config/vanity.yml", "w") do |io|
300
310
  io.write <<-YML
301
- development:
311
+ production:
302
312
  collecting: false
303
313
  YML
304
314
  end
@@ -354,7 +364,7 @@ $stdout << Vanity.playground.collecting?
354
364
  $:.delete_if { |path| path[/gems\\/vanity-\\d/] }
355
365
  $:.unshift File.expand_path("../lib")
356
366
  RAILS_ROOT = File.expand_path(".")
357
- RAILS_ENV = "#{env}"
367
+ RAILS_ENV = ENV['RACK_ENV'] = "#{env}"
358
368
  require "initializer"
359
369
  require "active_support"
360
370
  Rails.configuration = Rails::Configuration.new
data/test/test_helper.rb CHANGED
@@ -1,5 +1,8 @@
1
+ GC.disable
1
2
  $LOAD_PATH.delete_if { |path| path[/gems\/vanity-\d/] }
2
3
  $LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__))
4
+ ENV["RACK_ENV"] = "test"
5
+ ENV["DB"] ||= "redis"
3
6
 
4
7
  RAILS_ROOT = File.expand_path("..")
5
8
  require "test/unit"
@@ -21,9 +24,22 @@ if $VERBOSE
21
24
  $logger.level = Logger::DEBUG
22
25
  end
23
26
 
27
+
24
28
  class Test::Unit::TestCase
25
29
  include WebMock::API
26
30
 
31
+ # We go destructive on the database at the end of each run, so make sure we
32
+ # don't use databases you care about. For Redis, we pick database 15
33
+ # (default is 0).
34
+ DATABASE = {
35
+ "redis"=>"redis://localhost/15",
36
+ "mongodb"=>"mongodb://localhost/vanity",
37
+ "mysql"=> { "adapter"=>"active_record", "active_record_adapter"=>"mysql", "database"=>"vanity_test" },
38
+ "postgres"=> { "adapter"=>"active_record", "active_record_adapter"=>"postgresql", "database"=>"vanity_test", "username"=>"postgres" },
39
+ "mock"=>"mock:/"
40
+ }[ENV["DB"]] or raise "No support yet for #{ENV["DB"]}"
41
+
42
+
27
43
  def setup
28
44
  FileUtils.mkpath "tmp/experiments/metrics"
29
45
  new_playground
@@ -39,18 +55,8 @@ class Test::Unit::TestCase
39
55
  # Call this if you need a new playground, e.g. to re-define the same experiment,
40
56
  # or reload an experiment (saved by the previous playground).
41
57
  def new_playground
42
- adapter = ENV["ADAPTER"] || "redis"
43
- # We go destructive on the database at the end of each run, so make sure we
44
- # don't use databases you care about. For Redis, we pick database 15
45
- # (default is 0).
46
- spec = {
47
- "redis"=>"redis://localhost/15",
48
- "mongodb"=>"mongodb://localhost/vanity-test",
49
- "mock"=>"mock:/"
50
- }[adapter]
51
- raise "No support yet for #{adapter}" unless spec
52
58
  Vanity.playground = Vanity::Playground.new(:logger=>$logger, :load_path=>"tmp/experiments")
53
- Vanity.playground.establish_connection spec
59
+ Vanity.playground.establish_connection DATABASE
54
60
  end
55
61
 
56
62
  # Defines the specified metrics (one or more names). Returns metric, or array
@@ -103,6 +109,12 @@ end
103
109
  ActiveRecord::Base.logger = $logger
104
110
  ActiveRecord::Base.establish_connection :adapter=>"mysql", :database=>"vanity_test"
105
111
 
112
+ if ENV["DB"] == "mysql" || ENV["DB"] == "postgres"
113
+ require "generators/templates/vanity_migration"
114
+ VanityMigration.down rescue nil
115
+ VanityMigration.up
116
+ end
117
+
106
118
 
107
119
  class Array
108
120
  # Not in Ruby 1.8.6.