添加blog_info model的测试及相关数据

This commit is contained in:
刘惊坤 2016-01-09 23:17:26 +08:00
parent 9df8e9ff70
commit 381d4b6c98
2 changed files with 39 additions and 0 deletions

4
test/fixtures/blog_info.yml vendored Normal file
View File

@ -0,0 +1,4 @@
blog_info:
id: 1
name: 'blog1'
email: '1234567@qq.com'

View File

@ -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