Add lead and lead_ordering to edition_organisations and setup new associations and methods on Editions to access lead and supporting versions of edition_organisations and their organisations.
An Edition needs a lead organisation rather than just an organisation.
Change Edition factories to create lead organisations by default instead of just normal organisations.

To avoid changing loads of tests we turn the organisations attribute into an ignore and build lead_edtion_organisations with that in the background.
When creating a new edition, make sure it retains lead and supported organisations.
Fix importers to create editions that have lead organisations by supplying lead_edition_organisations attributes with EditionOrganisation instances in them, rather than poking directly onto the organisations association.

In passing we add a before_validation on Editions that makes sure that all of its EditionOrganistion instances have an edition instance that points to itself.  This gets around the case where you have a Edition instance and you try to add an EditionOrganisation instance that you built before you had access to the Edition and thus the EditionOrganisation fails validation because it has no Edition (e.g. exactly what happens in the importers).
First cut at UI for setting supporting and lead organisations.

Will try to use js-duplicate-fields to duplicate the entries rather than simply building some emtpy ones and forcing a limit on how many orgs can be associated.
Fix announcment_filter_json_presenter_test:

The new organisation structure on editions and factories to construct them mean that the organisations association of an edition is not populated by default after build (it's the lead_editions_organisations instead).  Just stub it for now.
Use skip_before_filter :build_edition instead of redefining it with a before_filter :build_edition in the national_applicability editions controller extension.

We do this because redefining it will leave it at the bottom of the stack, and other before_filters defined in edition_controller rely on it being run before them.
Add build_edition_organisations to build_edition_dependencies, so it there are still empty slots available on failed create and update views.
Fix up document and edition controller test helpers/macros to observe the new edition_organisations_attributes based attributes for editions.
In edition/document controller tests prefer controller_attributes_for in tests for create actions, and controller_attributes_for_instance for update actions, as these have been prepared to observe the edition_organisations_attributes structure.
Extract PublicationFilterJsonPresenterTest to its own file and while we're at it fix the sibling tests for presenters to stub organisations on the instances under test.
Fix PoliciesControllerTest::NationalApplicabilityTest to use the super behaviour for attributes_for_edition.
Update capybara to latest in the 1.1.x stream and update rack-test to a version that has a fix for arrays of hash params in multipart encoded forms.

The fix is not yet in rack-test, so we're using our own copy until https://github.com/brynary/rack-test/pull/69 is merged and a new version is released.
Change document and policy steps/helpers for cucumber to cope with the new lead organisations form.
Extract edition_organisations_attributes fields into a helper on the edition_form_builder.

Also because we submit our changes to edition_organisations_attributs we should look to see if the object in the form has errors.  If it does we should render the fields based on edition_organisations rather than lead_edition_organisations or supporting_edition_organisations, if it doesn't we can use the simpler API of lead_edition_organisations or supporting_edition_organisations.  We then have to do the same thing in build_edition_organisations too to make sure that we have enough "empty" objects lying around to present to the user.
When creating speeches mark the organisation of the role_appointment as a lead organisation.
Add validation to detect and disallow duplicate organisations being added via the edition_organisations associations on an edition.

We're not using validate_uniqueness_of because it won't give us a nice error (probably just edition_organisations is invalid).  Hence the slightly complex validation method on the Edition itself.
Remove edition_organisations.js as it was committed in error.

It was originally part of a sketch for how the UI might work for selecting
lead organisations on a document and has since been superseded by a much
simpler UI.
Use lead_organisations when rendering organisations for a document