alphagov/transition — pull request #227 by jennyd (2014-03-26 17:58:05+00:00)
Title: Fix Whitehall import overriding edits made by humans

This was caused by a bug in `Mapping.edited_by_human?` which meant that it would always return `false` for mappings which are not `from_redirector` (see 81dc72a for full details), and so the Whitehall import would update those mappings inappropriately. An example mapping affected by this is https://transition.production.alphagov.co.uk/sites/mod_dasa/mappings/525000/versions - the Whitehall import has repeatedly reverted edits made by a real user.

The source of this issue is our inconsistent configuration of PaperTrail, which records the history of mappings. Even though we had tests of each method involved, the differences in PaperTrail's configuration between model specs, controllers and the import code hid this bug from us. The real solution to this is to make our PaperTrail configuration consistent everywhere, as far as possible, and to make it easy to use correctly everywhere. This PR does this by:

- introducing a `Transition::History` module with methods which handle setting up and clearing the configuration, and asserting that it is correctly set when required
- before saving a mapping, ensuring that the configuration is set correctly if PaperTrail is enabled, so that we get quick feedback in development and can be sure that we are using it correctly in tests
- adding support for the mapping factory to specify a user to create the mapping as, defaulting to a stub user when we don't care about the user's details, which will be used in specs with `versioning: true`

We will need to clean up the mappings which have been affected by this bug by reverting them to the last version originating from a human user if there is one, but that should be done as a separate story.