Permalink
Browse files

allow for a custom exclude logic

this is just an example implementation for discussion, readme and docs are still missing.
  • Loading branch information...
phoet committed Mar 12, 2013
1 parent 79dc011 commit a328b8387ab8481c4a44160645d1c344e0e2a438
Showing with 23 additions and 1 deletion.
  1. +2 −0 lib/split/configuration.rb
  2. +1 −1 lib/split/helper.rb
  3. +20 −0 spec/helper_spec.rb
@@ -3,6 +3,7 @@ class Configuration
attr_accessor :bots
attr_accessor :robot_regex
attr_accessor :ignore_ip_addresses
+ attr_accessor :ignore_filter
attr_accessor :db_failover
attr_accessor :db_failover_on_db_error
attr_accessor :db_failover_allow_parameter_override
@@ -148,6 +149,7 @@ def robot_regex
def initialize
@ignore_ip_addresses = []
+ @ignore_filter = proc{|request| is_robot? || is_ignored_ip_address? }
@db_failover = false
@db_failover_on_db_error = proc{|error|} # e.g. use Rails logger here
@db_failover_allow_parameter_override = false
View
@@ -101,7 +101,7 @@ def ab_user
end
def exclude_visitor?
- is_robot? || is_ignored_ip_address?
+ instance_eval(&Split.configuration.ignore_filter)
end
def not_allowed_to_test?(experiment_key)
View
@@ -380,6 +380,26 @@ def should_finish_experiment(experiment_name, should_finish=true)
end
end
+
+ describe 'when providing custom ignore logic' do
+ context "using a proc to configure custom logic" do
+
+ before(:each) do
+ Split.configure do |c|
+ c.ignore_filter = proc{|request| !!"i_am_going_to_be_disabled" }
+ end
+ end
+
+ it "ignores the ab_test" do
+ ab_test('link_color', 'blue', 'red')
+
+ red_count = Split::Alternative.new('red', 'link_color').participant_count
+ blue_count = Split::Alternative.new('blue', 'link_color').participant_count
+ (red_count + blue_count).should be(0)
+ end
+ end
+ end
+
shared_examples_for "a disabled test" do
describe 'ab_test' do

0 comments on commit a328b83

Please sign in to comment.