course model validations testing.
This commit is contained in:
parent
472b61fefe
commit
04ec6ff27a
|
@ -1,4 +1,30 @@
|
|||
---
|
||||
courses_invalid_001:
|
||||
id: 1
|
||||
tea_id:
|
||||
name: ''
|
||||
state:
|
||||
code:
|
||||
time:
|
||||
extra:
|
||||
created_at: 2013-09-30 15:36:00.000000000 Z
|
||||
updated_at: 2014-04-19 01:50:41.000000000 Z
|
||||
location:
|
||||
term:
|
||||
string:
|
||||
password:
|
||||
setup_time:
|
||||
endup_time:
|
||||
class_period:
|
||||
school_id:
|
||||
description:
|
||||
status: 1
|
||||
attachmenttype: 2
|
||||
lft:
|
||||
rgt:
|
||||
is_public: 1
|
||||
inherit_members: 1
|
||||
|
||||
courses_008:
|
||||
id: 8
|
||||
tea_id: 5
|
||||
|
|
|
@ -6,6 +6,37 @@ class CourseTest < ActiveSupport::TestCase
|
|||
def setup
|
||||
end
|
||||
|
||||
# 基本测试,从不完整的空对象,验证属性的合法值
|
||||
test 'test courses all validations' do
|
||||
course = Course.new
|
||||
assert_not_nil course
|
||||
# 默认模型不完整
|
||||
assert course.invalid?
|
||||
error_keys = course.errors.keys
|
||||
|
||||
valid_attr = [:password, :term, :name, :class_period]
|
||||
puts error_keys
|
||||
valid_attr.each do |attr|
|
||||
assert(error_keys.include?(attr), "attr unknow: #{attr}")
|
||||
end
|
||||
|
||||
# 添加密码
|
||||
course.password = '123456'
|
||||
course.term = '春季学期'
|
||||
course.name = '课程名称测试'
|
||||
course.class_period = '32'
|
||||
assert course.valid?, course.errors.full_messages.to_s
|
||||
end
|
||||
|
||||
test 'class_period format validations' do
|
||||
course = Course.find_by_id(8)
|
||||
assert course, "course obj is nil."
|
||||
course.class_period = ''
|
||||
assert course.invalid?, "course class_period can not be number. #{course.class_period}"
|
||||
course.class_period = '32'
|
||||
assert course.valid?, "course class_period can not be number. #{course.class_period}"
|
||||
end
|
||||
|
||||
test 'name valid with CJK coding' do
|
||||
name_quirk = '电路与电子学基础(软件工程专业)'
|
||||
course = Course.find_by_id(74)
|
||||
|
@ -15,9 +46,9 @@ class CourseTest < ActiveSupport::TestCase
|
|||
assert course.valid?
|
||||
end
|
||||
|
||||
test 'description too long must be valid.' do
|
||||
test 'description too long must be valid.(4096)' do
|
||||
course = Course.find_by_id(8)
|
||||
course.description = 'a' * 2048 # description length validate.
|
||||
course.description = 'a' * 40 # description length validate.
|
||||
course.valid?
|
||||
assert course.errors[:name].empty?
|
||||
assert course.valid?
|
||||
|
|
Loading…
Reference in New Issue