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.
@@ -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
@@ -7,38 +7,41 @@ class Abongo
7
7
  module Sugar
8
8
 
9
9
  def ab_test(test_name, alternatives = nil, options = {})
10
- if (Abongo.options[:enable_specification] && !params[test_name].nil?)
11
- choice = params[test_name]
12
- elsif (Abongo.options[:enable_override_in_session] && !session[test_name].nil?)
13
- choice = session[test_name]
14
- elsif (Abongo.options[:enable_selection] && !params[test_name].nil?)
15
- choice = Abongo.parse_alternatives(alternatives)[params[test_name].to_i]
16
- elsif (alternatives.nil?)
17
- begin
18
- choice = Abongo.flip(test_name, options)
19
- rescue
20
- if Abongo.options[:failsafe]
21
- choice = true
22
- else
23
- raise
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
- end
26
- else
27
- begin
28
- choice = Abongo.test(test_name, alternatives, options)
29
- rescue
30
- if Abongo.options[:failsafe]
31
- choice = Abongo.parse_alternatives(alternatives).first
32
- else
33
- raise
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(choice)
42
+ yield(@choices[test_name])
40
43
  else
41
- choice
44
+ @choices[test_name]
42
45
  end
43
46
  end
44
47
 
@@ -1,4 +1,4 @@
1
1
  class Abongo
2
- VERSION = '1.0.5'
2
+ VERSION = '1.0.6'
3
3
  MAJOR_VERSION = '1'
4
4
  end
@@ -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
- if (Abongo.options[:enable_specification] && !params[test_name].nil?)
9
- choice = params[test_name]
10
- elsif (Abongo.options[:enable_override_in_session] && !session[test_name].nil?)
11
- choice = session[test_name]
12
- elsif (Abongo.options[:enable_selection] && !params[test_name].nil?)
13
- choice = Abongo.parse_alternatives(alternatives)[params[test_name].to_i]
14
- elsif (alternatives.nil?)
15
- begin
16
- choice = Abongo.flip(test_name, options)
17
- rescue
18
- if Abongo.options[:failsafe]
19
- choice = true
20
- else
21
- raise
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
- end
24
- else
25
- begin
26
- choice = Abongo.test(test_name, alternatives, options)
27
- rescue
28
- if Abongo.options[:failsafe]
29
- choice = Abongo.parse_alternatives(alternatives).first
30
- else
31
- raise
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(choice, &block)
38
- Rails::VERSION::MAJOR <= 2 and block_called_from_erb?(block) ? concat(content_tag) : content_tag
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
- choice
42
+ @choices[test_name]
41
43
  end
42
44
  end
43
45
 
@@ -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
- - 5
9
- version: 1.0.5
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-03-12 00:00:00 -08:00
17
+ date: 2011-04-16 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency