ruby on rails - Object can not be deleted is attribute is active - Rspec RoR -
i'm trying test if object active , active can not deleted. have in plan_spec.rb:
"can not deleted if active" plan = plan.new(active: true) r = plan.destroy r.should_not be_valid end
name of attribute i'm trying check 'active' , boolean, if active true can't object plan can not deleted. help?
it can achieved using before_destroy callback return false if record can't destroyed:
class plan < activerecord::base   # ...   before_destroy :check_if_active   # ...   private    def check_if_active     !active?   end end   with solution, should rewrite test, cause shouldn't check validity:
it 'can not deleted if active'   plan = plan.create!(active: true)   expect { plan.destroy }.to_not change { plan.count } end      
Comments
Post a Comment