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