Skip to content

Instantly share code, notes, and snippets.

@dce
Created February 14, 2011 15:44
Show Gist options
  • Save dce/826049 to your computer and use it in GitHub Desktop.
Save dce/826049 to your computer and use it in GitHub Desktop.
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
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