abongo 1.0.5 → 1.0.6
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.
- data/lib/abongo.rb +2 -0
- data/lib/abongo/sugar.rb +29 -26
- data/lib/abongo/version.rb +1 -1
- data/lib/abongo/view_helper.rb +29 -27
- data/test/test_abongo.rb +9 -0
- metadata +3 -3
data/lib/abongo.rb
CHANGED
@@ -201,7 +201,9 @@ class Abongo
|
|
201
201
|
|
202
202
|
def self.end_experiment!(test_name, final_alternative, conversion_name = nil)
|
203
203
|
warn("conversion_name is deprecated") if conversion_name
|
204
|
+
test = get_test(test_name)
|
204
205
|
Abongo.experiments.update({:name => test_name}, {'$set' => { :final => final_alternative}}, :upsert => true, :safe => true)
|
206
|
+
Abongo.conversions.update({'tests' => test['_id']}, {'$pull' => {'tests' => test['_id']}}, :multi => true)
|
205
207
|
end
|
206
208
|
|
207
209
|
protected
|
data/lib/abongo/sugar.rb
CHANGED
@@ -7,38 +7,41 @@ class Abongo
|
|
7
7
|
module Sugar
|
8
8
|
|
9
9
|
def ab_test(test_name, alternatives = nil, options = {})
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
10
|
+
@choices ||= {}
|
11
|
+
unless @choices[test_name]
|
12
|
+
if (Abongo.options[:enable_specification] && !params[test_name].nil?)
|
13
|
+
@choices[test_name] = params[test_name]
|
14
|
+
elsif (Abongo.options[:enable_override_in_session] && !session[test_name].nil?)
|
15
|
+
@choices[test_name] = session[test_name]
|
16
|
+
elsif (Abongo.options[:enable_selection] && !params[test_name].nil?)
|
17
|
+
@choices[test_name] = Abongo.parse_alternatives(alternatives)[params[test_name].to_i]
|
18
|
+
elsif (alternatives.nil?)
|
19
|
+
begin
|
20
|
+
@choices[test_name] = Abongo.flip(test_name, options)
|
21
|
+
rescue
|
22
|
+
if Abongo.options[:failsafe]
|
23
|
+
@choices[test_name] = true
|
24
|
+
else
|
25
|
+
raise
|
26
|
+
end
|
24
27
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
else
|
29
|
+
begin
|
30
|
+
@choice[test_name] = Abongo.test(test_name, alternatives, options)
|
31
|
+
rescue
|
32
|
+
if Abongo.options[:failsafe]
|
33
|
+
@choices[test_name] = Abongo.parse_alternatives(alternatives).first
|
34
|
+
else
|
35
|
+
raise
|
36
|
+
end
|
34
37
|
end
|
35
38
|
end
|
36
39
|
end
|
37
|
-
|
40
|
+
|
38
41
|
if block_given?
|
39
|
-
yield(
|
42
|
+
yield(@choices[test_name])
|
40
43
|
else
|
41
|
-
|
44
|
+
@choices[test_name]
|
42
45
|
end
|
43
46
|
end
|
44
47
|
|
data/lib/abongo/version.rb
CHANGED
data/lib/abongo/view_helper.rb
CHANGED
@@ -4,40 +4,42 @@ class Abongo
|
|
4
4
|
module ViewHelper
|
5
5
|
|
6
6
|
def ab_test(test_name, alternatives = nil, options = {}, &block)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
7
|
+
@choices ||= {}
|
8
|
+
unless @choices[test_name]
|
9
|
+
if (Abongo.options[:enable_specification] && !params[test_name].nil?)
|
10
|
+
@choices[test_name] = params[test_name]
|
11
|
+
elsif (Abongo.options[:enable_override_in_session] && !session[test_name].nil?)
|
12
|
+
@choices[test_name] = session[test_name]
|
13
|
+
elsif (Abongo.options[:enable_selection] && !params[test_name].nil?)
|
14
|
+
@choices[test_name] = Abongo.parse_alternatives(alternatives)[params[test_name].to_i]
|
15
|
+
elsif (alternatives.nil?)
|
16
|
+
begin
|
17
|
+
@choices[test_name] = Abongo.flip(test_name, options)
|
18
|
+
rescue
|
19
|
+
if Abongo.options[:failsafe]
|
20
|
+
@choices[test_name] = true
|
21
|
+
else
|
22
|
+
raise
|
23
|
+
end
|
22
24
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
else
|
26
|
+
begin
|
27
|
+
@choices[test_name] = Abongo.test(test_name, alternatives, options)
|
28
|
+
rescue
|
29
|
+
if Abongo.options[:failsafe]
|
30
|
+
@choices[test_name] = Abongo.parse_alternatives(alternatives).first
|
31
|
+
else
|
32
|
+
raise
|
33
|
+
end
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
38
|
if block
|
37
|
-
content_tag = capture(
|
38
|
-
Rails::VERSION::MAJOR <= 2
|
39
|
+
content_tag = capture(@choices[test_name], &block)
|
40
|
+
Rails::VERSION::MAJOR <= 2 && block_called_from_erb?(block) ? concat(content_tag) : content_tag
|
39
41
|
else
|
40
|
-
|
42
|
+
@choices[test_name]
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
data/test/test_abongo.rb
CHANGED
@@ -132,6 +132,15 @@ class TestAbongo < Test::Unit::TestCase
|
|
132
132
|
assert_equal('alt3', Abongo.test('test_test', ['alt1', 'alt2']))
|
133
133
|
end
|
134
134
|
|
135
|
+
def test_ending_an_experiment_removes_conversion
|
136
|
+
Abongo.identity = 'ident'
|
137
|
+
assert_equal('alt1', Abongo.test('test_test', ['alt1', 'alt2']))
|
138
|
+
experiment = Abongo.get_test('test_test')
|
139
|
+
assert(Abongo.tests_listening_to_conversion('test_test').include?(experiment['_id']))
|
140
|
+
Abongo.end_experiment!('test_test', 'alt2')
|
141
|
+
assert(!Abongo.tests_listening_to_conversion('test_test').include?(experiment['_id']))
|
142
|
+
end
|
143
|
+
|
135
144
|
def test_ensure_one_participation_per_participant
|
136
145
|
Abongo.identity = 'ident'
|
137
146
|
10.times do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 6
|
9
|
+
version: 1.0.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Fairley
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-04-16 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|