diff --git a/test/fixtures/article_comments.yml b/test/fixtures/article_comments.yml new file mode 100644 index 0000000..125ee5d --- /dev/null +++ b/test/fixtures/article_comments.yml @@ -0,0 +1,3 @@ +article_comments: + id: 1 + content: 'aaaaaaaaaaaa' diff --git a/test/models/comments_model_test.rb b/test/models/comments_model_test.rb new file mode 100644 index 0000000..d3a4d03 --- /dev/null +++ b/test/models/comments_model_test.rb @@ -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