Skip to content

Instantly share code, notes, and snippets.

@andreaseriksson
Created May 18, 2013 13:41
Show Gist options
  • Save andreaseriksson/5604428 to your computer and use it in GitHub Desktop.
Save andreaseriksson/5604428 to your computer and use it in GitHub Desktop.
RSPEC Controller spec #UPDATE
describe 'PUT#update' do
before :each do
@message = create(:message, name: "Aaron Sumner",
email: "[email protected]")
end
it "locates the requested @message" do
put :update, id: @message, message: attributes_for(:message)
expect(assigns(:message)).to eq(@message)
end
context "valid attributes" do
it "changes @message's attributes" do
put :update, id: @message, message: attributes_for(:message, firstname: "A. Sumner")
@message.reload
expect(@message.name).to eq("A. Sumner")
end
it "redirects to the updated message" do
put :update, id: @message, message: attributes_for(:message)
response.should redirect_to @message
expect(response).to redirect_to @message
end
end
context "invalid attributes" do
it "does not change @message's attributes" do
put :update, id: @message, message: attributes_for(:message, name: "None of your business", email: nil)
@message.reload
expect(@message.name).to eq("None of your business")
end
it "re-renders the edit method" do
put :update, id: @message, message: attributes_for(:invalid_message)
expect(response).to render_template :edit
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment