Skip to content

Commit

Permalink
Add header text wrap fields
Browse files Browse the repository at this point in the history
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
Rosa-Fox authored and leenagupte committed Oct 28, 2021
1 parent b7d3383 commit 1bda6c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
17 changes: 17 additions & 0 deletions db/migrate/20211019142632_add_header_link_wrap_text_fields.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class AddHeaderLinkWrapTextFields < ActiveRecord::Migration[6.1]
def up
change_table :coronavirus_pages, bulk: true do |t|
t.remove :header_link_text
t.string :header_link_pre_wrap_text
t.string :header_link_post_wrap_text
end
end

def down
change_table :coronavirus_pages, bulk: true do |t|
t.text :header_link_text
t.remove :header_link_pre_wrap_text
t.remove :header_link_post_wrap_text
end
end
end
5 changes: 3 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_10_08_133209) do
ActiveRecord::Schema.define(version: 2021_10_19_142632) do

create_table "coronavirus_announcements", charset: "utf8", force: :cascade do |t|
t.bigint "coronavirus_page_id", null: false
Expand All @@ -37,7 +37,8 @@
t.string "header_title"
t.text "header_body"
t.text "header_link_url"
t.text "header_link_text"
t.string "header_link_pre_wrap_text"
t.string "header_link_post_wrap_text"
end

create_table "coronavirus_sub_sections", charset: "utf8", force: :cascade do |t|
Expand Down

0 comments on commit 1bda6c8

Please sign in to comment.