Created
February 14, 2011 15:44
-
-
Save dce/826049 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def PostsController < ActionController::Base | |
def create | |
@post = Post.new(params[:post]) | |
if @post.save | |
redirect_to posts_path | |
else | |
render :action => "new" | |
end | |
end | |
end |
This file contains hidden or 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
class PostsControllerTest < ActionController::TestCase | |
context "A PostsController" do | |
context "on POST to :create" do | |
context "with valid input" do | |
setup do | |
post :create, :post => Factory.attributes_for(:post) | |
end | |
should_redirect_to("post index") { posts_path } | |
should_change("number of posts", :by => 1) { Post.count } | |
end | |
context "with invalid input" do | |
setup do | |
post :create, :post => Factory.attributes_for(:post, :title => "") | |
end | |
should_respond_with :success | |
should_render_template :new | |
should_not_change("number of posts") { Post.count } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment