From 7f4c891f4a5919287e25caa4d889eb186926ef36 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 21:35:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0article=20model=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=8F=8A=E7=9B=B8=E5=85=B3fixture=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/fixtures/articles.yml | 6 +++++ test/fixtures/categorys.yml | 6 +++++ test/models/articles_model_test.rb | 38 ++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 test/fixtures/articles.yml create mode 100644 test/fixtures/categorys.yml create mode 100644 test/models/articles_model_test.rb diff --git a/test/fixtures/articles.yml b/test/fixtures/articles.yml new file mode 100644 index 0000000..ad9e6dc --- /dev/null +++ b/test/fixtures/articles.yml @@ -0,0 +1,6 @@ +article1: + id: 1 + title: "aaaaaaaaaaaa" + tags: "aaa" + content: "aaaaaaaaaaaaa" + diff --git a/test/fixtures/categorys.yml b/test/fixtures/categorys.yml new file mode 100644 index 0000000..85e933d --- /dev/null +++ b/test/fixtures/categorys.yml @@ -0,0 +1,6 @@ +category1: + id: 1 + name: "category" +category2: + id: 2 + name: "category2" diff --git a/test/models/articles_model_test.rb b/test/models/articles_model_test.rb new file mode 100644 index 0000000..0d3a2c1 --- /dev/null +++ b/test/models/articles_model_test.rb @@ -0,0 +1,38 @@ +require 'test_helper' + +class ArticleTest < ActiveSupport::TestCase + fixtures :articles + + setup do + @article = Article.find(1) + @newarticle = Article.new + end + + test "test_article_create" do + @newarticle.title = 'bbbbbbbbbbb' + @newarticle.tags = 'bbbb' + @newarticle.content = 'bbbbbbbbbbbbbbbb' + @newarticle.category_id = 1 + assert @newarticle.save + end + + test "test_article_read" do + assert_instance_of Article, @article + assert_equal 1, @article.id, "test Article.id" + assert_equal "aaaaaaaaaaaa", @article.title, "test Article.title" + assert_equal "aaa", @article.tags, "test Article.tags" + assert_equal "aaaaaaaaaaaaa", @article.content, "test Article.content" + end + + test "test_article_update" do + @article.category_id = 2 + assert @article.save, @article.errors.full_messages.join("; ") + @article.reload + assert 2, @article.category_id + end + + test "test_article_delete" do + @article.destroy + assert_raise(ActiveRecord::RecordNotFound) { Article.find(@article.id) } + end +end