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