【发布时间】:2015-07-02 14:07:23
【问题描述】:
MyModel 类:
class Post < ActiveRecord::Base
validates_presence_of :value
...
end
我的 post.yml
one:
row: 2
col: 3
name: 'Test'
我的测试用例
require 'test_helper'
class SimulationsModelTest < ActiveSupport::TestCase
def setup
@post = Post.new
end
test 'post must have name' do
@post.name = ' '
assert @post.valid?
end
结束
为什么上面的测试用例失败了?但是以下测试用例正在通过
test 'post must have name' do
@post.name = ' '
assert_not @post.valid?
结束
在我的模型中,我没有为名称设置presence => true,那么为什么第一个测试用例失败了?
编辑-1
如果我有两个validates_presence of : value , :name。我的测试用例是:
test 'post must have name' do
@post.name = 'some'
@post.value = 'test'
assert @post.valid?
end
它必须通过测试用例,但它失败了。我在models中没有任何其他必需参数
【问题讨论】:
标签: ruby ruby-on-rails-3 ruby-on-rails-4 minitest