Skip to content

Commit

Permalink
Reload service from API on failed save.
Browse files Browse the repository at this point in the history
  • Loading branch information
rheinwein committed Nov 25, 2014
1 parent 74c94f8 commit ad49266
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/services_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def update
format.json { render(json: @service.to_json, status: status) }
end
else
@service.reload
render :show
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/controllers/services_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@
context 'when saving fails' do
before do
valid_service.stub(:save).and_return(false)
valid_service.stub(:reload).and_return(true)
end

it 'reloads the service' do
patch :update, app_id: 2, id: 3, service: attributes
expect(valid_service).to have_received(:reload)
end

it 're-renders the show page' do
Expand Down

0 comments on commit ad49266

Please sign in to comment.