1
这是我的测试。使用Shoulda进行测试验证的问题
class AlertSettingTest < ActiveSupport::TestCase
context "For ALL Alert Settings" do
setup do
@alert = AlertSetting.create({ :alert_type_id=>'1',:name => 'xxx'})
end
subject { @alert }
should_belong_to :alert_type
should_validate_presence_of :name
end
end
这是我的模型。
class AlertSetting < ActiveRecord::Base
belongs_to :alert_type
validates_presence_of :name, :message => "Alert name can't be blank."
validates_presence_of :alert_type_id, :message => "Please select valid Alert Type."
end
我也得到预期的错误,包括时名称设置为无“不能为空”,得到了错误:命名警报名称不能为空。 (无)
我不明白。为什么? 谢谢!
我认为应该是(后应该用空格)“应validate_presence_of”,而不是“should_validate_presence_of” – 2013-05-07 18:46:25