添加comments model测试及相关数据

This commit is contained in:
刘惊坤 2016-01-09 23:05:25 +08:00
parent ef94568d80
commit 9df8e9ff70
2 changed files with 36 additions and 0 deletions

3
test/fixtures/article_comments.yml vendored Normal file
View File

@ -0,0 +1,3 @@
article_comments:
id: 1
content: 'aaaaaaaaaaaa'

View File

@ -0,0 +1,33 @@
require 'test_helper'
class ArticleCommentTest < ActiveSupport::TestCase
fixtures :article_comments
setup do
@comment = ArticleComment.find(1)
@newcomment = ArticleComment.new
end
test "test_comment_create" do
@newcomment.content = 'bbbbbbbbbbb'
assert @newcomment.save
end
test "test_comment_read" do
assert_instance_of ArticleComment, @comment
assert_equal 1, @comment.id, "test ArticleComment.id"
assert_equal "aaaaaaaaaaaa", @comment.content, "test ArticleComment.title"
end
test "test_comment_update" do
@comment.content = 'cccccccc'
assert @comment.save, @comment.errors.full_messages.join("; ")
@comment.reload
assert 'cccccccc', @comment.content
end
test "test_comment_delete" do
@comment.destroy
assert_raise(ActiveRecord::RecordNotFound) { ArticleComment.find(@comment.id) }
end
end