2016-01-02 08:15:42 +08:00
|
|
|
require 'test_helper'
|
|
|
|
require 'articles_controller'
|
|
|
|
require 'comments_controller'
|
|
|
|
|
|
|
|
class CommentsControllerTest < ActionController::TestCase
|
2016-01-09 22:52:45 +08:00
|
|
|
fixtures :articles
|
2016-01-02 08:15:42 +08:00
|
|
|
setup do
|
|
|
|
@controller = CommentsController.new
|
2016-01-09 22:52:45 +08:00
|
|
|
@comment = ArticleComment.new
|
|
|
|
@comment.content = 'comment111111'
|
|
|
|
# @comment.status = true
|
|
|
|
# @comment.message = 'message1'
|
2016-01-02 08:15:42 +08:00
|
|
|
@comment.save
|
|
|
|
end
|
|
|
|
|
2016-01-09 22:52:45 +08:00
|
|
|
test "should create comment" do
|
|
|
|
post :create, articles:"aaaaaaaaaaaa", article_id: 1, :article_comment => {:content => 'content222222'}
|
|
|
|
#assert_not_nil session[:comment_id]
|
|
|
|
# assert_redirected_to comment_path(@comment)
|
|
|
|
#assert_respond_to "format.js"
|
2016-01-02 08:15:42 +08:00
|
|
|
end
|
|
|
|
|
2016-01-09 22:52:45 +08:00
|
|
|
test "should edit comment" do
|
|
|
|
#get:edit,id:@comment.id
|
|
|
|
#assert_response:success
|
2016-01-02 08:15:42 +08:00
|
|
|
end
|
|
|
|
|
2016-01-09 22:52:45 +08:00
|
|
|
test "should update comment" do
|
|
|
|
#get:update,id:@comment.id
|
|
|
|
#assert_response:success
|
2016-01-02 08:15:42 +08:00
|
|
|
end
|
|
|
|
|
2016-01-09 22:52:45 +08:00
|
|
|
test "should destroy comment" do
|
|
|
|
#assert_difference('Comment.count',-1) do
|
|
|
|
# delete:destroy,id:@comment.id
|
|
|
|
#end
|
2016-01-02 08:15:42 +08:00
|
|
|
|
2016-01-09 22:52:45 +08:00
|
|
|
#assert_redirected_to comments_path
|
2016-01-02 08:15:42 +08:00
|
|
|
end
|
|
|
|
|
2016-01-09 22:52:45 +08:00
|
|
|
test "destroy_wrong" do
|
|
|
|
#post:destroy,:comment=>{:content=>'content1'}
|
|
|
|
#assert_response:success
|
|
|
|
#assert_equal '删除失败',flash[:error]
|
2016-01-02 08:15:42 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|