Skip to content

Conversation

@dsingleton
Copy link
Contributor

Taking this approach simplifies the code significantly, keeping the relationship to Government encapsulated in Edition, and there's not a need to de-normalise onto Document yet, and if becomes needed it can be added and backfilled then.

Changes:

  • Gets the right government for Speech, using the delivered_on in preference to first_published_at, as there are many examples where delivered_on is much earlier.
  • Government is now exposed by Edition#government, and derived at run-time, rather than being set during publishing.
  • Removes the Document.government field - which isn't used anywhere yet.
  • Adds factories for tests creating Governments and refactors the tests to be more readable.

This supports:

Paired with @tekin

dsingleton and others added 7 commits March 3, 2015 15:12
Government was set based on `first_published_at`, which does not work for consultations and speeches;

 - Consultations do not set a `first_published_at`
 - Speeches have a `delivered_on`, which may be different from
   `first_published_at`, and is usually earlier.

Add a new method to expose the right date to identify a Government responsible for the Edition.
This association is not used anywhere in the app. Getting rid of it
as a pre step to refactoring the derivation of government on editions.
We've moving away from Government being set on Document, and 
instead being derived from the Edition itself.

Move the "which government owns this edition" logic into the Edition model itself. Update the publishing workflow to use this, rather than having to know about Edition/Government relationships.
We now derive Government from an Edition, on demand, rather than pre-calculating it and storing it on Document.
- Break date related tests into their own class
- Use new government factories
- Generally much easier to read and understand intent 👍
Don't use :scope when returning a single value, use class methods
instead.

Remove redundant nil (implicit from return) and make the guard vs
lookup more distinct
@edds
Copy link
Contributor

edds commented Mar 4, 2015

👍 Good changes.

dsingleton added a commit that referenced this pull request Mar 4, 2015
Derive Government from Edition at run-time, rather than persisting on Document
@dsingleton dsingleton merged commit 99a80de into master Mar 4, 2015
@dsingleton dsingleton deleted the government-on-edition branch March 4, 2015 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants