Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/split/helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions spec/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down