Created
May 18, 2013 13:40
-
-
Save andreaseriksson/5604424 to your computer and use it in GitHub Desktop.
RSPEC Controller spec #CREATE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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