I have Rails 4 Application with TravelNotes. Travel notes has 3 kind of statuses: draft, published, archived. If the status is draft, then it can be deleted otherwise not.
In the TravelNote-Model:
before_destroy :check_for_draft
def check_for_draft
if status == 'draft'
delete
else
errors.add(:scope, 'Only drafts can be deleted')
return false
end
end
And i use RSpec for testing:
it "should delete a travel note if its status is draft" do
expect{ draft.destroy! }.to change{ TravelNote.count }.by(-1)
end
it "should not delete a travel note if its status is published or archived" do
expect{ published.destroy! }.to_not change{ TravelNote.count }
When i run the test the draft-deleting-test passes but for published-deleting-test i get:
Failures:
1) TravelNote delete should not delete a travel note if its status is published or archived
Failure/Error: expect{ published.destroy! }.to_not change{ TravelNote.count }
ActiveRecord::RecordNotDestroyed:
ActiveRecord::RecordNotDestroyed
Obviously the code is working and only travel notes with other statuses than draft can be deleted.
How can i turn the Failure-Message ActiveRecord::RecordNotDestroyed to green?