Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The [original link fields] are used to determine where the action link text in the header should wrap when the landing page is being viewed in mobile view. For example, at the moment the fields contain "Find out how to stay safe and help" and "prevent the spread". On a desktop this is displayed as one line "Find out how to stay safe and help prevent the spread", but on a mobile, it wraps in the expected place. i.e. the use sees: "Find out how to stay safe and help" "prevent the spread" This commit provides two header text fields: `header_link_pre_wrap_text` and `header_link_post_wrap_text`. In the migration, I initially wanted to use (header_link_post_wrap_text omitted from the following examples to save space): ``` def change rename_column :coronavirus_pages, :header_link_text, :header_link_pre_wrap_text change_column :coronavirus_pages, :header_link_pre_wrap_text, :string end ``` However the linter threw a: ``` Rails/BulkChangeTable: You can use change_table :coronavirus_pages, bulk: true to combine alter queries. ``` error… hence using `bulk: true`. ``` def change change_table :coronavirus_pages, bulk: true do |t| t.rename :header_link_text, :header_link_pre_wrap_text t.string :header_link_pre_wrap_text end end ``` This did not remove the header_link_text and added the header_link_pre_wrap_text. I decided to remove the column instead: ``` def change change_table :coronavirus_pages, bulk: true do |t| t.remove :header_link_text t.string :header_link_pre_wrap_text end end ``` However the linter threw a `Rails/ReversibleMigration` error. I therefore used `up` and `down` methods to make the migration reversable, as [suggested by the author of the cop]. Annoyingly `remove_column` is usually reversible with a `type` but the bulk [change_table syntax] does not allow a type to be specified. Its a bit convoluted to appease the linter... it seems to have been raised as an issue to [Rubocop] but oh well. [original link fields]: https://github.com/alphagov/govuk-coronavirus-content/blob/12bacb98cdfa9a96a8f6f344143be0be1361babd/content/coronavirus_landing_page.yml#L14-L15 [suggested by the author of the cop]: rubocop/rubocop-rails#110 (comment) [change_table syntax]: http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/change_table [Rubocop]: rubocop/rubocop-rails#161
- Loading branch information