Skip to content
Browse files

Merge pull request #151 from andrew/goals_no_array

finished method accept goals that are not passed as arrays
  • Loading branch information...
2 parents 0ce952d + cbd0354 commit 0b8d8c79a4e449c18e4d691ec01715f1ed5a426f @andrew andrew committed
Showing with 15 additions and 18 deletions.
  1. +1 −1 README.mdown
  2. +11 −14 lib/split/helper.rb
  3. +3 −3 spec/helper_spec.rb
View
2 README.mdown
@@ -396,7 +396,7 @@ end
To complete a goal conversion, you do it like:
```ruby
-finished("link_color" => ["purchase"])
+finished("link_color" => "purchase")
```
### DB failover solution
View
25 lib/split/helper.rb
@@ -1,13 +1,13 @@
module Split
module Helper
- def ab_test(experiment_label, control=nil, *alternatives)
+ def ab_test(metric_descriptor, control=nil, *alternatives)
if RUBY_VERSION.match(/1\.8/) && alternatives.length.zero? && ! control.nil?
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
begin
- experiment_name_with_version, goals = normalize_experiment(experiment_label)
+ experiment_name_with_version, goals = normalize_experiment(metric_descriptor)
experiment_name = experiment_name_with_version.to_s.split(':')[0]
experiment = Split::Experiment.new(experiment_name, :alternatives => [control].compact + alternatives, :goals => goals)
control ||= experiment.control && experiment.control.name
@@ -67,10 +67,10 @@ def finish_experiment(experiment, options = {:reset => true})
end
- def finished(metric_name, options = {:reset => true})
+ def finished(metric_descriptor, options = {:reset => true})
return if exclude_visitor? || Split.configuration.disabled?
- metric_name, goals = normalize_experiment(metric_name)
- experiments = Metric.possible_experiments(metric_name)
+ metric_descriptor, goals = normalize_experiment(metric_descriptor)
+ experiments = Metric.possible_experiments(metric_descriptor)
if experiments.any?
experiments.each do |experiment|
@@ -141,12 +141,13 @@ def is_ignored_ip_address?
end
protected
- def normalize_experiment(experiment_label)
- if Hash === experiment_label
- experiment_name = experiment_label.keys.first
- goals = experiment_label.values.first
+
+ def normalize_experiment(metric_descriptor)
+ if Hash === metric_descriptor
+ experiment_name = metric_descriptor.keys.first
+ goals = Array(metric_descriptor.values.first)
else
- experiment_name = experiment_label
+ experiment_name = metric_descriptor
goals = []
end
return experiment_name, goals
@@ -156,10 +157,6 @@ def control_variable(control)
Hash === control ? control.keys.first : control
end
- def load_and_start_trial(experiment_label, control, alternatives)
- experiment_name, goals = normalize_experiment(experiment_label)
- end
-
def start_trial(trial)
experiment = trial.experiment
if override_present?(experiment.name)
View
6 spec/helper_spec.rb
@@ -27,8 +27,8 @@
lambda { ab_test({'link_color' => ["purchase", "refund"]}, 'blue', 'red') }.should_not raise_error
end
- it "should raise the appropriate error when passed string for goals" do
- lambda { ab_test({'link_color' => "purchase"}, 'blue', 'red') }.should raise_error(ArgumentError)
+ it "should not raise error when passed just one goal" do
+ lambda { ab_test({'link_color' => "purchase"}, 'blue', 'red') }.should_not raise_error
end
it "should assign a random alternative to a new user when there are an equal number of alternatives assigned" do
@@ -852,7 +852,7 @@ def should_finish_experiment(experiment_name, should_finish=true)
it "should increment the counter for the specified-goal completed alternative" do
@previous_completion_count_for_goal1 = Split::Alternative.new(@alternative_name, @experiment_name).completed_count(@goal1)
@previous_completion_count_for_goal2 = Split::Alternative.new(@alternative_name, @experiment_name).completed_count(@goal2)
- finished({"link_color" => ["purchase"]})
+ finished({"link_color" => "purchase"})
new_completion_count_for_goal1 = Split::Alternative.new(@alternative_name, @experiment_name).completed_count(@goal1)
new_completion_count_for_goal1.should eql(@previous_completion_count_for_goal1 + 1)
new_completion_count_for_goal2 = Split::Alternative.new(@alternative_name, @experiment_name).completed_count(@goal2)

0 comments on commit 0b8d8c7

Please sign in to comment.
Something went wrong with that request. Please try again.