Skip to content

Commit 6d1dc2d

Browse files
authored
Merge pull request #568 from giraffate/force_alternative_with_version
Fix `force_aleternative` for experiments with incremented version
2 parents 023b69d + b8803f0 commit 6d1dc2d

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

lib/split/dashboard.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ class Dashboard < Sinatra::Base
3333
end
3434

3535
post '/force_alternative' do
36-
alternative = Split::Alternative.new(params[:alternative], params[:experiment])
36+
experiment = Split::ExperimentCatalog.find(params[:experiment])
37+
alternative = Split::Alternative.new(params[:alternative], experiment.name)
3738
alternative.increment_participation
38-
Split::User.new(self)[params[:experiment]] = params[:alternative]
39+
Split::User.new(self)[experiment.key] = alternative.name
3940
redirect url('/')
4041
end
4142

spec/dashboard_spec.rb

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,39 @@ def link(color)
7474
end
7575

7676
describe "force alternative" do
77-
let!(:user) do
78-
Split::User.new(@app, { experiment.name => 'red' })
79-
end
77+
context "initial version" do
78+
let!(:user) do
79+
Split::User.new(@app, { experiment.name => 'red' })
80+
end
8081

81-
before do
82-
allow(Split::User).to receive(:new).and_return(user)
82+
before do
83+
allow(Split::User).to receive(:new).and_return(user)
84+
end
85+
86+
it "should set current user's alternative" do
87+
blue_link.participant_count = 7
88+
post "/force_alternative?experiment=#{experiment.name}", alternative: "blue"
89+
expect(user[experiment.key]).to eq("blue")
90+
expect(blue_link.participant_count).to eq(8)
91+
end
8392
end
8493

85-
it "should set current user's alternative" do
86-
blue_link.participant_count = 7
87-
post "/force_alternative?experiment=#{experiment.name}", alternative: "blue"
88-
expect(user[experiment.name]).to eq("blue")
89-
expect(blue_link.participant_count).to eq(8)
94+
context "incremented version" do
95+
let!(:user) do
96+
experiment.increment_version
97+
Split::User.new(@app, { "#{experiment.name}:#{experiment.version}" => 'red' })
98+
end
99+
100+
before do
101+
allow(Split::User).to receive(:new).and_return(user)
102+
end
103+
104+
it "should set current user's alternative" do
105+
blue_link.participant_count = 7
106+
post "/force_alternative?experiment=#{experiment.name}", alternative: "blue"
107+
expect(user[experiment.key]).to eq("blue")
108+
expect(blue_link.participant_count).to eq(8)
109+
end
90110
end
91111
end
92112

0 commit comments

Comments
 (0)