docbrown/spec/models/ab_experiment_spec.rb
Ben Halpern 8159f4383c
Feed experiment 4: Final order (#16128)
* Feed experiment 4: Final order

* Remove development line

* Fix text in tests

* Fix text in tests

* Switch query to greatest of
2022-01-17 17:05:43 -05:00

60 lines
2.3 KiB
Ruby

require "rails_helper"
RSpec.describe AbExperiment do
let(:controller) { ApplicationController.new }
let(:user) { double }
describe ".get" do
before do
allow(controller).to receive(:field_test).with(:feed_strategy_round_4, participant: user).and_return("special")
end
context "with :feed_strategy_round_3 experiment" do
it "repurposes the :feed_strategy experiment" do
expect(described_class.get(experiment: :feed_strategy_round_4,
user: user,
controller: controller,
default_value: "default")).to eq("special")
end
end
context "with :feed_strategy experiment" do
before do
allow(controller).to receive(:field_test).with(:feed_strategy, participant: user).and_return("special")
end
let(:experiment) { :feed_strategy }
it "returns an inquirable string" do
result = described_class.get(experiment: :feed_strategy,
user: user,
controller: controller,
default_value: "default")
expect(result).to eq("special")
expect(result).to be_special
end
it "allows for an config override" do
result = described_class.get(experiment: :feed_strategy,
user: user,
controller: controller,
default_value: "special",
config: { "AB_EXPERIMENT_FEED_STRATEGY" => "not_special" })
expect(result).to eq("not_special")
expect(result).to be_not_special
end
it "returns the default value when the FeatureFlipper is off" do
allow(FeatureFlag).to receive(:accessible?).with(:ab_experiment_feed_strategy).and_return(false)
result = described_class.get(experiment: :feed_strategy,
user: user,
controller: controller,
default_value: "special",
config: { "AB_EXPERIMENT_FEED_STRATEGY" => "not_special" })
expect(result).to eq("special")
expect(result).to be_special
end
end
end
end