Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing tests #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ source "https://rubygems.org"
gemspec

gem "appraisal"
gem "pry"
34 changes: 25 additions & 9 deletions lib/split/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,39 @@ def begin_experiment(experiment, alternative_name = nil)

# alternative can be either a string or an array of strings
def ensure_alternative_or_exclude(experiment_name, alternatives)
return if @alternative_ensured
alternatives = Array(alternatives)
experiment = ExperimentCatalog.find(experiment_name)

# This is called if the experiment is not yet created. Since we can't created (we need the alternatives
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creo que es Since we can't create it

# configuration to be passed to this method), we exclude the user, and when `ab_test` is called after
# the experiment is created. This means the first user will be excluded from the test and will have
# the control alternative
if !experiment
experiment = Experiment.new(experiment_name)
exclude_visitor(experiment)
return
end

# if ab_user was not called before, then force the alternative and manually increment the counter.
unless experiment = ExperimentCatalog.find(experiment_name)
ab_user[experiment_name] = default_alternative = alternatives.first
Split::Alternative.new(default_alternative, experiment_name).increment_participation
@alternative_ensured = true
# If the user doesn't have an alternative set, we override the alternative and we manually increment the
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user doesn't have an alternative set, we override the alternative It doesn't makes much sense

# participant count, since split doesn't do it when an alternative is overriden
unless ab_user[experiment.key]
params[experiment_name] = ab_user[experiment.key] = alternatives.sample
Split::Alternative.new(ab_user[experiment.key], experiment_name).increment_participation
return
end

current_alternative = ab_user[experiment.key]

return if exclude_visitor?(experiment) || alternatives.include?(current_alternative)
# We don't decrement the participant count if the visitor is included or if the desired alternative
# was already chosen by split before
if exclude_visitor?(experiment) || alternatives.include?(current_alternative)
params[experiment_name] ||= current_alternative
return
end

Split::Alternative.new(current_alternative, experiment.key).decrement_participation
params[experiment_name] = alternatives.sample
# We decrement the participant count if the desired alternative was not chosen by split before
Split::Alternative.new(current_alternative, experiment_name).decrement_participation
params[experiment_name] = ab_user[experiment.key] = alternatives.sample
exclude_visitor(experiment)
end

Expand Down
Loading