これが私のテストです。
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
また、nameがnilに設定されている場合、予期されるエラーに「空白にすることはできません」が含まれ、エラーが発生します:nameアラート名を空白にすることはできません。(なし)
理解できません 。なんで?ありがとう!