Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/split/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class Dashboard < Sinatra::Base
erb :index
end

post '/force_alternative' do
Split::User.new(self)[params[:experiment]] = params[:alternative]
redirect url('/')
end

post '/experiment' do
@experiment = Split::ExperimentCatalog.find(params[:experiment])
@alternative = Split::Alternative.new(params[:alternative], params[:experiment])
Expand Down
4 changes: 4 additions & 0 deletions lib/split/dashboard/views/_experiment.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<% if alternative.control? %>
<em>control</em>
<% end %>
<form action="<%= url('force_alternative') + '?experiment=' + experiment.name %>" method='post'>
<input type='hidden' name='alternative' value='<%= h alternative.name %>'>
<input type="submit" value="Force for current user" class="green">
</form>
</td>
<td><%= alternative.participant_count %></td>
<td><%= alternative.unfinished_count %></td>
Expand Down
15 changes: 15 additions & 0 deletions spec/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ def link(color)
end
end

describe "force alternative" do
let!(:user) do
Split::User.new(@app, { experiment.name => 'a' })
end

before do
allow(Split::User).to receive(:new).and_return(user)
end

it "should set current user's alternative" do
post "/force_alternative?experiment=#{experiment.name}", alternative: "b"
expect(user[experiment.name]).to eq("b")
end
end

describe "index page" do
context "with winner" do
before { experiment.winner = 'red' }
Expand Down