Refactor assignment model constraints and queries

Constraints are easier to make sense of when grouped by the
attribute that they are constraining.

Many of the query styles that will be deprecated in Rails 4 have
been updated. Though, some cannot be upgraded now as the API does
not yet exist.

I also took the liberty of making some other small refactorings as I was going along.
Use 2 (not 1) spaces for indentation.