everydayrails / everydayrails-rspec-2017

Sample source for the 2017 edition of Everyday Rails Testing with RSpec.
http://rspectutorial.com
312 stars 247 forks source link

Chapter 11 11.3 should use :update_attributes! #79

Open YaEvan opened 6 years ago

YaEvan commented 6 years ago

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

ruralocity commented 6 years ago

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.

YaEvan commented 6 years ago

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

`