From 9df8e9ff705057079098af0dc3169596ae700c7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=83=8A=E5=9D=A4?= Date: Sat, 9 Jan 2016 23:05:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0comments=20model=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=8F=8A=E7=9B=B8=E5=85=B3=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/fixtures/article_comments.yml | 3 +++ test/models/comments_model_test.rb | 33 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/fixtures/article_comments.yml create mode 100644 test/models/comments_model_test.rb 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