alphagov/content-planner — pull request #66 by RuslanHamidullin (2014-05-05 17:36:51+00:00)
Title: 68355394 store needs in db

- added api_id column to Organisation model
because needs api returns organisation_ids with ids of Organisations.
https://github.com/alphagov/govuk_need_api/blob/master/test/functional/needs_controller_test.rb#L150
example:
organisation_ids: ["cabinet-office","department-for-transport"]
- corrected ImportOrganisations script (added saving of api_id)
- added ImportNeeds task
- corrected related associations ContentNeed and ContentPlanNeed
So, these to tables stored api id of need in need_id
Now when we store Needs in out db table it should store id of database entry
- corrected calls to needs in app
- corrected Rspec tests

Important note:
1. migration 20140505144311_correct_needs_associations_structure.rb
is oriented to correct Needs realated associations ContentNeed and ContentPlanNeed.
So, it's important to have in db already populated Organisations and Needs.
So, API_CLIENT_CREDENTIALS should not be empty if you are running it on staging or prod envs.
If you run it in dev env - you can uncomment line 15:
# PopulateOrganisationAndNeedForDevEnv.run
This will populate test Organisation and Needs.

2. In case if you already run rake db:migrate, but needs db table was empty
- you can then run:
rake db:import to import needs from API or
rake db:populate_organisation_and_need_for_dev_env if you have no access to API
- and the run:
rake db:correct_need_associations - it will correct ContentPlanNeed and ContentNeed tables