Skip to content

Commit

Permalink
Prevent withdrawal notices on translated editions displaying multiple…
Browse files Browse the repository at this point in the history
… languages

Currently a withdrawn translated edition may display the majority of the
withdrawal notice title in English, but with dates and publication type
in the chosen locale.

Until withdrawal notices are also available via I18n, this PR will ensure
only English is displayed.
  • Loading branch information
edwardkerry committed Apr 18, 2019
1 parent 22fdff9 commit 31203cf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/presenters/content_item/withdrawable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ def withdrawal_notice_title
end

def withdrawal_notice_context
I18n.t("content_item.schema_name.#{schema_name}", count: 1)
I18n.t("content_item.schema_name.#{schema_name}", count: 1, locale: :en)
end

def withdrawal_notice_time
content_tag(:time, display_date(withdrawal_notice["withdrawn_at"]), datetime: withdrawal_notice["withdrawn_at"])
content_tag(:time, english_display_date(withdrawal_notice["withdrawn_at"]), datetime: withdrawal_notice["withdrawn_at"])
end

def english_display_date(timestamp, format = "%-d %B %Y")
I18n.l(Time.zone.parse(timestamp), format: format, locale: :en) if timestamp
end
end
end
30 changes: 29 additions & 1 deletion test/presenters/content_item/withdrawable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ class ContentItemWithdrawableTest < ActiveSupport::TestCase
def setup
@withdrawable = Object.new
@withdrawable.extend(ContentItem::Withdrawable)
I18n.locale = :cy
end

def teardown
I18n.locale = I18n.default_locale
end

test 'content item is withdrawn' do
Expand Down Expand Up @@ -60,7 +65,30 @@ def content_item
end
end

assert_equal @withdrawable.withdrawal_notice_component[:title], "This news article was withdrawn on <time datetime=\"2016-07-12T09:47:15Z\">2016-07-12T09:47:15Z</time>"
assert_equal @withdrawable.withdrawal_notice_component[:title], "This news article was withdrawn on <time datetime=\"2016-07-12T09:47:15Z\">12 July 2016</time>"
assert_equal @withdrawable.withdrawal_notice_component[:description_govspeak], "<div class='govspeak'><p>It has been superseded by <a href='https://www.gov.uk/government/statistics/local-area-walking-and-cycling-in-england-2014-to-2015'>Local area walking and cycling in England: 2014 to 2015</a>.</p>\\n</div>"
end

test 'notice title presents only in English, even if locale is set to another language' do
# This is to prevent the withdrawal notices on translated editions
# displaying a combination of languages in their titles.
class << @withdrawable
def schema_name
'publication'
end

def content_item
{
'title' => 'Proportion of residents who do any walking or cycling (at local authority level) (CW010)',
'withdrawn_notice' => {
'explanation' => '<div class=\'govspeak\'><p>It has been superseded by <a href=\'https://www.gov.uk/government/statistics/local-area-walking-and-cycling-in-england-2014-to-2015\'>Local area walking and cycling in England: 2014 to 2015</a>.</p>\n</div>',
'withdrawn_at' => '2016-07-12T09:47:15Z'
},
'locale': 'cy'
}
end
end

assert_equal @withdrawable.withdrawal_notice_component[:title], "This publication was withdrawn on <time datetime=\"2016-07-12T09:47:15Z\">12 July 2016</time>"
end
end

0 comments on commit 31203cf

Please sign in to comment.