vanity 2.0.0.beta → 2.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/gemfiles/rails32.gemfile.lock +1 -1
- data/gemfiles/rails4.gemfile.lock +1 -1
- data/lib/vanity/playground.rb +1 -51
- data/lib/vanity/templates/vanity.css +1 -1
- data/lib/vanity/version.rb +1 -1
- data/test/frameworks/rails/action_mailer_test.rb +14 -17
- data/test/frameworks/rails/rails_test.rb +0 -7
- data/test/playground_test.rb +80 -64
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/lib/vanity/playground.rb
CHANGED
@@ -18,7 +18,6 @@ module Vanity
|
|
18
18
|
# First argument is connection specification (see #redis=), last argument is
|
19
19
|
# a set of options, both are optional. Supported options are:
|
20
20
|
# - connection -- Connection specification
|
21
|
-
# - namespace -- Namespace to use
|
22
21
|
# - load_path -- Path to load experiments/metrics from
|
23
22
|
# - logger -- Logger to use
|
24
23
|
# - redis -- A Redis object that will be used for the connection
|
@@ -41,7 +40,6 @@ module Vanity
|
|
41
40
|
|
42
41
|
@options = defaults.merge(config).merge(options)
|
43
42
|
|
44
|
-
warn "Deprecated: namespace option no longer supported directly" if @options[:namespace]
|
45
43
|
@load_path = @options[:load_path] || DEFAULTS[:load_path]
|
46
44
|
unless @logger = @options[:logger]
|
47
45
|
@logger = Logger.new(STDOUT)
|
@@ -57,9 +55,6 @@ module Vanity
|
|
57
55
|
@collecting = !!@options[:collecting]
|
58
56
|
end
|
59
57
|
|
60
|
-
# Deprecated. Use redis.server instead.
|
61
|
-
attr_accessor :host, :port, :db, :password, :namespace
|
62
|
-
|
63
58
|
# Path to load experiment files from.
|
64
59
|
attr_accessor :load_path
|
65
60
|
|
@@ -417,39 +412,10 @@ module Vanity
|
|
417
412
|
establish_connection(@spec)
|
418
413
|
end
|
419
414
|
|
420
|
-
# Deprecated. Use Vanity.playground.collecting = true/false instead.
|
421
|
-
def test!
|
422
|
-
warn "Deprecated: use collecting = false instead"
|
423
|
-
self.collecting = false
|
424
|
-
end
|
425
|
-
|
426
|
-
# Deprecated. Use establish_connection or configuration file instead.
|
427
|
-
def redis=(spec_or_connection)
|
428
|
-
warn "Deprecated: use establish_connection method instead"
|
429
|
-
case spec_or_connection
|
430
|
-
when String
|
431
|
-
establish_connection "redis://" + spec_or_connection
|
432
|
-
when ::Redis
|
433
|
-
@connection = Adapters::RedisAdapter.new(spec_or_connection)
|
434
|
-
when :mock
|
435
|
-
establish_connection :adapter=>:mock
|
436
|
-
else
|
437
|
-
raise "I don't know what to do with #{spec_or_connection.inspect}"
|
438
|
-
end
|
439
|
-
end
|
440
|
-
|
441
|
-
def redis
|
442
|
-
warn "Deprecated: use connection method instead"
|
443
|
-
connection
|
444
|
-
end
|
445
|
-
|
446
415
|
protected
|
447
416
|
|
448
417
|
def autoconnect(options, arguments)
|
449
|
-
if options[:
|
450
|
-
warn "Deprecated: please specify Redis connection as URL (\"redis://host:port/db\")"
|
451
|
-
establish_connection :adapter=>"redis", :host=>options[:host], :port=>options[:port], :database=>options[:db] || options[:database]
|
452
|
-
elsif options[:redis]
|
418
|
+
if options[:redis]
|
453
419
|
@adapter = RedisAdapter.new(:redis=>options[:redis])
|
454
420
|
else
|
455
421
|
connection_spec = arguments.shift || options[:connection]
|
@@ -496,19 +462,3 @@ module Vanity
|
|
496
462
|
end
|
497
463
|
end
|
498
464
|
end
|
499
|
-
|
500
|
-
|
501
|
-
class Object
|
502
|
-
|
503
|
-
# Use this method to access an experiment by name.
|
504
|
-
#
|
505
|
-
# @example
|
506
|
-
# puts experiment(:text_size).alternatives
|
507
|
-
#
|
508
|
-
# @see Vanity::Playground#experiment
|
509
|
-
# @deprecated
|
510
|
-
def experiment(name)
|
511
|
-
warn "Deprecated. Please call Vanity.playground.experiment directly."
|
512
|
-
Vanity.playground.experiment(name)
|
513
|
-
end
|
514
|
-
end
|
@@ -13,7 +13,7 @@
|
|
13
13
|
.vanity .ab_test .choice td { font-weight: bold; background: #f0f0f8 }
|
14
14
|
.vanity .ab_test caption { caption-side: bottom; padding: .5em; background: transparent; text-align: left }
|
15
15
|
.vanity .ab_test td.option { width: 5em; white-space: nowrap; overflow: hidden }
|
16
|
-
.vanity .ab_test td.value { width: 8em;
|
16
|
+
.vanity .ab_test td.value { width: 8em; overflow: hidden }
|
17
17
|
.vanity .ab_test td.action { width: 6em; overflow: hidden; text-align: right }
|
18
18
|
|
19
19
|
.vanity .metrics { list-style: none; margin: 0; padding: 0; border-bottom: 1px solid #ddd }
|
data/lib/vanity/version.rb
CHANGED
@@ -5,27 +5,17 @@ class VanityMailer < ActionMailer::Base
|
|
5
5
|
include ActionView::Helpers::AssetTagHelper
|
6
6
|
include ActionView::Helpers::TagHelper
|
7
7
|
|
8
|
-
def ab_test_subject(user
|
8
|
+
def ab_test_subject(user)
|
9
9
|
use_vanity_mailer user
|
10
|
-
experiment(:pie_or_cake).chooses(forced_outcome)
|
11
10
|
|
12
|
-
|
13
|
-
mail :subject =>ab_test(:pie_or_cake).to_s, :body => ""
|
14
|
-
else
|
15
|
-
subject ab_test(:pie_or_cake).to_s
|
16
|
-
body ""
|
17
|
-
end
|
11
|
+
mail :subject =>ab_test(:pie_or_cake).to_s, :body => ""
|
18
12
|
end
|
19
13
|
|
20
14
|
def ab_test_content(user)
|
21
15
|
use_vanity_mailer user
|
22
16
|
|
23
|
-
|
24
|
-
|
25
|
-
format.html { render :text=>view_context.vanity_tracking_image(Vanity.context.vanity_identity, :open, :host => "127.0.0.1:3000") }
|
26
|
-
end
|
27
|
-
else
|
28
|
-
body vanity_tracking_image(Vanity.context.vanity_identity, :open, :host => "127.0.0.1:3000")
|
17
|
+
mail do |format|
|
18
|
+
format.html { render :text=>view_context.vanity_tracking_image(Vanity.context.vanity_identity, :open, :host => "127.0.0.1:3000") }
|
29
19
|
end
|
30
20
|
end
|
31
21
|
end
|
@@ -43,17 +33,24 @@ class UseVanityMailerTest < ActionMailer::TestCase
|
|
43
33
|
|
44
34
|
def test_js_enabled_still_adds_participant
|
45
35
|
Vanity.playground.use_js!
|
46
|
-
|
36
|
+
experiment(:pie_or_cake).identify { }
|
37
|
+
experiment(:pie_or_cake).chooses(true)
|
38
|
+
VanityMailer.ab_test_subject(nil)
|
39
|
+
|
47
40
|
|
48
41
|
alts = experiment(:pie_or_cake).alternatives
|
49
42
|
assert_equal 1, alts.map(&:participants).sum
|
50
43
|
end
|
51
44
|
|
52
45
|
def test_returns_different_alternatives
|
53
|
-
|
46
|
+
experiment(:pie_or_cake).identify { }
|
47
|
+
|
48
|
+
experiment(:pie_or_cake).chooses(true)
|
49
|
+
email = VanityMailer.ab_test_subject(nil)
|
54
50
|
assert_equal 'true', email.subject
|
55
51
|
|
56
|
-
|
52
|
+
experiment(:pie_or_cake).chooses(false)
|
53
|
+
email = VanityMailer.ab_test_subject(nil)
|
57
54
|
assert_equal 'false', email.subject
|
58
55
|
end
|
59
56
|
|
@@ -211,13 +211,6 @@ $stdout << Vanity.playground.collecting?
|
|
211
211
|
RB
|
212
212
|
end
|
213
213
|
|
214
|
-
def test_collection_false_after_test!
|
215
|
-
assert_equal "false", load_rails("", <<-RB)
|
216
|
-
Vanity.playground.test!
|
217
|
-
$stdout << Vanity.playground.collecting?
|
218
|
-
RB
|
219
|
-
end
|
220
|
-
|
221
214
|
def test_playground_loads_if_connected
|
222
215
|
assert_equal "{}", load_rails("", <<-RB)
|
223
216
|
$stdout << Vanity.playground.instance_variable_get(:@experiments).inspect
|
data/test/playground_test.rb
CHANGED
@@ -1,98 +1,114 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
|
-
|
3
|
+
describe Vanity::Playground do
|
4
4
|
|
5
|
-
|
5
|
+
it "has one global instance" do
|
6
6
|
assert instance = Vanity.playground
|
7
7
|
assert_equal instance, Vanity.playground
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
describe "#use_js!" do
|
11
|
+
it "sets via use_js" do
|
12
|
+
assert !Vanity.playground.using_js?
|
13
|
+
Vanity.playground.use_js!
|
14
|
+
assert Vanity.playground.using_js?
|
15
|
+
end
|
14
16
|
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
describe "#failover_on_datastore_error" do
|
19
|
+
it "sets failover_on_datastore_error" do
|
20
|
+
assert !Vanity.playground.failover_on_datastore_error?
|
21
|
+
Vanity.playground.failover_on_datastore_error!
|
22
|
+
assert Vanity.playground.failover_on_datastore_error?
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
describe "#on_datastore_error" do
|
27
|
+
it "has a default failover_on_datastore_error" do
|
28
|
+
proc = Vanity.playground.on_datastore_error
|
29
|
+
assert proc.respond_to?(:call)
|
30
|
+
assert_silent do
|
31
|
+
proc.call(Exception.new("datastore error"), self.class, caller[0][/`.*'/][1..-2], [1, 2, 3])
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
36
|
+
describe "#request_filter" do
|
37
|
+
it "sets request_filter" do
|
38
|
+
proc = Vanity.playground.request_filter
|
39
|
+
assert proc.respond_to?(:call)
|
40
|
+
assert_silent do
|
41
|
+
proc.call(dummy_request)
|
42
|
+
end
|
35
43
|
end
|
36
44
|
end
|
37
45
|
|
38
|
-
|
39
|
-
|
46
|
+
describe "#add_participant_path" do
|
47
|
+
it "sets a default add participant path" do
|
48
|
+
assert_equal Vanity.playground.add_participant_path, Vanity::Playground::DEFAULT_ADD_PARTICIPANT_PATH
|
49
|
+
end
|
40
50
|
end
|
41
51
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
52
|
+
describe "autoconnect" do
|
53
|
+
it "reconnects with existing connection" do
|
54
|
+
Vanity.playground.establish_connection "mock:/"
|
55
|
+
Vanity.playground.reconnect!
|
56
|
+
assert_equal Vanity.playground.connection.to_s, "mock:/"
|
57
|
+
end
|
47
58
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
59
|
+
it "establishes connection by default with connection" do
|
60
|
+
instance = Vanity::Playground.new(:connection=>"mock:/")
|
61
|
+
assert instance.connected?
|
62
|
+
end
|
52
63
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
64
|
+
it "establishes connection by default" do
|
65
|
+
Vanity::Playground.any_instance.expects(:establish_connection)
|
66
|
+
Vanity::Playground.new
|
67
|
+
end
|
57
68
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
69
|
+
it "can skip connection" do
|
70
|
+
Vanity::Autoconnect.stubs(:playground_should_autoconnect?).returns(false)
|
71
|
+
instance = Vanity::Playground.new(:connection=>"mock:/")
|
72
|
+
assert !instance.connected?
|
73
|
+
end
|
62
74
|
end
|
63
75
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
76
|
+
describe "experiments_persisted?" do
|
77
|
+
it "returns true" do
|
78
|
+
metric "Coolness"
|
79
|
+
new_ab_test :foobar do
|
80
|
+
alternatives "foo", "bar"
|
81
|
+
identify { "abcdef" }
|
82
|
+
metrics :coolness
|
83
|
+
end
|
71
84
|
|
72
|
-
|
73
|
-
|
85
|
+
assert Vanity.playground.experiments_persisted?
|
86
|
+
end
|
74
87
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
88
|
+
it "returns false" do
|
89
|
+
name = 'Price'
|
90
|
+
id = :price
|
91
|
+
experiment = Vanity::Experiment::AbTest.new(Vanity.playground, id, name)
|
92
|
+
Vanity.playground.experiments[id] = experiment
|
80
93
|
|
81
|
-
|
94
|
+
assert !Vanity.playground.experiments_persisted?
|
82
95
|
|
83
|
-
|
96
|
+
Vanity.playground.experiments.delete(id)
|
97
|
+
end
|
84
98
|
end
|
85
99
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
100
|
+
describe "participant_info" do
|
101
|
+
it "returns participant's experiments" do
|
102
|
+
assert_equal [], Vanity.playground.participant_info("abcdef")
|
103
|
+
metric "Coolness"
|
104
|
+
new_ab_test :foobar do
|
105
|
+
alternatives "foo", "bar"
|
106
|
+
identify { "abcdef" }
|
107
|
+
metrics :coolness
|
108
|
+
end
|
109
|
+
alt = experiment(:foobar).choose
|
110
|
+
assert_equal [[Vanity.playground.experiment(:foobar), alt]], Vanity.playground.participant_info("abcdef")
|
93
111
|
end
|
94
|
-
alt = experiment(:foobar).choose
|
95
|
-
assert_equal [[Vanity.playground.experiment(:foobar), alt]], Vanity.playground.participant_info("abcdef")
|
96
112
|
end
|
97
113
|
|
98
114
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vanity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.beta2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -186,7 +186,7 @@ licenses:
|
|
186
186
|
post_install_message: To get started run vanity --help
|
187
187
|
rdoc_options:
|
188
188
|
- --title
|
189
|
-
- Vanity 2.0.0.
|
189
|
+
- Vanity 2.0.0.beta2
|
190
190
|
- --main
|
191
191
|
- README.rdoc
|
192
192
|
- --webcvs
|