forked from splitrb/split
-
Notifications
You must be signed in to change notification settings - Fork 1
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
gschammah
wants to merge
2
commits into
master
Choose a base branch
from
feature/ensure_alternative
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ source "https://rubygems.org" | |
gemspec | ||
|
||
gem "appraisal" | ||
gem "pry" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
# 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
# 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 | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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