Skip to content

Commit

Permalink
Merge pull request #3633 from alphagov/revert-3626-simplify-email-ale…
Browse files Browse the repository at this point in the history
…rt-title-builder

Revert "Remove unused pluralisation logic from email alert title builder"
  • Loading branch information
ChrisBAshton authored Jan 16, 2025
2 parents ef248a1 + 0d29093 commit 1f28c3d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
8 changes: 7 additions & 1 deletion app/lib/email_alert_title_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ def call
attr_reader :filter, :subscription_list_title_prefix, :facets

def prefix
if selected_facets.empty?
if facets.size == 1 && subscription_list_title_prefix.is_a?(Hash)
subscription_list_title_prefix[plural_or_single].to_s.strip
elsif selected_facets.empty?
subscription_list_title_prefix.to_s.strip
elsif subscription_list_title_prefix.present?
"#{subscription_list_title_prefix.strip} with"
end
end

def plural_or_single
filter.fetch(facets.first["facet_id"], []).length == 1 ? "singular" : "plural"
end

def suffix
return singular_suffix if facets.size == 1

Expand Down
4 changes: 2 additions & 2 deletions app/lib/search/query.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Facade that speaks to Search API. Combines a content item with
# search results from Search API.
# Facade that speaks to rummager. Combines a content item with
# search results from rummager.
module Search
class Query
SITE_SEARCH_FINDER_BASE_PATH = "/search/all".freeze
Expand Down
6 changes: 5 additions & 1 deletion features/fixtures/bad_input_email_signup.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
"filter": {
"document_type": "cma_case"
},
"subscription_list_title_prefix": "CMA cases"
"subscription_list_title_prefix": {
"singular": "CMA cases with the following case type: ",
"plural": "CMA cases with the following case types: ",
"many": "Competition and Markets Authority (CMA) cases: "
}
}
}
6 changes: 5 additions & 1 deletion features/fixtures/cma_cases_signup_content_item.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@
"filter": {
"format": "cma_case"
},
"subscription_list_title_prefix": "CMA cases"
"subscription_list_title_prefix": {
"singular": "CMA cases with the following case type: ",
"plural": "CMA cases with the following case types: ",
"many": "Competition and Markets Authority (CMA) cases: "
}
}
}
13 changes: 7 additions & 6 deletions spec/lib/email_alert_title_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
it { is_expected.to eq(subscription_list_title_prefix) }
end

context "when there is one facet with a string subscription_list_title_prefix" do
let(:subscription_list_title_prefix) { "Prefix" }

context "when there is one facet" do
let(:subscription_list_title_prefix) do
{ "singular" => "Prefix:", "plural" => "Prefixes:" }
end
let(:facets) do
[
{
Expand All @@ -67,19 +68,19 @@
context "when no choice is selected" do
let(:filter) { {} }

it { is_expected.to eq("Prefix") }
it { is_expected.to eq("Prefixes:") }
end

context "when one choice is selected" do
let(:filter) { { "facet_id" => %w[key_one] } }

it { is_expected.to eq("Prefix with topic name one") }
it { is_expected.to eq("Prefix: topic name one") }
end

context "when two choices are selected" do
let(:filter) { { "facet_id" => %w[key_one key_two] } }

it { is_expected.to eq("Prefix with topic name one and topic name two") }
it { is_expected.to eq("Prefixes: topic name one and topic name two") }
end
end

Expand Down

0 comments on commit 1f28c3d

Please sign in to comment.