From 2020a9c575abf577ae1ad4ffa7e0e88b929b663a Mon Sep 17 00:00:00 2001 From: Michael-Keith Bernard Date: Fri, 6 Sep 2013 14:23:19 -0700 Subject: [PATCH] Only trigger completion callback with valid Trial Previously it was possible to trigger the #on_trial_complete even if the Trial wasn't legally completed (eg #complete! was falsey). This can occur if the user reaches a #finished call before they reach an #ab_test call. --- lib/split/helper.rb | 3 +-- spec/helper_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/split/helper.rb b/lib/split/helper.rb index 17124765..b6a36d2a 100644 --- a/lib/split/helper.rb +++ b/lib/split/helper.rb @@ -62,8 +62,7 @@ def finish_experiment(experiment, options = {:reset => true}) else alternative_name = ab_user[experiment.key] trial = Trial.new(:experiment => experiment, :alternative => alternative_name, :goals => options[:goals]) - trial.complete! - call_trial_complete_hook(trial) + call_trial_complete_hook(trial) if trial.complete! if should_reset reset!(experiment) diff --git a/spec/helper_spec.rb b/spec/helper_spec.rb index 77ebf986..4472e744 100755 --- a/spec/helper_spec.rb +++ b/spec/helper_spec.rb @@ -261,6 +261,12 @@ self.should_receive(:some_method) finished(@experiment_name) end + + it "should not call the method without alternative" do + ab_user[@experiment.key] = nil + self.should_not_receive(:some_method) + finished(@experiment_name) + end end end