diff --git a/app/helpers/tab_nav_helper.rb b/app/helpers/tab_nav_helper.rb index 68caf16c1..5b8a74bb1 100644 --- a/app/helpers/tab_nav_helper.rb +++ b/app/helpers/tab_nav_helper.rb @@ -1,32 +1,44 @@ -module TabNavHelper - include GovukLinkHelper - include Helpers - def user_cell(user) - link_text = user.name.presence || user.email - [govuk_link_to(link_text, user), "User #{user.email}"].join("\n") - end + module TabNavHelper + include GovukLinkHelper + include Helpers + using FormatPostcode + - def location_cell(location, link) - link_text = location.postcode.formatted_postcode - [govuk_link_to(link_text, link, method: :patch), "Location #{location.name}"].join("\n") - end + def user_cell(user) + link_text = user.name.presence || user.email + [govuk_link_to(link_text, user), "User #{user.email}"].join("\n") + end +<<<<<<< Updated upstream def scheme_cell(scheme) link_text = scheme.service_name link = scheme.confirmed? ? scheme : scheme_check_answers_path(scheme) [govuk_link_to(link_text, link), "Scheme #{scheme.primary_client_group}"].join("\n") end +======= + def location_cell(location, link) + + link_text = location.postcode.formatted_postcode + [govuk_link_to(link_text, link, method: :patch), "Location #{location.name}"].join("\n") + end +>>>>>>> Stashed changes - def org_cell(user) - role = "#{user.role.to_s.humanize}" - [user.organisation.name, role].join("\n") - end + def scheme_cell(scheme) + link_text = scheme.service_name + [govuk_link_to(link_text, scheme), "Scheme #{scheme.primary_client_group}"].join("\n") + end - def tab_items(user) - [ - { name: t("Details"), url: details_organisation_path(user.organisation) }, - { name: t("Users"), url: users_organisation_path(user.organisation) }, - ] + def org_cell(user) + role = "#{user.role.to_s.humanize}" + [user.organisation.name, role].join("\n") + end + + def tab_items(user) + [ + { name: t("Details"), url: details_organisation_path(user.organisation) }, + { name: t("Users"), url: users_organisation_path(user.organisation) }, + ] + end end -end + diff --git a/app/models/form/setup/questions/location_id.rb b/app/models/form/setup/questions/location_id.rb index 1fa8e82e2..fa243c62f 100644 --- a/app/models/form/setup/questions/location_id.rb +++ b/app/models/form/setup/questions/location_id.rb @@ -1,4 +1,5 @@ class Form::Setup::Questions::LocationId < ::Form::Question + using FormatPostcode def initialize(_id, hsh, page) super("location_id", hsh, page) @check_answer_label = "Location" diff --git a/app/postcode_app.rb b/app/postcode_app.rb new file mode 100644 index 000000000..d532947d9 --- /dev/null +++ b/app/postcode_app.rb @@ -0,0 +1,17 @@ +module FormatPostcode + refine FormatPostcode do + def formatted_postcode + postcode = upcase.gsub(/\s+/, "") + case postcode.length + when 5 + postcode.insert(2, " ") + when 6 + postcode.insert(3, " ") + when 7 + postcode.insert(4, " ") + else + self + end + end + end + \ No newline at end of file diff --git a/lib/ext/string.rb b/lib/ext/string.rb deleted file mode 100644 index 1e9bad95a..000000000 --- a/lib/ext/string.rb +++ /dev/null @@ -1,15 +0,0 @@ -class String - def formatted_postcode - postcode = upcase.gsub(/\s+/, "") - case postcode.length - when 5 - postcode.insert(2, " ") - when 6 - postcode.insert(3, " ") - when 7 - postcode.insert(4, " ") - else - self - end - end -end diff --git a/spec/features/form/postcode_format_spec.rb b/spec/features/form/postcode_format_spec.rb deleted file mode 100644 index 36c2460a0..000000000 --- a/spec/features/form/postcode_format_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require "rails_helper" -require_relative "helpers" - -RSpec.describe "Postcode formatting" do - include Helpers - let(:user) { FactoryBot.create(:user) } - let(:case_log) do - FactoryBot.create( - :case_log, - :in_progress, - owning_organisation: user.organisation, - managing_organisation: user.organisation, - ) - end - let(:id) { case_log.id } - - before do - sign_in user - end - - context "when a postcode is input" do - it "for a 6 character postcode a space will be after the third character" do - visit("/logs/#{id}/property-postcode") - fill_in("case-log-postcode-full-field", with: "aa11aa") - click_button("Save and continue") - visit("/logs/#{id}/property-information/check-answers") - expect(page).to have_text("AA1 1AA") - end - - it "for a 5 character postcode a space will be after the second character" do - visit("/logs/#{id}/property-postcode") - fill_in("case-log-postcode-full-field", with: "a99aa") - click_button("Save and continue") - visit("/logs/#{id}/property-information/check-answers") - expect(page).to have_text("A9 9AA") - end - end -end