|
127 | 127 | expect(alternative).to eq("blue") |
128 | 128 | end |
129 | 129 |
|
| 130 | + it "should allow the alternative to be forced by a cookie" do |
| 131 | + @request = build_request(cookies: { "split_override" => '{ "link_color": "red" }' }) |
| 132 | + |
| 133 | + expect(ab_test("link_color", "blue", "red")).to eq("red") |
| 134 | + end |
| 135 | + |
| 136 | + it "should ignore a malformed split_override cookie and assign normally" do |
| 137 | + @request = build_request(cookies: { "split_override" => "{ this is not valid json" }) |
| 138 | + |
| 139 | + expect { ab_test("link_color", "blue", "red") }.not_to raise_error |
| 140 | + expect(["blue", "red"]).to include(ab_user["link_color"]) |
| 141 | + end |
| 142 | + |
130 | 143 | it "should not store the split when a param forced alternative" do |
131 | 144 | @params = { "ab_test" => { "link_color" => "blue" } } |
132 | 145 | expect(ab_user).not_to receive(:[]=) |
@@ -611,6 +624,51 @@ def should_finish_experiment(experiment_name, should_finish = true) |
611 | 624 | expect(alternative.extra_info).to eql({}) |
612 | 625 | end |
613 | 626 | end |
| 627 | + |
| 628 | + context "for an experiment that the user is not participating in" do |
| 629 | + before do |
| 630 | + Split::ExperimentCatalog.find_or_create("link_color", "blue", "red") |
| 631 | + end |
| 632 | + |
| 633 | + it "does not record extra data for any alternative" do |
| 634 | + ab_record_extra_info("link_color", "some_data", 10) |
| 635 | + |
| 636 | + expect(Split::Alternative.new("blue", "link_color").extra_info).to eql({}) |
| 637 | + expect(Split::Alternative.new("red", "link_color").extra_info).to eql({}) |
| 638 | + end |
| 639 | + end |
| 640 | + |
| 641 | + context "when the visitor is excluded" do |
| 642 | + before do |
| 643 | + Split::ExperimentCatalog.find_or_create("link_color", "blue", "red") |
| 644 | + @request = build_request(user_agent: "Googlebot/2.1 (+http://www.google.com/bot.html)") |
| 645 | + end |
| 646 | + |
| 647 | + it "does not record extra data" do |
| 648 | + ab_record_extra_info("link_color", "some_data", 10) |
| 649 | + |
| 650 | + expect(Split::Alternative.new("blue", "link_color").extra_info).to eql({}) |
| 651 | + expect(Split::Alternative.new("red", "link_color").extra_info).to eql({}) |
| 652 | + end |
| 653 | + end |
| 654 | + |
| 655 | + context "when redis is not available" do |
| 656 | + before do |
| 657 | + expect(Split).to receive(:redis).and_raise(Errno::ECONNREFUSED) |
| 658 | + end |
| 659 | + |
| 660 | + it "raises the error when db_failover is off" do |
| 661 | + Split.configuration.db_failover = false |
| 662 | + expect { ab_record_extra_info("link_color", "some_data", 10) }.to raise_error(Errno::ECONNREFUSED) |
| 663 | + end |
| 664 | + |
| 665 | + it "calls db_failover_on_db_error when db_failover is on" do |
| 666 | + Split.configuration.db_failover = true |
| 667 | + expect(Split.configuration.db_failover_on_db_error).to receive(:call).with(instance_of(Errno::ECONNREFUSED)) |
| 668 | + |
| 669 | + expect { ab_record_extra_info("link_color", "some_data", 10) }.not_to raise_error |
| 670 | + end |
| 671 | + end |
614 | 672 | end |
615 | 673 |
|
616 | 674 | describe "conversions" do |
@@ -687,6 +745,40 @@ def should_finish_experiment(experiment_name, should_finish = true) |
687 | 745 | end |
688 | 746 | end |
689 | 747 |
|
| 748 | + describe "ab_active_experiments" do |
| 749 | + it "returns the experiments the user is actively participating in" do |
| 750 | + Split.configure do |config| |
| 751 | + config.allow_multiple_experiments = true |
| 752 | + end |
| 753 | + alternative = ab_test("def", "4", "5", "6") |
| 754 | + another_alternative = ab_test("ghi", "7", "8", "9") |
| 755 | + |
| 756 | + experiments = ab_active_experiments |
| 757 | + expect(experiments.count).to eq 2 |
| 758 | + expect(experiments["def"]).to eq alternative |
| 759 | + expect(experiments["ghi"]).to eq another_alternative |
| 760 | + end |
| 761 | + |
| 762 | + context "when redis is not available" do |
| 763 | + before do |
| 764 | + ab_test("link_color", "blue", "red") |
| 765 | + allow(Split).to receive(:redis).and_raise(Errno::ECONNREFUSED) |
| 766 | + end |
| 767 | + |
| 768 | + it "raises the error when db_failover is off" do |
| 769 | + Split.configuration.db_failover = false |
| 770 | + expect { ab_active_experiments }.to raise_error(Errno::ECONNREFUSED) |
| 771 | + end |
| 772 | + |
| 773 | + it "calls db_failover_on_db_error when db_failover is on" do |
| 774 | + Split.configuration.db_failover = true |
| 775 | + expect(Split.configuration.db_failover_on_db_error).to receive(:call).with(Errno::ECONNREFUSED) |
| 776 | + |
| 777 | + expect { ab_active_experiments }.not_to raise_error |
| 778 | + end |
| 779 | + end |
| 780 | + end |
| 781 | + |
690 | 782 | describe "when user is a robot" do |
691 | 783 | before(:each) do |
692 | 784 | @request = build_request(user_agent: "Googlebot/2.1 (+http://www.google.com/bot.html)") |
@@ -915,7 +1007,7 @@ def should_finish_experiment(experiment_name, should_finish = true) |
915 | 1007 |
|
916 | 1008 | context "when redis is not available" do |
917 | 1009 | before(:each) do |
918 | | - expect(Split).to receive(:redis).at_most(5).times.and_raise(Errno::ECONNREFUSED.new) |
| 1010 | + allow(Split).to receive(:redis).and_raise(Errno::ECONNREFUSED) |
919 | 1011 | end |
920 | 1012 |
|
921 | 1013 | context "and db_failover config option is turned off" do |
|
0 commit comments