Skip to content

Instantly share code, notes, and snippets.

@andreaseriksson
Created May 18, 2013 13:40
Show Gist options
  • Save andreaseriksson/5604424 to your computer and use it in GitHub Desktop.
Save andreaseriksson/5604424 to your computer and use it in GitHub Desktop.
RSPEC Controller spec #CREATE
describe "POST#create" do
context "with valid attributes" do
it "saves the new message in the database" do
expect{
post :create, message: attributes_for(:message)
}.to change(Message, :count).by(1)
end
it "redirects to the home page" do
post :create, message: attributes_for(:message)
expect(response).to redirect_to root_url
end
end
context "with invalid attributes" do
it "does not save the new message in the database" do
expect{
post :create, message: attributes_for(:invalid_message)
}.to_not change(Message, :count)
end
it "re-renders the :new template" do
post :create, message: attributes_for(:invalid_message)
expect(response).to render_template :new
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment