implemented forum post controller

This commit is contained in:
albert
2011-01-13 18:16:39 -05:00
parent 523cc9fe02
commit 541163685d
13 changed files with 121 additions and 42 deletions

View File

@@ -14,23 +14,37 @@ class CommentsControllerTest < ActionController::TestCase
CurrentUser.ip_addr = nil
end
should "get the index page" do
get :index
assert_response :success
end
should "update a comment" do
post :update, {:id => @comment.id, :comment => {:body => "abc"}}, {:user_id => @comment.creator_id}
assert_redirected_to comment_path(@comment)
end
should "create a comment" do
p = Factory.create(:post)
assert_difference("Comment.count", 1) do
post :create, {:comment => Factory.attributes_for(:comment, :post_id => p.id)}, {:user_id => @user.id}
context "index action" do
should "render by post" do
get :index, {:group_by => "post"}
assert_response :success
end
should "render by comment" do
get :index, {:group_by => "comment"}
assert_response :success
end
end
context "update action" do
should "update the comment" do
post :update, {:id => @comment.id, :comment => {:body => "abc"}}, {:user_id => @comment.creator_id}
assert_redirected_to comment_path(@comment)
end
end
context "create action"do
setup do
@post = Factory.create(:post)
end
should "create a comment" do
assert_difference("Comment.count", 1) do
post :create, {:comment => Factory.attributes_for(:comment, :post_id => @post.id)}, {:user_id => @user.id}
end
comment = Comment.last
assert_redirected_to post_path(comment.post)
end
comment = Comment.last
assert_redirected_to post_path(comment.post)
end
end
end