Browse Source

Create method to downcase a question, but only the first character, excluding within validate methods

pull/2674/head
Manny Dinssa 2 years ago
parent
commit
21074da537
  1. 5
      app/helpers/formatting_helper.rb
  2. 12
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  3. 8
      app/services/bulk_upload/lettings/year2024/row_parser.rb
  4. 12
      app/services/bulk_upload/sales/year2023/row_parser.rb
  5. 8
      app/services/bulk_upload/sales/year2024/row_parser.rb

5
app/helpers/formatting_helper.rb

@ -3,4 +3,9 @@ module FormattingHelper
return value if value.blank? return value if value.blank?
value.match?(/[[:punct:]]\z/) && !value.match?(/[(){}\[\]]\z/) ? value : "#{value}." value.match?(/[[:punct:]]\z/) && !value.match?(/[(){}\[\]]\z/) ? value : "#{value}."
end end
def downcase_first_letter(str)
return str if str.blank?
str[0].downcase + str[1..]
end
end end

12
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -544,9 +544,9 @@ private
fields.each do |field| fields.each do |field|
if setup_question?(question) if setup_question?(question)
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(QUESTIONS[field])&.downcase), category: :setup) errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field]))), category: :setup)
else else
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(QUESTIONS[field])&.downcase)) errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field]))))
end end
end end
end end
@ -764,14 +764,14 @@ private
fields.each do |field| fields.each do |field|
if errors.select { |e| fields.include?(e.attribute) }.none? if errors.select { |e| fields.include?(e.attribute) }.none?
question_text = question.error_display_label.presence || "this question." question_text = question.error_display_label.presence || "this question."
errors.add(field, I18n.t("validations.not_answered", question: question_text.downcase), category: :setup) if field.present? errors.add(field, I18n.t("validations.not_answered", question: downcase(question_text)), category: :setup) if field.present?
end end
end end
else else
fields.each do |field| fields.each do |field|
unless errors.any? { |e| fields.include?(e.attribute) } unless errors.any? { |e| fields.include?(e.attribute) }
question_text = question.error_display_label.presence || "this question." question_text = question.error_display_label.presence || "this question."
errors.add(field, I18n.t("validations.not_answered", question: question_text.downcase), category: :not_answered) errors.add(field, I18n.t("validations.not_answered", question: downcase(question_text)), category: :not_answered)
end end
end end
end end
@ -1607,4 +1607,8 @@ private
def is_carehome def is_carehome
field_127.present? ? 1 : 0 field_127.present? ? 1 : 0
end end
def downcase(str)
downcase_first_letter(str)
end
end end

8
app/services/bulk_upload/lettings/year2024/row_parser.rb

@ -568,9 +568,9 @@ private
fields.each do |field| fields.each do |field|
if setup_question?(question) if setup_question?(question)
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(QUESTIONS[field])&.downcase), category: :setup) errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field]))), category: :setup)
else else
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(QUESTIONS[field])&.downcase)) errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field]))))
end end
end end
end end
@ -1642,4 +1642,8 @@ private
def bulk_upload_organisation def bulk_upload_organisation
Organisation.find(bulk_upload.organisation_id) Organisation.find(bulk_upload.organisation_id)
end end
def downcase(str)
downcase_first_letter(str)
end
end end

12
app/services/bulk_upload/sales/year2023/row_parser.rb

@ -1243,13 +1243,13 @@ private
if setup_question?(question) if setup_question?(question)
fields.each do |field| fields.each do |field|
unless errors.any? { |e| fields.include?(e.attribute) } unless errors.any? { |e| fields.include?(e.attribute) }
errors.add(field, I18n.t("validations.not_answered", question: question.error_display_label&.downcase), category: :setup) errors.add(field, I18n.t("validations.not_answered", question: downcase(question.error_display_label)), category: :setup)
end end
end end
else else
fields.each do |field| fields.each do |field|
unless errors.any? { |e| fields.include?(e.attribute) } unless errors.any? { |e| fields.include?(e.attribute) }
errors.add(field, I18n.t("validations.not_answered", question: question.error_display_label&.downcase), category: :not_answered) errors.add(field, I18n.t("validations.not_answered", question: downcase(question.error_display_label)), category: :not_answered)
end end
end end
end end
@ -1271,13 +1271,13 @@ private
fields.each do |field| fields.each do |field|
if errors[field].none? if errors[field].none?
block_log_creation! block_log_creation!
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(QUESTIONS[field])&.downcase), category: :setup) errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field]))), category: :setup)
end end
end end
else else
fields.each do |field| fields.each do |field|
unless errors.any? { |e| fields.include?(e.attribute) } unless errors.any? { |e| fields.include?(e.attribute) }
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(QUESTIONS[field])&.downcase)) errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field]))))
end end
end end
end end
@ -1335,4 +1335,8 @@ private
errors.add(:field_35, "Buyer 1 cannot be a child under 16.") errors.add(:field_35, "Buyer 1 cannot be a child under 16.")
end end
end end
def downcase(str)
downcase_first_letter(str)
end
end end

8
app/services/bulk_upload/sales/year2024/row_parser.rb

@ -1407,13 +1407,13 @@ private
fields.each do |field| fields.each do |field|
if errors[field].none? if errors[field].none?
block_log_creation! block_log_creation!
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(QUESTIONS[field])&.downcase), category: :setup) errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field]))), category: :setup)
end end
end end
else else
fields.each do |field| fields.each do |field|
unless errors.any? { |e| fields.include?(e.attribute) } unless errors.any? { |e| fields.include?(e.attribute) }
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(QUESTIONS[field])&.downcase)) errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field]))))
end end
end end
end end
@ -1509,4 +1509,8 @@ private
def bulk_upload_organisation def bulk_upload_organisation
Organisation.find(bulk_upload.organisation_id) Organisation.find(bulk_upload.organisation_id)
end end
def downcase(str)
downcase_first_letter(str)
end
end end

Loading…
Cancel
Save