everydayrails-rspec-2017
everydayrails-rspec-2017 copied to clipboard
Chapter 11 11.3 should use :update_attributes!
before do
allow_any_instance_of(Project).to(
receive(:update_attributes).with(completed: true).and_return(false))
end
before do
allow_any_instance_of(Project).to(
receive(:update_attributes!).with(completed: true).and_return(false))
end
The sample code is expecting a true/false response ... update_attributes!
raises an exception if it fails. Could you elaborate on why you'd make this change? Thanks.
The reason I did this is because the concrete code used update_attributes! when it was called. `
def complete
if @project.update_attributes!(completed: true)
flash[:notice] = "Congratulations, this project is complete!"
else
flash[:alert] = "Unable to complete project."
end
redirect_to @project
end
`