-
-
Save gotascii/832055 to your computer and use it in GitHub Desktop.
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
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 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 | |
setup do | |
@post = Factory.build(:post) | |
Post.stubs(:new).returns(@post) | |
end | |
should "create a new post with params" do | |
params = {'some' => 'params'} | |
Post.expects(:new).with(params).returns(post) | |
post :create, :post => params | |
end | |
should "assign the new post" do | |
post :create | |
assigns(:post).should == @post | |
end | |
should "try to save the new post" do | |
@post.expects(:save) | |
post :create | |
end | |
context "with valid input" do | |
setup do | |
@post.stubs(:save).returns(true) | |
post :create | |
end | |
should_redirect_to("post index") { posts_path } | |
end | |
context "with invalid input" do | |
setup do | |
@post.stubs(:save).returns(false) | |
post :create | |
end | |
should_respond_with :success | |
should_render_template :new | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment