protected
def find_scenario(id = params[:id])
@scenario = current_user.scenarios.find_by_id(id)
end
def update
@scenario = find_scenario
if @scenario.update_attributes(params[:scenario])
flash[:notice] = 'Scenario updated successfully...'
else
flash[:error] = 'There was a problem updating the scenario...'
end
redirect_to(room_scenario_path(current_room, @scenario))
end
spec
before do
@scenario = mock_model(Scenario)
controller.stub!(:find_scenario).and_return(@scenario)
end
it "finds a scenario" do
get :update, :Id => 1
response.should be_redirect
end
it "shows the correct message if updating the scenario failed" do
@scenario.should_receive(:update_attributes).and_return(false)
flash[:message].should =~ /problem/
get :update, :id => 1
end
...