Only set state to pending when last is deleted

If a user deletes a submission that's not the last one, the prior one gets a
`pending` state. This caused two submissions for the same exercise to appear
on the current_exercises list. This commit fixes this by making sure that the
submission getting deleted is the last one and then setting the state of the
prior one to `pending`.
Refactor solution to check submissions state

Add test to make sure that the solution changes a submissions state when the
necessary conditions are met. Add test to make sure solution does not change a
submissions state when the conditions are not met.
Refactor solution to check a submissions state as opposed to check if its the
last submission.
Merge pull request #1830 from Adam89/ma-delete-submission-bug

Only set state to pending when last is deleted