Use FactoryGirl.build_stubbed instead of a hand-rolled solution.

`FactoryGirl.build_stubbed` takes care of all this (and more).

I had run into problems with the previous implementation where, because
the "stub record" was still an instance of the `ActiveRecord::Base`
subclass (albeit with lots of stubbed method), and because its
`#new_record?` method returned `true`, it was possible for a database
query to be initiated by something as simple as inspecting the record or
calling an association method.

This problem was compounded in the cases I saw, because Mocha tried to
report the unexpected invocation of `select` on the `ActiveRecord`
connection, but in doing so it also wanted to list the stubbed methods
on the record. The latter caused a recursive call to the record's
`#inspect` method and an eventual stack overflow error.
Sort by timestamp then by document_id

Publications get a date for public_timestamp. This can cause many
timestamps to be the same. In those instances the order which the items
came out of the database was non-determanistic. This will ensure that
they come out in a pre-defined order, even if document is editioned.

https://www.pivotaltracker.com/story/show/45188181
Revert "Reverting "Data migration to add mainstream categories for DCMS""

We have the correct mainstream subcategories now.

This reverts commit 0a8d509790e1282e8116fa64a05835485c1c45b2 to reinstate (a corrected) commit 7fe82c9a425e61ee5dbfb7c8ee92f8ad825668b5.

For: https://www.pivotaltracker.com/story/show/45057197
Make DCMS migration idempotent

We need to run this manually on production urgently, so best to make
this work without errors.
Revert "Use FactoryGirl.build_stubbed instead of a hand-rolled solution."

This reverts commit 13237e4ea7e54c4d3bc9bd8d244fe08ff0655b2f.

For some reason this was causing a seg fault on CI.
Make the admin navigation only contain 3 items

The admin nav bar was getting very very long. It was decided that
everything other than "Documents", "Document series" and "[My
department]" should be moved under a sub-nav item.

https://www.pivotaltracker.com/story/show/44907221
https://www.pivotaltracker.com/story/show/45162979
Fix DCMS brand colour

This changes them from the generic (and wrong) black to their preferred
magenta-ish thing.

https://www.pivotaltracker.com/story/show/44964555
Ensure only one json next link exists on the page

Due to the way slimmer moves the next link to the header we were ending
up with multiple links on the page. This ensures that one is removed
before adding the next one.

The new one should really be added to the head of the page but this will
do for now.
Force downloads to have an extension if invalid

Some URLs are of the form "filename.version1" etc, which Ruby thinks is
an extension. We want to cause these URLs to have an extension appended
using the regular logic.

To achieve this I've made the extension_white_list functionality
publicly available and used it to determine if what Ruby thinks is the
file extension is invalid, then give the file an extension.

Pivotal Ticket for this was closed.
Reduce number of tests around showing govspeak

The `should_allow_showing_of` test macro was used in 10 controller tests. The
test in the macro was exercising logic in the 'editions/document_preview'
partial which is shared by all of these controllers. By changing these tests
to use the `GenericEditionsController` we reduce the number of functional
tests by 9 (from 10 to 1).
Reduce number of tests around audit trail

The `should_show_document_audit_trail_for` test macro was used in 9 controller
tests. The test in the macro was exercising logic in the
'editions/audit_trail_entry' partial which is shared by all of these
controllers. By changing these tests to use the `GenericEditionsController` we
reduce the number of functional tests by 16 (from 18 to 2).

*NOTE* I've had to create an empty 'generic_editions/_form' partial so that we
can render 'editions/edit' correctly.
Introduce the GenericEditionsControllerTest

This allows me to test that the `GenericEditionsController` inherits from
`Admin::EditionsController` in a single place.
Reduce number of tests around unpublishing

The `should_allow_unpublishing_for` test macro was used in 10 controller
tests. The tests in the macro were exercising logic in the
'editions/navigation' partial which is shared by all of these controllers. By
changing these tests to use the `GenericEditionsController` we can reduce the
number of functional tests by 18 (from 20 to 2).
Reduce number of tests around revising

The `should_allow_revision_of` test macro was used in 7 controller tests. The
tests in the macro were exercising logic in the 'editions/navigation' partial
which is shared by all of these controllers. By changing these tests to use
the `GenericEditionsController` we can reduce the number of functional tests
by 18 (from 21 to 3).
Reduce number of tests around deleting

The `should_be_able_to_delete_an_edition` test macro was used in 10 controller
tests. The tests in the macro were exercising logic in the
'editions/navigation' partial and the editions controller, all of which are
shared by these controllers. By changing these tests to use the
`GenericEditionsController` we can reduce the number of functional tests by 63
(from 70 to 7).

*NOTE*. It should be possible to further simplify the tests for the
presence/absence of the delete button as the template only switches based on
the value of `Edition#deletable?` (i.e. it doesn't care about the actual state
of the edition).
Reduce number of tests around viewing

The `should_link_to_public_version_when_published` and its counterpart,
`should_not_link_to_public_version_when_not_published` test macros were both
used in 10 controller tests. The two tests in those macros were exercising
logic in the 'editions/navigation' partial which is shared by all those
controllers. By changing these tests to use the `GenericEditionsController` we
can reduce the number of functional tests by 18 (20 down to 2).
Reduce number of tests around previewing

The `should_link_to_preview_version_when_not_published` test macro was used in
10 controller tests. The single test in that macro was exercising logic in the
'editions/navigation' partial which is shared by all those controllers. By
changing these tests to use the `GenericEditionsController` we can reduce the
number of functional tests by 9 (from 10 to 1).
Reduce number of tests around rejecting

The `should_be_rejectable` test macro was used in 10 controller tests. The
tests in that macro were exercising the 'editions/navigation' partial, the
'editions/rejected_by' partial, and the 'editions/audit_trail_entry' partial;
all of which are shared by those controllers. By changing these tests to use
the `GenericEditionsController` we can reduce the number of functional tests
by 45 (from 50 to 5).
Reduce number of tests around publishing

The `should_be_publishable` test macro was used in 10 controller tests. The
tests in the macro were exercising logic in the 'editions/navigation' partial
which is shared by all of these controllers. By changing these tests to use
the `GenericEditionsController` we can reduce the number of functional tests
by 18 (from 20 to 2).
Reduce number of tests around force publishing

The `should_be_force_publishable` test macro was used in 10 controller tests.
The tests in the macro were exercising logic in the 'editions/navigation'
partial which is shared by all of these controllers. By changing these tests
to use the `GenericEditionsController` we can reduce the number of functional
tests by 54 (from 60 to 6).