Ruby on rails Rails 3.2销毁挂钩失败前的RSpec测试
我有两种型号:Ruby on rails Rails 3.2销毁挂钩失败前的RSpec测试,ruby-on-rails,rspec-rails,Ruby On Rails,Rspec Rails,我有两种型号: class Region < ActiveRecord::Base has_one :acol, :dependent => :nullify before_destroy :check_acol_presence private def check_acol_presence if acol errors.add(:base,"activerecord.errors.models.region.delete_with_existin
class Region < ActiveRecord::Base
has_one :acol, :dependent => :nullify
before_destroy :check_acol_presence
private
def check_acol_presence
if acol
errors.add(:base,"activerecord.errors.models.region.delete_with_existing_acol")
return false
end
end
end
class Acol < ActiveRecord::Base
belongs_to :region
end
在rails控制台中,此检查工作正常。但测试失败了。为什么?试着在有一行之前放置销毁行应该是raise\u错误,而不仅仅是raise:
lambda { region.reload }.should_not raise_error(ActiveRecord::RecordNotFound)
否则,您的测试本身可能会导致错误。旧帖子,但它可以将“在销毁之前”移到“已销毁”之前。。。谢谢
lambda { region.reload }.should_not raise_error(ActiveRecord::RecordNotFound)