[#1216] Correct the logic in resource_delete

resource_delete, as it stands, is broken. This fixes the logic and adds tests
for resource_delete. Fixes #1216.
Merge remote-tracking branch 'upstream/1216-fix-resource-delete'