everydayrails-rspec-2017 icon indicating copy to clipboard operation
everydayrails-rspec-2017 copied to clipboard

Chapter 11 11.3 should use :update_attributes!

Open YaEvan opened this issue 6 years ago • 2 comments

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

YaEvan avatar May 18 '18 07:05 YaEvan

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.

ruralocity avatar May 24 '18 01:05 ruralocity

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

`

YaEvan avatar May 24 '18 06:05 YaEvan