From 0579bbd19bda10c7fcb3b1bd646f849a318c44e5 Mon Sep 17 00:00:00 2001 From: Brandon Parsons Date: Mon, 4 Aug 2014 09:03:28 +0200 Subject: [PATCH] Provide an option to generically disable Split. --- README.mdown | 6 ++++++ lib/split/helper.rb | 12 ++++++++++-- spec/helper_spec.rb | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/README.mdown b/README.mdown index bbd8c216..a139ef13 100644 --- a/README.mdown +++ b/README.mdown @@ -179,6 +179,12 @@ If you have an experiment called `button_color` with alternatives called `red` a will always have red buttons. This won't be stored in your session or count towards to results, unless you set the `store_override` configuration option. +In the event you want to disable all tests without having to know the individual experiment names, add a `SPLIT_DISABLE` query parameter. + + http://myawesomesite.com?SPLIT_DISABLE=trues + +It is not required to send `SPLIT_DISABLE=false` to activate Split. + ### Starting experiments manually By default new AB tests will be active right after deployment. In case you would like to start new test a while after diff --git a/lib/split/helper.rb b/lib/split/helper.rb index 02d57906..df4b09ae 100644 --- a/lib/split/helper.rb +++ b/lib/split/helper.rb @@ -31,8 +31,9 @@ def ab_test(metric_descriptor, control=nil, *alternatives) raise(e) unless Split.configuration.db_failover Split.configuration.db_failover_on_db_error.call(e) - if Split.configuration.db_failover_allow_parameter_override && override_present?(experiment_name) - ret = override_alternative(experiment_name) + if Split.configuration.db_failover_allow_parameter_override + ret = override_alternative(experiment_name) if override_present?(experiment_name) + ret = control_variable(control) if split_generically_disabled? end ensure ret ||= control_variable(control) @@ -97,6 +98,10 @@ def override_alternative(experiment_name) params[experiment_name] if override_present?(experiment_name) end + def split_generically_disabled? + defined?(params) && params['SPLIT_DISABLE'] + end + def begin_experiment(experiment, alternative_name = nil) alternative_name ||= experiment.control.name ab_user[experiment.key] = alternative_name @@ -169,6 +174,9 @@ def start_trial(trial) if override_present?(experiment.name) and experiment[override_alternative(experiment.name)] ret = override_alternative(experiment.name) ab_user[experiment.key] = ret if Split.configuration.store_override + elsif split_generically_disabled? + ret = experiment.control.name + ab_user[experiment.key] = ret if Split.configuration.store_override elsif experiment.has_winner? ret = experiment.winner.name else diff --git a/spec/helper_spec.rb b/spec/helper_spec.rb index 2455aa43..ba0fef02 100755 --- a/spec/helper_spec.rb +++ b/spec/helper_spec.rb @@ -113,6 +113,24 @@ ab_test('link_color', 'blue', 'red') end + it "SPLIT_DISABLE query parameter should also force the alternative (uses control)" do + @params = {'SPLIT_DISABLE' => 'true'} + alternative = ab_test('link_color', 'blue', 'red') + alternative.should eql('blue') + alternative = ab_test('link_color', {'blue' => 1}, 'red' => 5) + alternative.should eql('blue') + alternative = ab_test('link_color', 'red', 'blue') + alternative.should eql('red') + alternative = ab_test('link_color', {'red' => 5}, 'blue' => 1) + alternative.should eql('red') + end + + it "should not store the split when Split generically disabled" do + @params = {'SPLIT_DISABLE' => 'true'} + ab_user.should_not_receive(:[]=) + ab_test('link_color', 'blue', 'red') + end + context "when store_override is set" do before { Split.configuration.store_override = true }