I have two models:
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
I want to check the 'check_acol_presence' hook in RSpec test. So here is the test code:
region = FactoryGirl.create(:region)
acol = FactoryGirl.create(:acol, :region => region)
region.reload
region.destroy
lambda { region.reload }.should_not raise(ActiveRecord::RecordNotFound)
In rails console this check works just fine. But the test fails. Why?