alphagov/transition — pull request #286 by jennyd (2014-05-21 13:53:40+00:00)
Title: Add a type column to mappings to use instead of http_status

This moves us towards being able to store users' decisions about mappings in the database without those decisions having to match up to real HTTP status codes; it will be Bouncer's responsibility to use the appropriate HTTP status code for each mapping type. This change enables us to introduce unresolved and pending content mapping types more cleanly, and lets us refer to a mapping's type using the same word everywhere, rather than having 'Type' in the UI and having to convert that to and from `http_status`.

What this does:

- Add the `type` column to the relevant tables and populate it from `http_status` for existing mappings and batches in a data migration
- Switch to using the new columns everywhere in Transition
- Continue to set `http_status` on mappings in a `before_validation` callback; this is essential because Bouncer still uses this column (and also do this on batches, for consistency)
- There should be no visible changes in the app
- Incidentally:
- rename a jasmine spec file so that it gets run, and make its tests pass as well as renaming things in it
- document the existence of a few '418' (pending content) mappings which were imported from Redirector and preserve their type in the new column

This is intended to be safe to deploy before the other required steps involved in this change. They are separate stories and will need to be deployed in the correct order after this one:

- Make Bouncer use a mapping's `type` instead of `http_status`
- Remove the `http_status` columns (from mappings and mappings batches) entirely

Some other considerations:

- Hits and related tables still have `http_status`: they represent real requests which got responses with real status codes, so should stay as they are.
- `Site` still has `global_http_status` - for consistency this should probably become `global_type`, but that change can be made later because it's not required for enabling new mapping types.
- `ActiveRecord` by default assumes that a `type` column should be used for [Single Table Inheritance](http://api.rubyonrails.org/v3.2.17/classes/ActiveRecord/Base.html#label-Single+table+inheritance), and tries to activate STI as soon as it sees such a column, so we need to override the name of the column which would be used for STI on the affected models to prevent this causing errors. This will also need to be done in Bouncer in the `Mapping` model.

The last remaining thing to do here, I think, is to tidy up the handling of `http_status` and `type` in the versions helpers, but I'd really appreciate more eyes on this to check my find-and-replacing and to hunt for anything I've missed (or replaced when I shouldn't have...).