Skip to content

Commit 6bac1b9

Browse files
NaturalHokkeandrew
authored andcommitted
fix user participating alternative not found (#536)
1 parent 40ef808 commit 6bac1b9

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

lib/split/trial.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ def choose!(context = nil)
6868
if exclude_user?
6969
self.alternative = @experiment.control
7070
else
71-
value = @user[@experiment.key]
72-
if value
73-
self.alternative = value
74-
else
71+
self.alternative = @user[@experiment.key]
72+
if alternative.nil?
7573
self.alternative = @experiment.next_alternative
7674

7775
# Increment the number of participants since we are actually choosing a new alternative

spec/trial_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ def expect_alternative(trial, alternative_name)
176176

177177
expect_alternative(trial, 'basket')
178178
end
179+
180+
context "when alternative is not found" do
181+
it "falls back on next_alternative" do
182+
user[experiment.key] = 'notfound'
183+
expect(experiment).to receive(:next_alternative).and_call_original
184+
expect_alternative(trial, alternatives)
185+
end
186+
end
179187
end
180188

181189
context "when user is a new participant" do

0 commit comments

Comments
 (0)