Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WOUnit doesn't propagate delete when validating objects for deletion #43

Closed
hprange opened this issue Jun 9, 2015 · 0 comments
Closed
Assignees
Labels
Milestone

Comments

@hprange
Copy link
Owner

hprange commented Jun 9, 2015

The implementation of the CanBeDeletedMatcher can lead to code that will pass the tests but will fail in production.

WOUnit offers a matcher to verify if an object can or cannot be deleted. The implementation of this matcher is simple. It calls only the validateForDelete method on the object being verified. Considering how EOF works, this implementation is not enough. It doesn't guarantee, for instance, that the state of the object will be correct when firing the validation code while running tests.

In production, two actions execute before the validation and may change the state of an object. The ERXEC calls the ERXEnterpriseObject.mightDelete method when the object is deleted, and the original EOEditingContext propagates the deletion over related objects (applying the delete rules defined in the EOModel) when the editing context is saved. If a relationship has a delete rule of type Nullify or Cascade, it will no longer be in place when the validation is executed.

The following uses of the CanBeDeletedMatcher are affected by this issue:

confirm(eo, canBeDeleted());
confirm(eo, cannotBeDeleted());
confirm(eo, cannotBeDeletedBecause("reason"));

To fix this problem, the CanBeDeletedMatcher should call the ERXEnterpriseObject.mightDelete and the EOEnterpriseObject.propagateDeleteWithEditingContext methods before calling the validateForDelete method.

@hprange hprange added the bug label Jun 9, 2015
@hprange hprange self-assigned this Jun 9, 2015
@hprange hprange added this to the wounit-1.3 milestone Jun 9, 2015
@hprange hprange closed this as completed in 201591c Jun 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant