vanity 2.0.0.beta4 → 2.0.0.beta5

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 (42) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +4 -0
  3. data/Appraisals +14 -0
  4. data/Gemfile +2 -2
  5. data/Gemfile.lock +5 -3
  6. data/README.rdoc +5 -1
  7. data/config/locales/vanity.en.yml +39 -0
  8. data/config/locales/vanity.pt-BR.yml +41 -0
  9. data/doc/ab_testing.textile +1 -1
  10. data/doc/rails.textile +13 -0
  11. data/gemfiles/rails32.gemfile +2 -2
  12. data/gemfiles/rails32.gemfile.lock +4 -3
  13. data/gemfiles/rails4.gemfile +2 -2
  14. data/gemfiles/rails4.gemfile.lock +4 -3
  15. data/gemfiles/rails41.gemfile +29 -0
  16. data/gemfiles/rails41.gemfile.lock +196 -0
  17. data/gemfiles/rails42.gemfile +29 -0
  18. data/gemfiles/rails42.gemfile.lock +235 -0
  19. data/lib/generators/templates/vanity_migration.rb +1 -1
  20. data/lib/generators/vanity/views_generator.rb +16 -0
  21. data/lib/vanity.rb +1 -0
  22. data/lib/vanity/experiment/ab_test.rb +15 -15
  23. data/lib/vanity/experiment/alternative.rb +2 -2
  24. data/lib/vanity/frameworks/rails.rb +16 -3
  25. data/lib/vanity/metric/active_record.rb +1 -1
  26. data/lib/vanity/playground.rb +19 -25
  27. data/lib/vanity/templates.rb +29 -0
  28. data/lib/vanity/templates/_ab_test.erb +12 -12
  29. data/lib/vanity/templates/_experiment.erb +4 -2
  30. data/lib/vanity/templates/_participant.erb +2 -2
  31. data/lib/vanity/templates/_report.erb +6 -6
  32. data/lib/vanity/templates/_vanity.js.erb +13 -15
  33. data/lib/vanity/templates/vanity.css +4 -4
  34. data/lib/vanity/version.rb +1 -1
  35. data/test/frameworks/rails/action_controller_test.rb +1 -1
  36. data/test/frameworks/rails/rails_test.rb +118 -102
  37. data/test/playground_test.rb +13 -0
  38. data/test/templates_test.rb +28 -0
  39. data/test/test_helper.rb +15 -17
  40. data/test/web/rails/dashboard_test.rb +25 -4
  41. data/vanity.gemspec +2 -0
  42. metadata +36 -18
@@ -99,6 +99,19 @@ describe Vanity::Playground do
99
99
  end
100
100
  end
101
101
 
102
+ describe "#experiments" do
103
+ it "saves experiments exactly once" do
104
+ File.open "tmp/experiments/foobar.rb", "w" do |f|
105
+ f.write <<-RUBY
106
+ ab_test :foobar do
107
+ end
108
+ RUBY
109
+ end
110
+ Vanity::Experiment::AbTest.any_instance.expects(:save).once
111
+ Vanity.playground.experiments
112
+ end
113
+ end
114
+
102
115
  describe "participant_info" do
103
116
  it "returns participant's experiments" do
104
117
  assert_equal [], Vanity.playground.participant_info("abcdef")
@@ -0,0 +1,28 @@
1
+ require "test_helper"
2
+
3
+ describe Vanity::Templates do
4
+ describe "template" do
5
+ it "resolves templates from the gem by default" do
6
+ custom_view_path = File.expand_path(File.join(Rails.root, 'app', 'views', 'vanity'))
7
+ gem_view_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'vanity', 'templates'))
8
+ expected = File.join(gem_view_path, 'foo.html')
9
+
10
+ assert_equal expected, Vanity::Templates.new.path('foo.html')
11
+ end
12
+
13
+ it "resolves templates from the Rails view directory if it exists" do
14
+ begin
15
+ custom_view_path = File.expand_path(File.join(Rails.root, 'app', 'views', 'vanity'))
16
+
17
+ expected = File.expand_path(File.join(custom_view_path, 'foo.html'))
18
+
19
+ FileUtils.mkpath(custom_view_path)
20
+ File.open(expected, "w")
21
+
22
+ assert_equal expected, Vanity::Templates.new.path('foo.html')
23
+ ensure
24
+ FileUtils.rm_rf(custom_view_path)
25
+ end
26
+ end
27
+ end
28
+ end
data/test/test_helper.rb CHANGED
@@ -3,8 +3,7 @@ $LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__))
3
3
  ENV["RACK_ENV"] = "test"
4
4
  ENV["DB"] ||= "redis"
5
5
 
6
- require "minitest/unit"
7
- require "minitest/spec"
6
+ require "minitest/autorun"
8
7
  require "tmpdir"
9
8
  require "action_controller"
10
9
  require "action_controller/test_case"
@@ -27,7 +26,7 @@ if defined?(Mocha::VERSION) && Mocha::VERSION < "0.13.0"
27
26
  else
28
27
  require "mocha/mini_test"
29
28
  end
30
- require "webmock/test_unit"
29
+ require "webmock/minitest"
31
30
 
32
31
  # Due to load order differences in Rails boot and test requires we have to
33
32
  # manually require these
@@ -124,40 +123,39 @@ module VanityTestHelpers
124
123
  end
125
124
  end
126
125
 
127
- class Test::Unit::TestCase
128
- include WebMock::API
129
- include VanityTestHelpers
126
+ if defined?(Test)
127
+ class Test::Unit::TestCase
128
+ include VanityTestHelpers
129
+ end
130
130
  end
131
131
 
132
132
  class MiniTest::Spec
133
- include WebMock::API
134
133
  include VanityTestHelpers
135
134
  end
136
135
 
137
136
  if defined?(MiniTest::Unit::TestCase)
138
137
  class MiniTest::Unit::TestCase
139
- include WebMock::API
140
138
  include VanityTestHelpers
141
139
  end
142
140
  end
143
141
 
144
142
  if defined?(ActiveSupport::TestCase)
145
143
  class ActiveSupport::TestCase
144
+ include VanityTestHelpers
145
+
146
146
  self.use_instantiated_fixtures = false if respond_to?(:use_instantiated_fixtures)
147
147
  self.use_transactional_fixtures = false if respond_to?(:use_transactional_fixtures)
148
148
  end
149
149
  end
150
150
 
151
151
  if defined?(ActionController::TestCase)
152
- module ActionController
153
- class TestCase
154
- alias :setup_controller_request_and_response_without_vanity :setup_controller_request_and_response
155
- # Sets Vanity.context to the current controller, so you can do things like:
156
- # experiment(:simple).chooses(:green)
157
- def setup_controller_request_and_response
158
- setup_controller_request_and_response_without_vanity
159
- Vanity.context = @controller
160
- end
152
+ class ActionController::TestCase
153
+ alias :setup_controller_request_and_response_without_vanity :setup_controller_request_and_response
154
+ # Sets Vanity.context to the current controller, so you can do things like:
155
+ # experiment(:simple).chooses(:green)
156
+ def setup_controller_request_and_response
157
+ setup_controller_request_and_response_without_vanity
158
+ Vanity.context = @controller
161
159
  end
162
160
  end
163
161
  end
@@ -16,6 +16,13 @@ class RailsDashboardTest < ActionController::TestCase
16
16
  metrics :sugar_high
17
17
  identify { '1' }
18
18
  end
19
+
20
+ metric :liquidity
21
+ new_ab_test :drink do
22
+ alternatives :tea, :coffee
23
+ metrics :liquidity
24
+ identify { '1' }
25
+ end
19
26
  end
20
27
 
21
28
  # -- Test dashboard --
@@ -51,15 +58,23 @@ class RailsDashboardTest < ActionController::TestCase
51
58
  # -- Actions used in non-admin actions, e.g. in JS --
52
59
 
53
60
  def test_add_participant
54
- xhr :post, :add_participant, :e => "food", :a => 0
61
+ xhr :post, :add_participant, :v => 'food=0'
62
+ assert_response :success
63
+ assert @response.body.blank?
64
+ assert_equal 1, experiment(:food).alternatives.map(&:participants).sum
65
+ end
66
+
67
+ def test_add_participant_multiple_experiments
68
+ xhr :post, :add_participant, :v => 'food=0,drink=1'
55
69
  assert_response :success
56
70
  assert @response.body.blank?
57
71
  assert_equal 1, experiment(:food).alternatives.map(&:participants).sum
72
+ assert_equal 1, experiment(:drink).alternatives.map(&:participants).sum
58
73
  end
59
74
 
60
75
  def test_add_participant_with_invalid_request
61
- @request.user_agent = "Googlebot/2.1 ( http://www.google.com/bot.html)"
62
- xhr :post, :add_participant, :e => "food", :a => 0
76
+ @request.user_agent = 'Googlebot/2.1 ( http://www.google.com/bot.html)'
77
+ xhr :post, :add_participant, :v => 'food=0'
63
78
  assert_equal 0, experiment(:food).alternatives.map(&:participants).sum
64
79
  end
65
80
 
@@ -69,6 +84,12 @@ class RailsDashboardTest < ActionController::TestCase
69
84
  assert @response.body.blank?
70
85
  end
71
86
 
87
+ def test_add_participant_not_fail_for_unknown_experiment
88
+ xhr :post, :add_participant, :e => 'unknown=0'
89
+ assert_response :not_found
90
+ assert @response.body.blank?
91
+ end
92
+
72
93
  # -- Test administrator actions --
73
94
 
74
95
  def test_participant_renders_experiment_for_id
@@ -99,7 +120,7 @@ class RailsDashboardTest < ActionController::TestCase
99
120
  def test_complete_with_confirmation_completes
100
121
  xhr :post, :complete, :e => "food", :a => 0, :confirmed => 'true'
101
122
  assert_response :success
102
- assert !Vanity.playground.experiment('food').active?
123
+ assert !Vanity.playground.experiment(:food).active?
103
124
  end
104
125
 
105
126
  def test_chooses
data/vanity.gemspec CHANGED
@@ -23,6 +23,8 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.required_ruby_version = ">= 1.9.3"
25
25
 
26
+ spec.add_runtime_dependency "i18n"
27
+
26
28
  spec.add_development_dependency "bundler", ">= 1.0.0"
27
29
  spec.add_development_dependency "minitest", ">= 4.2"
28
30
  end
metadata CHANGED
@@ -1,46 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanity
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta4
5
- prerelease: 6
4
+ version: 2.0.0.beta5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Assaf Arkin
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-08-26 00:00:00.000000000 Z
11
+ date: 2015-01-25 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: bundler
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
- - - ! '>='
31
+ - - '>='
20
32
  - !ruby/object:Gem::Version
21
33
  version: 1.0.0
22
34
  type: :development
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
- - - ! '>='
38
+ - - '>='
28
39
  - !ruby/object:Gem::Version
29
40
  version: 1.0.0
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: minitest
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - '>='
36
46
  - !ruby/object:Gem::Version
37
47
  version: '4.2'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - '>='
44
53
  - !ruby/object:Gem::Version
45
54
  version: '4.2'
46
55
  description: Mirror, mirror on the wall ...
@@ -63,6 +72,8 @@ files:
63
72
  - README.rdoc
64
73
  - Rakefile
65
74
  - bin/vanity
75
+ - config/locales/vanity.en.yml
76
+ - config/locales/vanity.pt-BR.yml
66
77
  - doc/_config.yml
67
78
  - doc/_layouts/_header.html
68
79
  - doc/_layouts/page.html
@@ -92,7 +103,12 @@ files:
92
103
  - gemfiles/rails32.gemfile.lock
93
104
  - gemfiles/rails4.gemfile
94
105
  - gemfiles/rails4.gemfile.lock
106
+ - gemfiles/rails41.gemfile
107
+ - gemfiles/rails41.gemfile.lock
108
+ - gemfiles/rails42.gemfile
109
+ - gemfiles/rails42.gemfile.lock
95
110
  - lib/generators/templates/vanity_migration.rb
111
+ - lib/generators/vanity/views_generator.rb
96
112
  - lib/generators/vanity_generator.rb
97
113
  - lib/vanity.rb
98
114
  - lib/vanity/adapters/abstract_adapter.rb
@@ -118,6 +134,7 @@ files:
118
134
  - lib/vanity/metric/google_analytics.rb
119
135
  - lib/vanity/metric/remote.rb
120
136
  - lib/vanity/playground.rb
137
+ - lib/vanity/templates.rb
121
138
  - lib/vanity/templates/_ab_test.erb
122
139
  - lib/vanity/templates/_experiment.erb
123
140
  - lib/vanity/templates/_experiments.erb
@@ -172,16 +189,18 @@ files:
172
189
  - test/metric/google_analytics_test.rb
173
190
  - test/metric/remote_test.rb
174
191
  - test/playground_test.rb
192
+ - test/templates_test.rb
175
193
  - test/test_helper.rb
176
194
  - test/web/rails/dashboard_test.rb
177
195
  - vanity.gemspec
178
196
  homepage: http://vanity.labnotes.org
179
197
  licenses:
180
198
  - MIT
199
+ metadata: {}
181
200
  post_install_message: To get started run vanity --help
182
201
  rdoc_options:
183
202
  - --title
184
- - Vanity 2.0.0.beta4
203
+ - Vanity 2.0.0.beta5
185
204
  - --main
186
205
  - README.rdoc
187
206
  - --webcvs
@@ -189,22 +208,20 @@ rdoc_options:
189
208
  require_paths:
190
209
  - lib
191
210
  required_ruby_version: !ruby/object:Gem::Requirement
192
- none: false
193
211
  requirements:
194
- - - ! '>='
212
+ - - '>='
195
213
  - !ruby/object:Gem::Version
196
214
  version: 1.9.3
197
215
  required_rubygems_version: !ruby/object:Gem::Requirement
198
- none: false
199
216
  requirements:
200
- - - ! '>'
217
+ - - '>'
201
218
  - !ruby/object:Gem::Version
202
219
  version: 1.3.1
203
220
  requirements: []
204
221
  rubyforge_project:
205
- rubygems_version: 1.8.23
222
+ rubygems_version: 2.1.5
206
223
  signing_key:
207
- specification_version: 3
224
+ specification_version: 4
208
225
  summary: Experience Driven Development framework for Ruby
209
226
  test_files:
210
227
  - test/adapters/redis_adapter_test.rb
@@ -248,6 +265,7 @@ test_files:
248
265
  - test/metric/google_analytics_test.rb
249
266
  - test/metric/remote_test.rb
250
267
  - test/playground_test.rb
268
+ - test/templates_test.rb
251
269
  - test/test_helper.rb
252
270
  - test/web/rails/dashboard_test.rb
253
271
  has_rdoc: