split 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.mdown +11 -0
- data/lib/split.rb +3 -9
- data/lib/split/engine.rb +8 -0
- data/lib/split/experiment.rb +4 -1
- data/lib/split/helper.rb +13 -3
- data/lib/split/version.rb +4 -1
- data/spec/experiment_spec.rb +1 -1
- data/spec/helper_spec.rb +31 -37
- metadata +19 -18
data/CHANGELOG.mdown
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## 0.4.6 (October 28, 2012)
|
2
|
+
|
3
|
+
Features:
|
4
|
+
|
5
|
+
- General code quality improvements (@buddhamagnet, #79)
|
6
|
+
|
7
|
+
Bugfixes:
|
8
|
+
|
9
|
+
- Don't increment the experiment counter if user has finished (@dimko, #78)
|
10
|
+
- Fixed an incorrect test (@jaywengrow, #74)
|
11
|
+
|
1
12
|
## 0.4.5 (August 30, 2012)
|
2
13
|
|
3
14
|
Bugfixes:
|
data/lib/split.rb
CHANGED
@@ -3,6 +3,7 @@ require 'split/alternative'
|
|
3
3
|
require 'split/helper'
|
4
4
|
require 'split/version'
|
5
5
|
require 'split/configuration'
|
6
|
+
require 'split/engine' if defined?(Rails)
|
6
7
|
require 'redis/namespace'
|
7
8
|
|
8
9
|
module Split
|
@@ -18,7 +19,7 @@ module Split
|
|
18
19
|
# or `Redis::Namespace`.
|
19
20
|
def redis=(server)
|
20
21
|
if server.respond_to? :split
|
21
|
-
if server
|
22
|
+
if server["redis://"]
|
22
23
|
redis = Redis.connect(:url => server, :thread_safe => true)
|
23
24
|
else
|
24
25
|
server, namespace = server.split('/', 2)
|
@@ -56,11 +57,4 @@ module Split
|
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
59
|
-
Split.configure {}
|
60
|
-
|
61
|
-
if defined?(Rails)
|
62
|
-
class ActionController::Base
|
63
|
-
ActionController::Base.send :include, Split::Helper
|
64
|
-
ActionController::Base.helper Split::Helper
|
65
|
-
end
|
66
|
-
end
|
60
|
+
Split.configure {}
|
data/lib/split/engine.rb
ADDED
data/lib/split/experiment.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Split
|
2
2
|
class Experiment
|
3
3
|
attr_accessor :name
|
4
|
-
attr_accessor :winner
|
5
4
|
|
6
5
|
def initialize(name, *alternative_names)
|
7
6
|
@name = name.to_s
|
@@ -75,6 +74,10 @@ module Split
|
|
75
74
|
end
|
76
75
|
end
|
77
76
|
|
77
|
+
def finished_key
|
78
|
+
"#{key}:finished"
|
79
|
+
end
|
80
|
+
|
78
81
|
def reset
|
79
82
|
alternatives.each(&:reset)
|
80
83
|
reset_winner
|
data/lib/split/helper.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
module Split
|
2
2
|
module Helper
|
3
3
|
def ab_test(experiment_name, control, *alternatives)
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
if RUBY_VERSION.match(/1\.8/) && alternatives.length.zero?
|
6
|
+
puts 'WARNING: You should always pass the control alternative through as the second argument with any other alternatives as the third because the order of the hash is not preserved in ruby 1.8'
|
7
|
+
end
|
8
|
+
|
6
9
|
ret = if Split.configuration.enabled
|
7
10
|
experiment_variable(alternatives, control, experiment_name)
|
8
11
|
else
|
@@ -25,10 +28,17 @@ module Split
|
|
25
28
|
def finished(experiment_name, options = {:reset => true})
|
26
29
|
return if exclude_visitor? or !Split.configuration.enabled
|
27
30
|
return unless (experiment = Split::Experiment.find(experiment_name))
|
31
|
+
return if !options[:reset] && ab_user[experiment.finished_key]
|
32
|
+
|
28
33
|
if alternative_name = ab_user[experiment.key]
|
29
34
|
alternative = Split::Alternative.new(alternative_name, experiment_name)
|
30
35
|
alternative.increment_completion
|
31
|
-
|
36
|
+
|
37
|
+
if options[:reset]
|
38
|
+
ab_user.delete(experiment.key)
|
39
|
+
else
|
40
|
+
ab_user[experiment.finished_key] = true
|
41
|
+
end
|
32
42
|
end
|
33
43
|
rescue => e
|
34
44
|
raise unless Split.configuration.db_failover
|
data/lib/split/version.rb
CHANGED
data/spec/experiment_spec.rb
CHANGED
@@ -55,7 +55,7 @@ describe Split::Experiment do
|
|
55
55
|
|
56
56
|
experiment.delete
|
57
57
|
Split.redis.exists('basket_text').should be false
|
58
|
-
Split::Experiment.find('
|
58
|
+
Split::Experiment.find('basket_text').should be_nil
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should increment the version" do
|
data/spec/helper_spec.rb
CHANGED
@@ -99,61 +99,55 @@ describe Split::Helper do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
describe 'finished' do
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
102
|
+
before(:each) do
|
103
|
+
@experiment_name = 'link_color'
|
104
|
+
@alternatives = ['blue', 'red']
|
105
|
+
@experiment = Split::Experiment.find_or_create(@experiment_name, *@alternatives)
|
106
|
+
@alternative_name = ab_test(@experiment_name, *@alternatives)
|
107
|
+
@previous_completion_count = Split::Alternative.new(@alternative_name, @experiment_name).completed_count
|
108
|
+
end
|
107
109
|
|
108
|
-
|
110
|
+
it 'should increment the counter for the completed alternative' do
|
111
|
+
finished(@experiment_name)
|
112
|
+
new_completion_count = Split::Alternative.new(@alternative_name, @experiment_name).completed_count
|
113
|
+
new_completion_count.should eql(@previous_completion_count + 1)
|
114
|
+
end
|
109
115
|
|
110
|
-
|
116
|
+
it "should set experiment's finished key if reset is false" do
|
117
|
+
finished(@experiment_name, :reset => false)
|
118
|
+
session[:split].should eql(@experiment.key => @alternative_name, @experiment.finished_key => true)
|
119
|
+
end
|
111
120
|
|
112
|
-
|
121
|
+
it 'should not increment the counter if reset is false and the experiment has been already finished' do
|
122
|
+
2.times { finished(@experiment_name, :reset => false) }
|
123
|
+
new_completion_count = Split::Alternative.new(@alternative_name, @experiment_name).completed_count
|
124
|
+
new_completion_count.should eql(@previous_completion_count + 1)
|
113
125
|
end
|
114
126
|
|
115
127
|
it "should clear out the user's participation from their session" do
|
116
|
-
experiment
|
117
|
-
|
118
|
-
|
119
|
-
previous_completion_count = Split::Alternative.new(alternative_name, 'link_color').completed_count
|
120
|
-
|
121
|
-
session[:split].should eql("link_color" => alternative_name)
|
122
|
-
finished('link_color')
|
128
|
+
session[:split].should eql(@experiment.key => @alternative_name)
|
129
|
+
finished(@experiment_name)
|
123
130
|
session[:split].should == {}
|
124
131
|
end
|
125
132
|
|
126
133
|
it "should not clear out the users session if reset is false" do
|
127
|
-
experiment
|
128
|
-
|
129
|
-
|
130
|
-
previous_completion_count = Split::Alternative.new(alternative_name, 'link_color').completed_count
|
131
|
-
|
132
|
-
session[:split].should eql("link_color" => alternative_name)
|
133
|
-
finished('link_color', :reset => false)
|
134
|
-
session[:split].should eql("link_color" => alternative_name)
|
134
|
+
session[:split].should eql(@experiment.key => @alternative_name)
|
135
|
+
finished(@experiment_name, :reset => false)
|
136
|
+
session[:split].should eql(@experiment.key => @alternative_name, @experiment.finished_key => true)
|
135
137
|
end
|
136
138
|
|
137
139
|
it "should reset the users session when experiment is not versioned" do
|
138
|
-
experiment
|
139
|
-
|
140
|
-
|
141
|
-
previous_completion_count = Split::Alternative.new(alternative_name, 'link_color').completed_count
|
142
|
-
|
143
|
-
session[:split].should eql(experiment.key => alternative_name)
|
144
|
-
finished('link_color', :reset => true)
|
140
|
+
session[:split].should eql(@experiment.key => @alternative_name)
|
141
|
+
finished(@experiment_name)
|
145
142
|
session[:split].should eql({})
|
146
143
|
end
|
147
144
|
|
148
145
|
it "should reset the users session when experiment is versioned" do
|
149
|
-
experiment
|
150
|
-
|
151
|
-
alternative_name = ab_test('link_color', 'blue', 'red')
|
152
|
-
|
153
|
-
previous_completion_count = Split::Alternative.new(alternative_name, 'link_color').completed_count
|
146
|
+
@experiment.increment_version
|
147
|
+
@alternative_name = ab_test(@experiment_name, *@alternatives)
|
154
148
|
|
155
|
-
session[:split].should eql(experiment.key => alternative_name)
|
156
|
-
finished(
|
149
|
+
session[:split].should eql(@experiment.key => @alternative_name)
|
150
|
+
finished(@experiment_name)
|
157
151
|
session[:split].should eql({})
|
158
152
|
end
|
159
153
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: split
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
16
|
-
requirement: &
|
16
|
+
requirement: &70093446916440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70093446916440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: redis-namespace
|
27
|
-
requirement: &
|
27
|
+
requirement: &70093446931800 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.1.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70093446931800
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sinatra
|
38
|
-
requirement: &
|
38
|
+
requirement: &70093446947900 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.2.6
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70093446947900
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &70093446950180 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70093446950180
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bundler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70093447002840 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '1.0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70093447002840
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70093447013900 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '2.6'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70093447013900
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rack-test
|
82
|
-
requirement: &
|
82
|
+
requirement: &70093447010320 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0.6'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70093447010320
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: guard-rspec
|
93
|
-
requirement: &
|
93
|
+
requirement: &70093447018620 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '1.2'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70093447018620
|
102
102
|
description:
|
103
103
|
email:
|
104
104
|
- andrewnez@gmail.com
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- lib/split/dashboard/views/_experiment.erb
|
126
126
|
- lib/split/dashboard/views/index.erb
|
127
127
|
- lib/split/dashboard/views/layout.erb
|
128
|
+
- lib/split/engine.rb
|
128
129
|
- lib/split/experiment.rb
|
129
130
|
- lib/split/helper.rb
|
130
131
|
- lib/split/version.rb
|