vanity 1.2.0 → 1.3.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 (69) hide show
  1. data/CHANGELOG +34 -0
  2. data/Gemfile +16 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +10 -5
  5. data/Rakefile +119 -0
  6. data/bin/vanity +23 -18
  7. data/lib/vanity.rb +12 -4
  8. data/lib/vanity/commands.rb +1 -0
  9. data/lib/vanity/commands/list.rb +21 -0
  10. data/lib/vanity/experiment/ab_test.rb +8 -1
  11. data/lib/vanity/experiment/base.rb +40 -30
  12. data/lib/vanity/frameworks/rails.rb +222 -0
  13. data/lib/vanity/metric/active_record.rb +77 -0
  14. data/lib/vanity/{metric.rb → metric/base.rb} +6 -71
  15. data/lib/vanity/metric/google_analytics.rb +76 -0
  16. data/lib/vanity/playground.rb +93 -44
  17. data/lib/vanity/templates/_metric.erb +12 -7
  18. data/lib/vanity/templates/vanity.css +1 -0
  19. data/test/ab_test_test.rb +69 -48
  20. data/test/experiment_test.rb +29 -15
  21. data/test/metric_test.rb +104 -0
  22. data/test/myapp/app/controllers/application_controller.rb +2 -0
  23. data/test/myapp/app/controllers/main_controller.rb +7 -0
  24. data/test/myapp/config/boot.rb +110 -0
  25. data/test/myapp/config/environment.rb +10 -0
  26. data/test/myapp/config/environments/production.rb +0 -0
  27. data/test/myapp/config/routes.rb +3 -0
  28. data/test/myapp/log/production.log +80 -0
  29. data/test/passenger_test.rb +34 -0
  30. data/test/rails_test.rb +129 -1
  31. data/test/test_helper.rb +12 -4
  32. data/vanity.gemspec +2 -2
  33. data/vendor/cache/RedCloth-4.2.2.gem +0 -0
  34. data/vendor/cache/actionmailer-2.3.5.gem +0 -0
  35. data/vendor/cache/actionpack-2.3.5.gem +0 -0
  36. data/vendor/cache/activerecord-2.3.5.gem +0 -0
  37. data/vendor/cache/activeresource-2.3.5.gem +0 -0
  38. data/vendor/cache/activesupport-2.3.5.gem +0 -0
  39. data/vendor/cache/autotest-4.2.7.gem +0 -0
  40. data/vendor/cache/autotest-fsevent-0.2.1.gem +0 -0
  41. data/vendor/cache/autotest-growl-0.2.0.gem +0 -0
  42. data/vendor/cache/bundler-0.9.7.gem +0 -0
  43. data/vendor/cache/classifier-1.3.1.gem +0 -0
  44. data/vendor/cache/directory_watcher-1.3.1.gem +0 -0
  45. data/vendor/cache/fastthread-1.0.7.gem +0 -0
  46. data/vendor/cache/garb-0.7.0.gem +0 -0
  47. data/vendor/cache/happymapper-0.3.0.gem +0 -0
  48. data/vendor/cache/jekyll-0.5.7.gem +0 -0
  49. data/vendor/cache/libxml-ruby-1.1.3.gem +0 -0
  50. data/vendor/cache/liquid-2.0.0.gem +0 -0
  51. data/vendor/cache/maruku-0.6.0.gem +0 -0
  52. data/vendor/cache/mocha-0.9.8.gem +0 -0
  53. data/vendor/cache/open4-1.0.1.gem +0 -0
  54. data/vendor/cache/passenger-2.2.9.gem +0 -0
  55. data/vendor/cache/rack-1.0.1.gem +0 -0
  56. data/vendor/cache/rails-2.3.5.gem +0 -0
  57. data/vendor/cache/rake-0.8.7.gem +0 -0
  58. data/vendor/cache/rubygems-update-1.3.5.gem +0 -0
  59. data/vendor/cache/shoulda-2.10.3.gem +0 -0
  60. data/vendor/cache/sqlite3-ruby-1.2.5.gem +0 -0
  61. data/vendor/cache/stemmer-1.0.1.gem +0 -0
  62. data/vendor/cache/syntax-1.0.0.gem +0 -0
  63. data/vendor/cache/sys-uname-0.8.4.gem +0 -0
  64. data/vendor/cache/timecop-0.3.4.gem +0 -0
  65. metadata +60 -11
  66. data/lib/vanity/rails.rb +0 -22
  67. data/lib/vanity/rails/dashboard.rb +0 -24
  68. data/lib/vanity/rails/helpers.rb +0 -101
  69. data/lib/vanity/rails/testing.rb +0 -11
@@ -15,7 +15,7 @@ class UseVanityTest < ActionController::TestCase
15
15
  def setup
16
16
  super
17
17
  metric :sugar_high
18
- Vanity.playground.define :pie_or_cake, :ab_test do
18
+ new_ab_test :pie_or_cake do
19
19
  metrics :sugar_high
20
20
  end
21
21
  UseVanityController.class_eval do
@@ -72,6 +72,134 @@ class UseVanityTest < ActionController::TestCase
72
72
  assert_equal "576", @controller.send(:vanity_identity)
73
73
  end
74
74
 
75
+ # query parameter filter
76
+
77
+ def test_redirects_and_loses_vanity_query_parameter
78
+ get :index, :foo=>"bar", :_vanity=>"567"
79
+ assert_redirected_to "/use_vanity?foo=bar"
80
+ end
81
+
82
+ def test_sets_choices_from_vanity_query_parameter
83
+ first = experiment(:pie_or_cake).alternatives.first
84
+ # experiment(:pie_or_cake).fingerprint(first)
85
+ 10.times do
86
+ @controller = nil ; setup_controller_request_and_response
87
+ get :index, :_vanity=>"aae9ff8081"
88
+ assert !experiment(:pie_or_cake).choose
89
+ assert experiment(:pie_or_cake).showing?(first)
90
+ end
91
+ end
92
+
93
+ def test_does_nothing_with_vanity_query_parameter_for_posts
94
+ first = experiment(:pie_or_cake).alternatives.first
95
+ post :index, :foo=>"bar", :_vanity=>"567"
96
+ assert_response :success
97
+ assert !experiment(:pie_or_cake).showing?(first)
98
+ end
99
+
100
+
101
+ # -- Load path --
102
+
103
+ def test_load_path
104
+ assert_equal File.expand_path("tmp/experiments"), load_rails(<<-RB)
105
+ initializer.after_initialize
106
+ $stdout << Vanity.playground.load_path
107
+ RB
108
+ end
109
+
110
+ def test_settable_load_path
111
+ assert_equal File.expand_path("tmp/predictions"), load_rails(<<-RB)
112
+ Vanity.playground.load_path = "predictions"
113
+ initializer.after_initialize
114
+ $stdout << Vanity.playground.load_path
115
+ RB
116
+ end
117
+
118
+ def test_absolute_load_path
119
+ assert_equal File.expand_path("/tmp/var"), load_rails(<<-RB)
120
+ Vanity.playground.load_path = "/tmp/var"
121
+ initializer.after_initialize
122
+ $stdout << Vanity.playground.load_path
123
+ RB
124
+ end
125
+
126
+
127
+ # -- Connection configuration --
128
+
129
+ def test_default_connection
130
+ assert_equal "localhost:6379", load_rails(<<-RB)
131
+ initializer.after_initialize
132
+ $stdout << Vanity.playground.redis.server
133
+ RB
134
+ end
135
+
136
+ def test_configured_connection
137
+ assert_equal "127.0.0.1:6379", load_rails(<<-RB)
138
+ Vanity.playground.redis = "127.0.0.1:6379"
139
+ initializer.after_initialize
140
+ $stdout << Vanity.playground.redis.server
141
+ RB
142
+ end
143
+
144
+ def test_test_connection
145
+ assert_equal "Vanity::MockRedis", load_rails(<<-RB)
146
+ Vanity.playground.test!
147
+ initializer.after_initialize
148
+ $stdout << Vanity.playground.redis.class
149
+ RB
150
+ end
151
+
152
+ def test_connection_from_yaml
153
+ FileUtils.mkpath "tmp/config"
154
+ yml = File.open("tmp/config/redis.yml", "w")
155
+ yml << "production: internal.local:6379\n"
156
+ yml.flush
157
+ assert_equal "internal.local:6379", load_rails(<<-RB)
158
+ initializer.after_initialize
159
+ $stdout << Vanity.playground.redis.server
160
+ RB
161
+ ensure
162
+ File.unlink yml
163
+ end
164
+
165
+ def test_connection_from_yaml_missing
166
+ FileUtils.mkpath "tmp/config"
167
+ yml = File.open("tmp/config/redis.yml", "w")
168
+ yml << "development: internal.local:6379\n"
169
+ yml.flush
170
+ assert_equal "localhost:6379", load_rails(<<-RB)
171
+ initializer.after_initialize
172
+ $stdout << Vanity.playground.redis.server
173
+ RB
174
+ ensure
175
+ File.unlink yml
176
+ end
177
+
178
+
179
+ def load_rails(code)
180
+ tmp = Tempfile.open("test.rb")
181
+ tmp.write <<-RB
182
+ $:.delete_if { |path| path[/gems\\/vanity-\\d/] }
183
+ $:.unshift File.expand_path("../lib")
184
+ RAILS_ROOT = File.expand_path(".")
185
+ RAILS_ENV = "production"
186
+ require "initializer"
187
+ require "active_support"
188
+ Rails.configuration = Rails::Configuration.new
189
+ initializer = Rails::Initializer.new(Rails.configuration)
190
+ initializer.check_gem_dependencies
191
+ require "vanity"
192
+ RB
193
+ tmp.write code
194
+ tmp.flush
195
+ Dir.chdir "tmp" do
196
+ open("|ruby #{tmp.path}").read
197
+ end
198
+ rescue
199
+ tmp.close!
200
+ end
201
+
202
+
75
203
  def teardown
76
204
  super
77
205
  UseVanityController.send(:filter_chain).clear
@@ -8,6 +8,7 @@ require "action_controller/test_case"
8
8
  require "active_record"
9
9
  require "initializer"
10
10
  Rails.configuration = Rails::Configuration.new
11
+ require "phusion_passenger/events"
11
12
  require "lib/vanity"
12
13
  require "timecop"
13
14
 
@@ -15,8 +16,6 @@ require "timecop"
15
16
  if $VERBOSE
16
17
  $logger = Logger.new(STDOUT)
17
18
  $logger.level = Logger::DEBUG
18
- else
19
- $logger = Logger.new("/dev/null")
20
19
  end
21
20
 
22
21
  class Test::Unit::TestCase
@@ -36,8 +35,8 @@ class Test::Unit::TestCase
36
35
  # Call this if you need a new playground, e.g. to re-define the same experiment,
37
36
  # or reload an experiment (saved by the previous playground).
38
37
  def new_playground
39
- Vanity.playground = Vanity::Playground.new(:logger=>$logger, :load_path=>"tmp/experiments", :db=>15)
40
- Vanity.playground.mock! unless ENV["REDIS"]
38
+ Vanity.playground = Vanity::Playground.new("::15", :logger=>$logger, :load_path=>"tmp/experiments")
39
+ #Vanity.playground.mock! unless ENV["REDIS"]
41
40
  end
42
41
 
43
42
  # Defines the specified metrics (one or more names). Returns metric, or array
@@ -50,6 +49,15 @@ class Test::Unit::TestCase
50
49
  names.size == 1 ? metrics.first : metrics
51
50
  end
52
51
 
52
+ # Defines an A/B experiment.
53
+ def new_ab_test(name, &block)
54
+ id = name.to_s.downcase.gsub(/\W/, "_").to_sym
55
+ experiment = Vanity::Experiment::AbTest.new(Vanity.playground, id, name)
56
+ experiment.instance_eval &block
57
+ experiment.save
58
+ Vanity.playground.experiments[id] = experiment
59
+ end
60
+
53
61
  # Returns named experiment.
54
62
  def experiment(name)
55
63
  Vanity.playground.experiment(name)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "vanity"
3
- spec.version = "1.2.0"
3
+ spec.version = "1.3.0"
4
4
  spec.author = "Assaf Arkin"
5
5
  spec.email = "assaf@labnotes.org"
6
6
  spec.homepage = "http://vanity.labnotes.org"
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.description = "Mirror, mirror on the wall ..."
9
9
  spec.post_install_message = "To get started run vanity --help"
10
10
 
11
- spec.files = Dir["{bin,lib,vendor,test}/**/*", "CHANGELOG", "MIT-LICENSE", "README.rdoc", "vanity.gemspec"]
11
+ spec.files = Dir["{bin,lib,vendor,test}/**/*", "CHANGELOG", "MIT-LICENSE", "README.rdoc", "Rakefile", "Gemfile", "vanity.gemspec"]
12
12
  spec.executable = "vanity"
13
13
 
14
14
  spec.has_rdoc = true
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanity
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 3
8
+ - 0
9
+ version: 1.3.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Assaf Arkin
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-12-14 00:00:00 -08:00
17
+ date: 2010-03-01 00:00:00 -08:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -25,18 +30,18 @@ extra_rdoc_files:
25
30
  files:
26
31
  - bin/vanity
27
32
  - lib/vanity/backport.rb
33
+ - lib/vanity/commands/list.rb
28
34
  - lib/vanity/commands/report.rb
29
35
  - lib/vanity/commands.rb
30
36
  - lib/vanity/experiment/ab_test.rb
31
37
  - lib/vanity/experiment/base.rb
38
+ - lib/vanity/frameworks/rails.rb
32
39
  - lib/vanity/helpers.rb
33
- - lib/vanity/metric.rb
40
+ - lib/vanity/metric/active_record.rb
41
+ - lib/vanity/metric/base.rb
42
+ - lib/vanity/metric/google_analytics.rb
34
43
  - lib/vanity/mock_redis.rb
35
44
  - lib/vanity/playground.rb
36
- - lib/vanity/rails/dashboard.rb
37
- - lib/vanity/rails/helpers.rb
38
- - lib/vanity/rails/testing.rb
39
- - lib/vanity/rails.rb
40
45
  - lib/vanity/templates/_ab_test.erb
41
46
  - lib/vanity/templates/_experiment.erb
42
47
  - lib/vanity/templates/_experiments.erb
@@ -48,6 +53,38 @@ files:
48
53
  - lib/vanity/templates/vanity.css
49
54
  - lib/vanity/templates/vanity.js
50
55
  - lib/vanity.rb
56
+ - vendor/cache/actionmailer-2.3.5.gem
57
+ - vendor/cache/actionpack-2.3.5.gem
58
+ - vendor/cache/activerecord-2.3.5.gem
59
+ - vendor/cache/activeresource-2.3.5.gem
60
+ - vendor/cache/activesupport-2.3.5.gem
61
+ - vendor/cache/autotest-4.2.7.gem
62
+ - vendor/cache/autotest-fsevent-0.2.1.gem
63
+ - vendor/cache/autotest-growl-0.2.0.gem
64
+ - vendor/cache/bundler-0.9.7.gem
65
+ - vendor/cache/classifier-1.3.1.gem
66
+ - vendor/cache/directory_watcher-1.3.1.gem
67
+ - vendor/cache/fastthread-1.0.7.gem
68
+ - vendor/cache/garb-0.7.0.gem
69
+ - vendor/cache/happymapper-0.3.0.gem
70
+ - vendor/cache/jekyll-0.5.7.gem
71
+ - vendor/cache/libxml-ruby-1.1.3.gem
72
+ - vendor/cache/liquid-2.0.0.gem
73
+ - vendor/cache/maruku-0.6.0.gem
74
+ - vendor/cache/mocha-0.9.8.gem
75
+ - vendor/cache/open4-1.0.1.gem
76
+ - vendor/cache/passenger-2.2.9.gem
77
+ - vendor/cache/rack-1.0.1.gem
78
+ - vendor/cache/rails-2.3.5.gem
79
+ - vendor/cache/rake-0.8.7.gem
80
+ - vendor/cache/RedCloth-4.2.2.gem
81
+ - vendor/cache/rubygems-update-1.3.5.gem
82
+ - vendor/cache/shoulda-2.10.3.gem
83
+ - vendor/cache/sqlite3-ruby-1.2.5.gem
84
+ - vendor/cache/stemmer-1.0.1.gem
85
+ - vendor/cache/syntax-1.0.0.gem
86
+ - vendor/cache/sys-uname-0.8.4.gem
87
+ - vendor/cache/timecop-0.3.4.gem
51
88
  - vendor/redis-rb/bench.rb
52
89
  - vendor/redis-rb/benchmarking/suite.rb
53
90
  - vendor/redis-rb/benchmarking/worker.rb
@@ -78,12 +115,22 @@ files:
78
115
  - test/experiments/metrics/yawns.rb
79
116
  - test/experiments/null_abc.rb
80
117
  - test/metric_test.rb
118
+ - test/myapp/app/controllers/application_controller.rb
119
+ - test/myapp/app/controllers/main_controller.rb
120
+ - test/myapp/config/boot.rb
121
+ - test/myapp/config/environment.rb
122
+ - test/myapp/config/environments/production.rb
123
+ - test/myapp/config/routes.rb
124
+ - test/myapp/log/production.log
125
+ - test/passenger_test.rb
81
126
  - test/playground_test.rb
82
127
  - test/rails_test.rb
83
128
  - test/test_helper.rb
84
129
  - CHANGELOG
85
130
  - MIT-LICENSE
86
131
  - README.rdoc
132
+ - Rakefile
133
+ - Gemfile
87
134
  - vanity.gemspec
88
135
  has_rdoc: true
89
136
  homepage: http://vanity.labnotes.org
@@ -92,7 +139,7 @@ licenses: []
92
139
  post_install_message: To get started run vanity --help
93
140
  rdoc_options:
94
141
  - --title
95
- - Vanity 1.2.0
142
+ - Vanity 1.3.0
96
143
  - --main
97
144
  - README.rdoc
98
145
  - --webcvs
@@ -103,18 +150,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
150
  requirements:
104
151
  - - ">="
105
152
  - !ruby/object:Gem::Version
153
+ segments:
154
+ - 0
106
155
  version: "0"
107
- version:
108
156
  required_rubygems_version: !ruby/object:Gem::Requirement
109
157
  requirements:
110
158
  - - ">="
111
159
  - !ruby/object:Gem::Version
160
+ segments:
161
+ - 0
112
162
  version: "0"
113
- version:
114
163
  requirements: []
115
164
 
116
165
  rubyforge_project:
117
- rubygems_version: 1.3.5
166
+ rubygems_version: 1.3.6
118
167
  signing_key:
119
168
  specification_version: 3
120
169
  summary: Experience Driven Development framework for Rails
@@ -1,22 +0,0 @@
1
- require "vanity/rails/helpers"
2
- require "vanity/rails/testing"
3
- require "vanity/rails/dashboard"
4
-
5
- # Include in controller, add view helper methods.
6
- ActionController::Base.class_eval do
7
- extend Vanity::Rails::ClassMethods
8
- include Vanity::Rails
9
- helper Vanity::Rails
10
- end
11
-
12
- Rails.configuration.after_initialize do
13
- # Use Rails logger by default.
14
- Vanity.playground.logger ||= ActionController::Base.logger
15
- Vanity.playground.load_path = "#{RAILS_ROOT}/experiments"
16
-
17
- # Do this at the very end of initialization, allowing test environment to do
18
- # Vanity.playground.mock! before any database access takes place.
19
- Rails.configuration.after_initialize do
20
- Vanity.playground.load!
21
- end
22
- end
@@ -1,24 +0,0 @@
1
- module Vanity
2
- module Rails
3
- # Step 1: Add a new resource in config/routes.rb:
4
- # map.vanity "/vanity/:action/:id", :controller=>:vanity
5
- #
6
- # Step 2: Create a new experiments controller:
7
- # class VanityController < ApplicationController
8
- # include Vanity::Rails::Dashboard
9
- # end
10
- #
11
- # Step 3: Open your browser to http://localhost:3000/vanity
12
- module Dashboard
13
- def index
14
- render Vanity.template("_report"), :content_type=>Mime::HTML, :layout=>true
15
- end
16
-
17
- def chooses
18
- exp = Vanity.playground.experiment(params[:e])
19
- exp.chooses(exp.alternatives[params[:a].to_i].value)
20
- render :partial=>Vanity.template("experiment"), :locals=>{ :experiment=>exp }
21
- end
22
- end
23
- end
24
- end