ministryofjustice/parliamentary-questions — pull request #99 by PhilT (2014-12-09 21:39:04+00:00)
Title: Replaced progress with a state machine

Every time a Pq is saved a transition attempt is made (forward or backward) and then validations are
run to see if the model is still valid. If it is, then the transition is saved along with the model.
If the transition is not successful the data is still saved but the state is not changed as we cannot
tell whether a transition is intended or not.

* A question will now progress through the various states (some have been removed, some flags replaced with states and the whole transition process refined according to conversations with PQ team)
* Renamed `question` field to `text` to avoid confusion in places where a `Pq` is called a `question`
* Renamed factory to `question` with the state appended after it e.g. `question_draft_pending`
* Added `?` methods for all states e.g. `question.draft_pending?` (see `define_method`)
* Removed `Progress` controller and associated views
* scopes added for in progress and new questions
* State is manipulated and stored in the state_machine then persisted into an integer state field on the Pq model
* The generic state machine parts of QuestionStateMachine should probably be extracted into a super class or mixin
* Private monitoring methods on `Pq` model are no longer being called and need to be hooked back in but
delayed this as it seemed a little pointless with no Ops resource to ensure it's working
* Used Ruby and Rails methods where appropriate
* `transition` method on `QuestionStateMachine` is a bit chunky and could probably do with some refactoring
* Removed a fair bit of duplication in some of the templates
* DB migration includes data migration from progresses to states and should handle the transition over
to the new states but will require some testing