diff --git a/app/helpers/formatting_helper.rb b/app/helpers/formatting_helper.rb index 48a296e83..1f692a994 100644 --- a/app/helpers/formatting_helper.rb +++ b/app/helpers/formatting_helper.rb @@ -2,7 +2,7 @@ module FormattingHelper def ensure_punctuation(value) return value if value.blank? - value.match?(/[[:punct:]]\z/) && !value.match?(/[(){}\[\]]\z/) ? value : "#{value}." + value.match?(/[[:punct:]]\z/) && !value.match?(/[%(){}\[\]]\z/) ? value : "#{value}." end def downcase_first_letter(sentence) diff --git a/spec/models/form/question_spec.rb b/spec/models/form/question_spec.rb index cce1d07c3..41e8862d5 100644 --- a/spec/models/form/question_spec.rb +++ b/spec/models/form/question_spec.rb @@ -381,16 +381,19 @@ RSpec.describe Form::Question, type: :model do let(:question_with_error_label_with_full_stop) { described_class.new("address_line1_input", { "header" => "Address line 1", "error_label" => "Address line 1." }, page) } let(:question_with_error_label_with_question_mark) { described_class.new("address_line1_input", { "header" => "Address line 1", "error_label" => "Address line 1?" }, page) } let(:question_with_error_label_with_brackets) { described_class.new("address_line1_input", { "header" => "Address line 1", "error_label" => "(Address line 1)" }, page) } + let(:question_with_error_label_with_percentage) { described_class.new("address_line1_input", { "header" => "Address line 1", "error_label" => "Address line 1%" }, page) } let(:question_with_check_answer_label_no_punctuation) { described_class.new("address_line1_input", { "header" => "Address line 1", "check_answer_label" => "Address line 1" }, page) } let(:question_with_check_answer_label_with_full_stop) { described_class.new("address_line1_input", { "header" => "Address line 1", "check_answer_label" => "Address line 1." }, page) } let(:question_with_check_answer_label_with_question_mark) { described_class.new("address_line1_input", { "header" => "Address line 1", "check_answer_label" => "Address line 1?" }, page) } let(:question_with_check_answer_label_with_brackets) { described_class.new("address_line1_input", { "header" => "Address line 1", "check_answer_label" => "(Address line 1)" }, page) } + let(:question_with_check_answer_label_with_percentage) { described_class.new("address_line1_input", { "header" => "Address line 1", "check_answer_label" => "Address line 1%" }, page) } let(:question_with_header_no_punctuation) { described_class.new("address_line1_input", { "header" => "Address line 1" }, page) } let(:question_with_header_with_full_stop) { described_class.new("address_line1_input", { "header" => "Address line 1." }, page) } let(:question_with_header_with_question_mark) { described_class.new("address_line1_input", { "header" => "Address line 1?" }, page) } let(:question_with_header_with_brackets) { described_class.new("address_line1_input", { "header" => "(Address line 1)" }, page) } + let(:question_with_header_with_percentage) { described_class.new("address_line1_input", { "header" => "Address line 1%" }, page) } let(:question_with_id_only_no_punctuation) { described_class.new("address_line1_input", {}, page) } @@ -429,6 +432,10 @@ RSpec.describe Form::Question, type: :model do expect(question_with_error_label_with_brackets.error_display_label).to eq("(Address line 1).") end + it "returns the error label with percentage changed to with a full stop" do + expect(question_with_error_label_with_percentage.error_display_label).to eq("Address line 1%.") + end + it "returns the check answer label with no punctuation changed with a full stop" do expect(question_with_check_answer_label_no_punctuation.error_display_label).to eq("Address line 1.") end @@ -437,6 +444,10 @@ RSpec.describe Form::Question, type: :model do expect(question_with_check_answer_label_with_brackets.error_display_label).to eq("(Address line 1).") end + it "returns the check answer label with percentage changed with a full stop" do + expect(question_with_check_answer_label_with_percentage.error_display_label).to eq("Address line 1%.") + end + it "returns the header with no punctuation changed with a full stop" do expect(question_with_header_no_punctuation.error_display_label).to eq("Address line 1.") end @@ -445,6 +456,10 @@ RSpec.describe Form::Question, type: :model do expect(question_with_header_with_brackets.error_display_label).to eq("(Address line 1).") end + it "returns the header with percentage changed with a full stop" do + expect(question_with_header_with_percentage.error_display_label).to eq("Address line 1%.") + end + it "returns the id with no punctuation changed with a full stop" do expect(question_with_id_only_no_punctuation.error_display_label).to eq("Address line1 input.") end