diff --git a/lib/split/helper.rb b/lib/split/helper.rb index 44ae7a23..61a33a5d 100644 --- a/lib/split/helper.rb +++ b/lib/split/helper.rb @@ -1,7 +1,6 @@ module Split module Helper def ab_test(experiment_name, control, *alternatives) - if RUBY_VERSION.match(/1\.8/) && alternatives.length.zero? 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' end @@ -67,7 +66,7 @@ def not_allowed_to_test?(experiment_key) end def doing_other_tests?(experiment_key) - ab_user.keys.reject { |k| k == experiment_key }.length > 0 + keys_without_experiment(ab_user.keys, experiment_key).length > 0 end def clean_old_versions(experiment) @@ -78,8 +77,8 @@ def clean_old_versions(experiment) def old_versions(experiment) if experiment.version > 0 - ab_user.keys.select { |k| k.match(Regexp.new(experiment.name)) }. - reject { |k| k.match(Regexp.new("^#{experiment.key}(:finished)?$")) } + keys = ab_user.keys.select { |k| k.match(Regexp.new(experiment.name)) } + keys_without_experiment(keys, experiment.key) else [] end @@ -141,6 +140,9 @@ def experiment_variable(alternatives, control, experiment_name) ret end + def keys_without_experiment(keys, experiment_key) + keys.reject { |k| k.match(Regexp.new("^#{experiment_key}(:finished)?$")) } + end end end diff --git a/spec/helper_spec.rb b/spec/helper_spec.rb index 03502c22..29c0dfe2 100755 --- a/spec/helper_spec.rb +++ b/spec/helper_spec.rb @@ -177,6 +177,12 @@ session[:split] = nil lambda { finished('some_experiment_not_started_by_the_user') }.should_not raise_exception end + + it 'should not be doing other tests when it has completed one that has :reset => false' do + ab_user[@experiment.key] = @alternative_name + ab_user[@experiment.finished_key] = true + doing_other_tests?(@experiment.key).should be false + end end describe 'conversions' do