From 381d4b6c98ec154166d8fbe4e93aa3e43bcd0811 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:17:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0blog=5Finfo=20model=E7=9A=84?= =?UTF-8?q?=E6=B5=8B=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/blog_info.yml | 4 ++++ test/models/blog_model_test.rb | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test/fixtures/blog_info.yml create mode 100644 test/models/blog_model_test.rb diff --git a/test/fixtures/blog_info.yml b/test/fixtures/blog_info.yml new file mode 100644 index 0000000..0e4f07b --- /dev/null +++ b/test/fixtures/blog_info.yml @@ -0,0 +1,4 @@ +blog_info: + id: 1 + name: 'blog1' + email: '1234567@qq.com' diff --git a/test/models/blog_model_test.rb b/test/models/blog_model_test.rb new file mode 100644 index 0000000..290fd29 --- /dev/null +++ b/test/models/blog_model_test.rb @@ -0,0 +1,35 @@ +require 'test_helper' + +class BlogInfoTest < ActiveSupport::TestCase + fixtures :blog_info + + setup do + @blog = BlogInfo.find(1) + @newblog = BlogInfo.new + end + + test "test_blog_create" do + @newblog.name = 'newblog' + @newblog.email = '12345678@qq.com' + assert @newblog.save + end + + test "test_blog_read" do + assert_instance_of BlogInfo, @blog + assert_equal 1, @blog.id, "test BlogInfo.id" + assert_equal "blog1", @blog.name, "test BlogInfo.name" + assert_equal "1234567@qq.com", @blog.email, "test BlogInfo.email" + end + + test "test_blog_update" do + @blog.name = 'updatename' + assert @blog.save, @blog.errors.full_messages.join("; ") + @blog.reload + assert 'updatename', @blog.name + end + + test "test_blog_delete" do + @blog.destroy + assert_raise(ActiveRecord::RecordNotFound) { BlogInfo.find(@blog.id) } + end +end