Skip to content

Re-organise routing in preparation for Maths & Physics - #597

Merged
tekin merged 8 commits into
masterfrom
maths-and-physics-routing
Nov 7, 2019
Merged

Re-organise routing in preparation for Maths & Physics#597
tekin merged 8 commits into
masterfrom
maths-and-physics-routing

Conversation

@tekin

@tekin tekin commented Nov 7, 2019

Copy link
Copy Markdown
Contributor

This should be the last PR laying the groundwork for introducing the Maths & Physics policy to the service. Several changes have been made to make it possible to drop in additional policies:

  • Introduced the Policies so that we have a global list of available policies to work with
  • routing.rb now generates routes for multiple policies, based on what is defined in Policies
  • views can be organised by policy, with policy specific ones living in their own folder
  • the hardcoded links to the Student Loans start page have been made dynamic

tekin added 2 commits November 7, 2019 14:54
These pages are for claimants primarily, they are not really relevant to
internal service operator users. Besides which we've made them
policy-aware, so soon it won't be clear which version they should even
link to when Maths & Physics is introduced.
A lot of the previous Maths & Physics preparation work was leading to
this moment where we can remove the default policy in the routing and
be explicit about the current active `:policy` in the app code. Now it
will be possible to introduce additional policy routing without breaking
any of the existing views, controllers or spec code.

To keep the rendering of the maintenace page working,
current_policy_routing_name had to be overriden in StaticPagesController
as the catch-all route for maintenance mode won't include a value for
:policy in the params.

Note that at the moment there is little to distinguish the specs that
have to be coupled to the policy, for example
spec/features/student_loans_claim_spec.rb, and those that shoud be more
generic as they cover behaviour that is policy-agnostic, such as
spec/requests/claims_spec.rb. At some point very soon these specs should
be rationalised to make it obvious which are testing behaviour specific
to a given policy, and which are policy-agnostic.
@tekin
tekin force-pushed the maths-and-physics-routing branch 2 times, most recently from 795b7e2 to e4c34a1 Compare November 7, 2019 15:20
@mec mec self-assigned this Nov 7, 2019

@mec mec left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good. I just had one question…

Comment thread config/routes.rb Outdated
tekin added 6 commits November 7, 2019 16:28
This makes it such that introducing routing for Maths & Physics will
simply be a case of defining a `MathsAndPhysics::SlugSequence` and
adding the `MathsAndPhysics` module to the array of `policies`.

I've made use of a routing constraint object here as I struggled to get
the routing to work just using the default constraints and defaults when
a second policy was introduced.
Because the routes for the verify actions are not namespaced to a
particular policy it won't be possible for the controller to redirect
users to a start page if they visit the URLs without an active claim. We
can redirect these requests to the root, which will be handled
appropriately, either as it is now by redirecting to the Student Loans
start page, or in the future when we introduce a page for lost users
pointing at both policies once Maths & Physics is introduced.
This gives us a global place where we can perform policy-based lookups.
To now PartOfClaimJourney was coupled to the StudentLoans policy. This
updates it so that it will correctly initialise new claims and redirect
unstarted claimants according to the actual policy defined by the
routing parameters. Note that current_claim needs to be able to behave
even when there is no `params[:policy]` because
Verify::AuthenticationsController is not namespaced by policy.
This allows us to keep each policy's views separate from each other,
whilst also sharing those that are common between them.

Because current_policy_routing_name is now being called in a
before_action, we need to explicitly unset the instance variable that
stores current_claim as it gets set when `current_policy_routing_name`
is called.
@tekin
tekin force-pushed the maths-and-physics-routing branch from e4c34a1 to 6509d7c Compare November 7, 2019 16:29

@pezholio pezholio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good - just one suggestion on the routes, but not a blocker

Comment thread app/models/policies.rb Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super useful, this 👍

Comment thread config/routes.rb
resources :claims, only: [:show, :update], param: :slug, path: "/"
# Used to constrain claim journey routing so only slugs
# that are part of a policy’s slug sequence are routed.
class RestrictToSequenceSlugs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit iffy about having the class inline in the routing block. Would it be OK to have it up top, so it makes the routes easier to read?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I like having the class near to where it is being used as it places it closer to the context in which it needs to be understood.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No drama. Happy for it to stay where it is in that case 👍

@robbiepaul robbiepaul left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some pretty nifty changes here. I learnt about prepend_view_path today 👍

@tekin
tekin merged commit 1f96ba2 into master Nov 7, 2019
@tekin
tekin deleted the maths-and-physics-routing branch November 7, 2019 20:18
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.

4 participants