lib/split/trial.rb in split-1.4.3 vs lib/split/trial.rb in split-1.4.4
- old
+ new
@@ -47,16 +47,19 @@
# Choose an alternative, add a participant, and save the alternative choice on the user. This
# method is guaranteed to only run once, and will skip the alternative choosing process if run
# a second time.
def choose!(context = nil)
- @user.cleanup_old_experiments
+ @user.cleanup_old_experiments!
# Only run the process once
return alternative if @alternative_choosen
if override_is_alternative?
self.alternative = @options[:override]
+ if should_store_alternative? && !@user[@experiment.key]
+ self.alternative.increment_participation
+ end
elsif @options[:disabled] || Split.configuration.disabled?
self.alternative = @experiment.control
elsif @experiment.has_winner?
self.alternative = @experiment.winner
else
@@ -100,24 +103,14 @@
end
end
def cleanup_old_versions
if @experiment.version > 0
- keys = @user.keys.select { |k| k.match(Regexp.new(@experiment.name)) }
- keys_without_experiment(keys).each { |key| @user.delete(key) }
+ @user.cleanup_old_versions!(@experiment)
end
end
def exclude_user?
- @options[:exclude] || @experiment.start_time.nil? || max_experiments_reached?
- end
-
- def max_experiments_reached?
- !Split.configuration.allow_multiple_experiments &&
- keys_without_experiment(@user.keys).length > 0
- end
-
- def keys_without_experiment(keys)
- keys.reject { |k| k.match(Regexp.new("^#{@experiment.key}(:finished)?$")) }
+ @options[:exclude] || @experiment.start_time.nil? || @user.max_experiments_reached?(@experiment.key)
end
end
end