moses-vanity 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/.autotest +22 -0
  2. data/.gitignore +7 -0
  3. data/.rvmrc +3 -0
  4. data/.travis.yml +13 -0
  5. data/CHANGELOG +374 -0
  6. data/Gemfile +28 -0
  7. data/MIT-LICENSE +21 -0
  8. data/README.rdoc +108 -0
  9. data/Rakefile +189 -0
  10. data/bin/vanity +16 -0
  11. data/doc/_config.yml +2 -0
  12. data/doc/_layouts/_header.html +34 -0
  13. data/doc/_layouts/page.html +47 -0
  14. data/doc/_metrics.textile +12 -0
  15. data/doc/ab_testing.textile +210 -0
  16. data/doc/configuring.textile +45 -0
  17. data/doc/contributing.textile +93 -0
  18. data/doc/credits.textile +23 -0
  19. data/doc/css/page.css +83 -0
  20. data/doc/css/print.css +43 -0
  21. data/doc/css/syntax.css +7 -0
  22. data/doc/email.textile +129 -0
  23. data/doc/experimental.textile +31 -0
  24. data/doc/faq.textile +8 -0
  25. data/doc/identity.textile +43 -0
  26. data/doc/images/ab_in_dashboard.png +0 -0
  27. data/doc/images/clear_winner.png +0 -0
  28. data/doc/images/price_options.png +0 -0
  29. data/doc/images/sidebar_test.png +0 -0
  30. data/doc/images/signup_metric.png +0 -0
  31. data/doc/images/vanity.png +0 -0
  32. data/doc/index.textile +91 -0
  33. data/doc/metrics.textile +231 -0
  34. data/doc/rails.textile +89 -0
  35. data/doc/site.js +27 -0
  36. data/generators/templates/vanity_migration.rb +53 -0
  37. data/generators/vanity_generator.rb +8 -0
  38. data/lib/generators/templates/vanity_migration.rb +53 -0
  39. data/lib/generators/vanity_generator.rb +15 -0
  40. data/lib/vanity.rb +36 -0
  41. data/lib/vanity/adapters/abstract_adapter.rb +140 -0
  42. data/lib/vanity/adapters/active_record_adapter.rb +248 -0
  43. data/lib/vanity/adapters/mock_adapter.rb +157 -0
  44. data/lib/vanity/adapters/mongodb_adapter.rb +178 -0
  45. data/lib/vanity/adapters/redis_adapter.rb +160 -0
  46. data/lib/vanity/backport.rb +26 -0
  47. data/lib/vanity/commands/list.rb +21 -0
  48. data/lib/vanity/commands/report.rb +64 -0
  49. data/lib/vanity/commands/upgrade.rb +34 -0
  50. data/lib/vanity/experiment/ab_test.rb +507 -0
  51. data/lib/vanity/experiment/base.rb +214 -0
  52. data/lib/vanity/frameworks.rb +16 -0
  53. data/lib/vanity/frameworks/rails.rb +318 -0
  54. data/lib/vanity/helpers.rb +66 -0
  55. data/lib/vanity/images/x.gif +0 -0
  56. data/lib/vanity/metric/active_record.rb +85 -0
  57. data/lib/vanity/metric/base.rb +244 -0
  58. data/lib/vanity/metric/google_analytics.rb +83 -0
  59. data/lib/vanity/metric/remote.rb +53 -0
  60. data/lib/vanity/playground.rb +396 -0
  61. data/lib/vanity/templates/_ab_test.erb +28 -0
  62. data/lib/vanity/templates/_experiment.erb +5 -0
  63. data/lib/vanity/templates/_experiments.erb +7 -0
  64. data/lib/vanity/templates/_metric.erb +14 -0
  65. data/lib/vanity/templates/_metrics.erb +13 -0
  66. data/lib/vanity/templates/_report.erb +27 -0
  67. data/lib/vanity/templates/_vanity.js.erb +20 -0
  68. data/lib/vanity/templates/flot.min.js +1 -0
  69. data/lib/vanity/templates/jquery.min.js +19 -0
  70. data/lib/vanity/templates/vanity.css +26 -0
  71. data/lib/vanity/templates/vanity.js +82 -0
  72. data/lib/vanity/version.rb +11 -0
  73. data/test/adapters/redis_adapter_test.rb +17 -0
  74. data/test/experiment/ab_test.rb +771 -0
  75. data/test/experiment/base_test.rb +150 -0
  76. data/test/experiments/age_and_zipcode.rb +19 -0
  77. data/test/experiments/metrics/cheers.rb +3 -0
  78. data/test/experiments/metrics/signups.rb +2 -0
  79. data/test/experiments/metrics/yawns.rb +3 -0
  80. data/test/experiments/null_abc.rb +5 -0
  81. data/test/metric/active_record_test.rb +277 -0
  82. data/test/metric/base_test.rb +293 -0
  83. data/test/metric/google_analytics_test.rb +104 -0
  84. data/test/metric/remote_test.rb +109 -0
  85. data/test/myapp/app/controllers/application_controller.rb +2 -0
  86. data/test/myapp/app/controllers/main_controller.rb +7 -0
  87. data/test/myapp/config/boot.rb +110 -0
  88. data/test/myapp/config/environment.rb +10 -0
  89. data/test/myapp/config/environments/production.rb +0 -0
  90. data/test/myapp/config/routes.rb +3 -0
  91. data/test/passenger_test.rb +43 -0
  92. data/test/playground_test.rb +26 -0
  93. data/test/rails_dashboard_test.rb +37 -0
  94. data/test/rails_helper_test.rb +36 -0
  95. data/test/rails_test.rb +389 -0
  96. data/test/test_helper.rb +145 -0
  97. data/vanity.gemspec +26 -0
  98. metadata +202 -0
@@ -0,0 +1,145 @@
1
+ GC.disable
2
+ $LOAD_PATH.delete_if { |path| path[/gems\/vanity-\d/] }
3
+ $LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__))
4
+ ENV["RACK_ENV"] = "test"
5
+ ENV["DB"] ||= "redis"
6
+
7
+ RAILS_ROOT = File.expand_path("..")
8
+ require "test/unit"
9
+ require "mocha"
10
+ require "action_controller"
11
+ require "action_controller/test_case"
12
+ require "action_view/test_case"
13
+ require "active_record"
14
+ require "initializer"
15
+ Rails.configuration = Rails::Configuration.new
16
+ require "phusion_passenger/events"
17
+ require "lib/vanity"
18
+ require "timecop"
19
+ require "webmock/test_unit"
20
+ require "ruby-debug"
21
+
22
+
23
+ if $VERBOSE
24
+ $logger = Logger.new(STDOUT)
25
+ $logger.level = Logger::DEBUG
26
+ end
27
+
28
+
29
+ class Test::Unit::TestCase
30
+ include WebMock::API
31
+
32
+ # We go destructive on the database at the end of each run, so make sure we
33
+ # don't use databases you care about. For Redis, we pick database 15
34
+ # (default is 0).
35
+ DATABASE = {
36
+ "redis"=>"redis://localhost/15",
37
+ "mongodb"=>"mongodb://localhost/vanity",
38
+ "mysql"=> { "adapter"=>"active_record", "active_record_adapter"=>"mysql", "database"=>"vanity_test" },
39
+ "postgres"=> { "adapter"=>"active_record", "active_record_adapter"=>"postgresql", "database"=>"vanity_test", "username"=>"postgres" },
40
+ "mock"=>"mock:/"
41
+ }[ENV["DB"]] or raise "No support yet for #{ENV["DB"]}"
42
+
43
+
44
+ def setup
45
+ FileUtils.mkpath "tmp/experiments/metrics"
46
+ new_playground
47
+ end
48
+
49
+ # Call this on teardown. It wipes put the playground and any state held in it
50
+ # (mostly experiments), resets vanity ID, and clears database of all experiments.
51
+ def nuke_playground
52
+ Vanity.playground.connection.flushdb
53
+ new_playground
54
+ end
55
+
56
+ # Call this if you need a new playground, e.g. to re-define the same experiment,
57
+ # or reload an experiment (saved by the previous playground).
58
+ def new_playground
59
+ Vanity.playground = Vanity::Playground.new(:logger=>$logger, :load_path=>"tmp/experiments")
60
+ Vanity.playground.establish_connection DATABASE
61
+ end
62
+
63
+ # Defines the specified metrics (one or more names). Returns metric, or array
64
+ # of metric (if more than one argument).
65
+ def metric(*names)
66
+ metrics = names.map do |name|
67
+ id = name.to_s.downcase.gsub(/\W+/, '_').to_sym
68
+ Vanity.playground.metrics[id] ||= Vanity::Metric.new(Vanity.playground, name)
69
+ end
70
+ names.size == 1 ? metrics.first : metrics
71
+ end
72
+
73
+ # Defines an A/B experiment.
74
+ def new_ab_test(name, &block)
75
+ id = name.to_s.downcase.gsub(/\W/, "_").to_sym
76
+ experiment = Vanity::Experiment::AbTest.new(Vanity.playground, id, name)
77
+ experiment.instance_eval &block
78
+ experiment.save
79
+ Vanity.playground.experiments[id] = experiment
80
+ end
81
+
82
+ # Returns named experiment.
83
+ def experiment(name)
84
+ Vanity.playground.experiment(name)
85
+ end
86
+
87
+ def today
88
+ @today ||= Date.today
89
+ end
90
+
91
+ def not_collecting!
92
+ Vanity.playground.collecting = false
93
+ Vanity.playground.stubs(:connection).returns(stub(:flushdb=>nil))
94
+ end
95
+
96
+ def teardown
97
+ Vanity.context = nil
98
+ FileUtils.rm_rf "tmp"
99
+ Vanity.playground.connection.flushdb if Vanity.playground.connected?
100
+ WebMock.reset!
101
+ end
102
+
103
+ end
104
+
105
+ ActionController::Routing::Routes.draw do |map|
106
+ map.connect ':controller/:action/:id'
107
+ end
108
+
109
+
110
+ ActiveRecord::Base.logger = $logger
111
+ ActiveRecord::Base.establish_connection :adapter=>"mysql", :database=>"vanity_test"
112
+
113
+ if ENV["DB"] == "mysql" || ENV["DB"] == "postgres"
114
+ require "generators/templates/vanity_migration"
115
+ VanityMigration.down rescue nil
116
+ VanityMigration.up
117
+ end
118
+
119
+
120
+ class Array
121
+ # Not in Ruby 1.8.6.
122
+ unless method_defined?(:shuffle)
123
+ def shuffle
124
+ copy = clone
125
+ Array.new(size) { copy.delete_at(Kernel.rand(copy.size)) }
126
+ end
127
+ end
128
+ end
129
+
130
+
131
+ # Source: http://gist.github.com/25455
132
+ def context(*args, &block)
133
+ return super unless (name = args.first) && block
134
+ parent = Class === self ? self : (defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase)
135
+ klass = Class.new(parent) do
136
+ def self.test(name, &block)
137
+ define_method("test_#{name.gsub(/\W/,'_')}", &block) if block
138
+ end
139
+ def self.xtest(*args) end
140
+ def self.setup(&block) define_method(:setup) { super() ; instance_eval &block } end
141
+ def self.teardown(&block) define_method(:teardown) { super() ; instance_eval &block } end
142
+ end
143
+ parent.const_set name.split(/\W+/).map(&:capitalize).join, klass
144
+ klass.class_eval &block
145
+ end
@@ -0,0 +1,26 @@
1
+ $: << File.dirname(__FILE__) + "/lib"
2
+ require "vanity/version"
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "moses-vanity"
6
+ spec.version = Vanity::VERSION
7
+ spec.author = "Assaf Arkin"
8
+ spec.email = "assaf@labnotes.org"
9
+ spec.homepage = "http://vanity.labnotes.org"
10
+ spec.summary = "Experience Driven Development framework for Ruby"
11
+ spec.description = "Mirror, mirror on the wall ..."
12
+ spec.post_install_message = "To get started run vanity --help"
13
+
14
+ spec.files = `git ls-files`.split("\n")
15
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.extra_rdoc_files = "README.rdoc", "CHANGELOG"
20
+ spec.rdoc_options = "--title", "Vanity #{spec.version}", "--main", "README.rdoc",
21
+ "--webcvs", "http://github.com/assaf/#{spec.name}"
22
+
23
+ spec.required_ruby_version = '>= 1.8.7'
24
+ spec.add_dependency "redis", "~>2.0"
25
+ spec.add_dependency "redis-namespace", "~>1.0.0"
26
+ end
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moses-vanity
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.7.1
6
+ platform: ruby
7
+ authors:
8
+ - Assaf Arkin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-02-06 00:00:00 -06:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: redis
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: "2.0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis-namespace
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 1.0.0
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: Mirror, mirror on the wall ...
39
+ email: assaf@labnotes.org
40
+ executables:
41
+ - vanity
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - README.rdoc
46
+ - CHANGELOG
47
+ files:
48
+ - .autotest
49
+ - .gitignore
50
+ - .rvmrc
51
+ - .travis.yml
52
+ - CHANGELOG
53
+ - Gemfile
54
+ - MIT-LICENSE
55
+ - README.rdoc
56
+ - Rakefile
57
+ - bin/vanity
58
+ - doc/_config.yml
59
+ - doc/_layouts/_header.html
60
+ - doc/_layouts/page.html
61
+ - doc/_metrics.textile
62
+ - doc/ab_testing.textile
63
+ - doc/configuring.textile
64
+ - doc/contributing.textile
65
+ - doc/credits.textile
66
+ - doc/css/page.css
67
+ - doc/css/print.css
68
+ - doc/css/syntax.css
69
+ - doc/email.textile
70
+ - doc/experimental.textile
71
+ - doc/faq.textile
72
+ - doc/identity.textile
73
+ - doc/images/ab_in_dashboard.png
74
+ - doc/images/clear_winner.png
75
+ - doc/images/price_options.png
76
+ - doc/images/sidebar_test.png
77
+ - doc/images/signup_metric.png
78
+ - doc/images/vanity.png
79
+ - doc/index.textile
80
+ - doc/metrics.textile
81
+ - doc/rails.textile
82
+ - doc/site.js
83
+ - generators/templates/vanity_migration.rb
84
+ - generators/vanity_generator.rb
85
+ - lib/generators/templates/vanity_migration.rb
86
+ - lib/generators/vanity_generator.rb
87
+ - lib/vanity.rb
88
+ - lib/vanity/adapters/abstract_adapter.rb
89
+ - lib/vanity/adapters/active_record_adapter.rb
90
+ - lib/vanity/adapters/mock_adapter.rb
91
+ - lib/vanity/adapters/mongodb_adapter.rb
92
+ - lib/vanity/adapters/redis_adapter.rb
93
+ - lib/vanity/backport.rb
94
+ - lib/vanity/commands/list.rb
95
+ - lib/vanity/commands/report.rb
96
+ - lib/vanity/commands/upgrade.rb
97
+ - lib/vanity/experiment/ab_test.rb
98
+ - lib/vanity/experiment/base.rb
99
+ - lib/vanity/frameworks.rb
100
+ - lib/vanity/frameworks/rails.rb
101
+ - lib/vanity/helpers.rb
102
+ - lib/vanity/images/x.gif
103
+ - lib/vanity/metric/active_record.rb
104
+ - lib/vanity/metric/base.rb
105
+ - lib/vanity/metric/google_analytics.rb
106
+ - lib/vanity/metric/remote.rb
107
+ - lib/vanity/playground.rb
108
+ - lib/vanity/templates/_ab_test.erb
109
+ - lib/vanity/templates/_experiment.erb
110
+ - lib/vanity/templates/_experiments.erb
111
+ - lib/vanity/templates/_metric.erb
112
+ - lib/vanity/templates/_metrics.erb
113
+ - lib/vanity/templates/_report.erb
114
+ - lib/vanity/templates/_vanity.js.erb
115
+ - lib/vanity/templates/flot.min.js
116
+ - lib/vanity/templates/jquery.min.js
117
+ - lib/vanity/templates/vanity.css
118
+ - lib/vanity/templates/vanity.js
119
+ - lib/vanity/version.rb
120
+ - test/adapters/redis_adapter_test.rb
121
+ - test/experiment/ab_test.rb
122
+ - test/experiment/base_test.rb
123
+ - test/experiments/age_and_zipcode.rb
124
+ - test/experiments/metrics/cheers.rb
125
+ - test/experiments/metrics/signups.rb
126
+ - test/experiments/metrics/yawns.rb
127
+ - test/experiments/null_abc.rb
128
+ - test/metric/active_record_test.rb
129
+ - test/metric/base_test.rb
130
+ - test/metric/google_analytics_test.rb
131
+ - test/metric/remote_test.rb
132
+ - test/myapp/app/controllers/application_controller.rb
133
+ - test/myapp/app/controllers/main_controller.rb
134
+ - test/myapp/config/boot.rb
135
+ - test/myapp/config/environment.rb
136
+ - test/myapp/config/environments/production.rb
137
+ - test/myapp/config/routes.rb
138
+ - test/passenger_test.rb
139
+ - test/playground_test.rb
140
+ - test/rails_dashboard_test.rb
141
+ - test/rails_helper_test.rb
142
+ - test/rails_test.rb
143
+ - test/test_helper.rb
144
+ - vanity.gemspec
145
+ has_rdoc: true
146
+ homepage: http://vanity.labnotes.org
147
+ licenses: []
148
+
149
+ post_install_message: To get started run vanity --help
150
+ rdoc_options:
151
+ - --title
152
+ - Vanity 1.7.1
153
+ - --main
154
+ - README.rdoc
155
+ - --webcvs
156
+ - http://github.com/assaf/moses-vanity
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: 1.8.7
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: "0"
171
+ requirements: []
172
+
173
+ rubyforge_project:
174
+ rubygems_version: 1.6.2
175
+ signing_key:
176
+ specification_version: 3
177
+ summary: Experience Driven Development framework for Ruby
178
+ test_files:
179
+ - test/adapters/redis_adapter_test.rb
180
+ - test/experiment/ab_test.rb
181
+ - test/experiment/base_test.rb
182
+ - test/experiments/age_and_zipcode.rb
183
+ - test/experiments/metrics/cheers.rb
184
+ - test/experiments/metrics/signups.rb
185
+ - test/experiments/metrics/yawns.rb
186
+ - test/experiments/null_abc.rb
187
+ - test/metric/active_record_test.rb
188
+ - test/metric/base_test.rb
189
+ - test/metric/google_analytics_test.rb
190
+ - test/metric/remote_test.rb
191
+ - test/myapp/app/controllers/application_controller.rb
192
+ - test/myapp/app/controllers/main_controller.rb
193
+ - test/myapp/config/boot.rb
194
+ - test/myapp/config/environment.rb
195
+ - test/myapp/config/environments/production.rb
196
+ - test/myapp/config/routes.rb
197
+ - test/passenger_test.rb
198
+ - test/playground_test.rb
199
+ - test/rails_dashboard_test.rb
200
+ - test/rails_helper_test.rb
201
+ - test/rails_test.rb
202
+ - test/test_helper.rb