Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

monetary values error messages #4478

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/forms/state_file/az_charitable_contributions_form.rb
Expand Up @@ -3,10 +3,11 @@ class AzCharitableContributionsForm < QuestionsForm
set_attributes_for :intake, :charitable_contributions, :charitable_cash, :charitable_noncash

validates :charitable_contributions, inclusion: { in: %w[yes no], message: :blank }
validates_numericality_of :charitable_cash, only_integer: true, message: :whole_number, if: -> { charitable_contributions == "yes" }
validates :charitable_cash, presence: true, numericality: { greater_than_or_equal_to: 0 }, allow_blank: false, if: -> { charitable_contributions == "yes" }
validates_numericality_of :charitable_noncash, only_integer: true, message: :whole_number, if: -> { charitable_contributions == "yes" }
validates :charitable_noncash, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 500 }, allow_blank: false, if: -> { charitable_contributions == "yes" }
validates_numericality_of :charitable_cash, only_integer: true, message: :whole_number, if: -> { charitable_contributions == "yes" && charitable_cash.present? }
validates :charitable_cash, numericality: { greater_than_or_equal_to: 1, message: ->(_object, _data) { I18n.t('errors.messages.greater_than_or_equal_to', count: 1)} }, if: -> { charitable_contributions == "yes" }
validates_numericality_of :charitable_noncash, only_integer: true, message: :whole_number, if: -> { charitable_contributions == "yes" && charitable_noncash.present? }
validates :charitable_noncash, numericality: { greater_than_or_equal_to: 1, message: ->(_object, _data) { I18n.t('errors.messages.greater_than_or_equal_to', count: 1)} }, if: -> { charitable_contributions == "yes" }
validates :charitable_noncash, numericality: { less_than_or_equal_to: 500, message: ->(_object, _data) { I18n.t('errors.messages.less_than_or_equal_to', count: 500)} }, if: -> { charitable_contributions == "yes" }


def save
Expand Down
8 changes: 4 additions & 4 deletions app/forms/state_file/az_state_credits_form.rb
Expand Up @@ -2,10 +2,10 @@ module StateFile
class AzStateCreditsForm < QuestionsForm
set_attributes_for :intake, :tribal_member, :tribal_wages, :armed_forces_member, :armed_forces_wages

validates_numericality_of :tribal_wages, only_integer: true, message: :whole_number, if: -> { tribal_member == "yes" }
validates :tribal_wages, presence: true, allow_blank: false, numericality: { greater_than_or_equal_to: 1 }, if: -> { tribal_member == "yes" }
validates_numericality_of :armed_forces_wages, only_integer: true, message: :whole_number, if: -> { armed_forces_member == "yes" }
validates :armed_forces_wages, presence: true, allow_blank: false, numericality: { greater_than_or_equal_to: 1 }, if: -> { armed_forces_member == "yes" }
validates_numericality_of :tribal_wages, only_integer: true, message: :whole_number, if: -> { tribal_member == "yes" && tribal_wages.present? }
validates :tribal_wages, numericality: { greater_than_or_equal_to: 1, message: ->(_object, _data) { I18n.t('errors.messages.greater_than_or_equal_to', count: 1)} }, if: -> { tribal_member == "yes" }
validates_numericality_of :armed_forces_wages, only_integer: true, message: :whole_number, if: -> { armed_forces_member == "yes" && armed_forces_wages.present? }
validates :armed_forces_wages, numericality: { greater_than_or_equal_to: 1, message: ->(_object, _data) { I18n.t('errors.messages.greater_than_or_equal_to', count: 1)} }, if: -> { armed_forces_member == "yes" }
validate :below_1040_amount, if: -> { tribal_wages.present? || armed_forces_wages.present? }

def save
Expand Down
2 changes: 1 addition & 1 deletion app/forms/state_file/taxes_owed_form.rb
Expand Up @@ -15,7 +15,7 @@ class TaxesOwedForm < TaxRefundForm
with_options unless: -> { payment_or_deposit_type == "mail" } do
validate :date_electronic_withdrawal_is_valid_date
validate :withdrawal_date_before_deadline, if: -> { date_electronic_withdrawal.present? }
validates :withdraw_amount, presence: true, numericality: { greater_than: 0 }
validates :withdraw_amount, numericality: { greater_than: 0, message: ->(_object, _data) { I18n.t('errors.messages.greater_than_or_equal_to', count: 0)} }
validate :withdraw_amount_higher_than_owed?
end

Expand Down
12 changes: 6 additions & 6 deletions app/models/state_file1099_g.rb
Expand Up @@ -46,12 +46,12 @@ class StateFile1099G < ApplicationRecord
validates :recipient_street_address_apartment, format: { :with => /\A[a-zA-Z0-9\/\s-]+\z/.freeze, message: ->(_object, _data) { I18n.t("errors.attributes.address.street_address.invalid") }}, allow_blank: true
validates :recipient_city, presence: true, format: { with: /\A[a-zA-Z\s]+\z/.freeze, message: ->(_object, _data) { I18n.t("errors.attributes.address.city.invalid") }}
validates :recipient_zip, zip_code: { zip_code_lengths: [5, 9, 12].freeze }
validates_numericality_of :unemployment_compensation, only_integer: true, message: :whole_number
validates :unemployment_compensation, numericality: { greater_than_or_equal_to: 1 }
validates_numericality_of :federal_income_tax_withheld, only_integer: true, message: :whole_number
validates :federal_income_tax_withheld, numericality: { greater_than_or_equal_to: 0}
validates_numericality_of :state_income_tax_withheld, only_integer: true, message: :whole_number
validates :state_income_tax_withheld, numericality: { greater_than_or_equal_to: 0}
validates_numericality_of :unemployment_compensation, only_integer: true, message: :whole_number, if: -> { unemployment_compensation.present? }
validates :unemployment_compensation, numericality: { greater_than_or_equal_to: 1, message: ->(_object, _data) { I18n.t('errors.messages.greater_than_or_equal_to', count: 1)} }
validates_numericality_of :federal_income_tax_withheld, only_integer: true, message: :whole_number, if: -> { federal_income_tax_withheld.present? }
validates :federal_income_tax_withheld, numericality: { greater_than_or_equal_to: 0}, allow_blank: true
validates_numericality_of :state_income_tax_withheld, only_integer: true, message: :whole_number, if: -> { state_income_tax_withheld.present? }
validates :state_income_tax_withheld, numericality: { greater_than_or_equal_to: 0}, allow_blank: true
validate :state_specific_validation

def update_conditional_attributes
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Expand Up @@ -222,7 +222,9 @@ en:
inclusion: Please select a state from the list.
messages:
blank: Can't be blank.
greater_than_or_equal_to: must be greater than or equal to %{count}
invalid: is invalid
less_than_or_equal_to: must be less than or equal to %{count}
only_letters: Only letters are accepted
round_to_whole_number: round to the nearest whole number
whole_number: must be a whole number
Expand Down
2 changes: 2 additions & 0 deletions config/locales/es.yml
Expand Up @@ -223,7 +223,9 @@ es:
inclusion: Por favor, seleccione un estado de la lista.
messages:
blank: No puede estar en blanco.
greater_than_or_equal_to: debe ser mayor o igual a %{count}
invalid: es invalido
less_than_or_equal_to: debe ser menor o igual a %{count}
only_letters: Sólo se aceptan cartas
round_to_whole_number: redondea al número entero más próximo
whole_number: Debe ser un número entero
Expand Down
6 changes: 4 additions & 2 deletions spec/models/state_file1099_g_spec.rb
Expand Up @@ -85,13 +85,13 @@
end
it "validates federal_income_tax_withheld" do
state_file_1099.federal_income_tax_withheld = nil
expect(state_file_1099.save).to eq false
expect(state_file_1099.save).to eq true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good spec for verifying that we accept blanks. I would add at least one spec where we assert on the scenario for must be greater than or equal to 1 that you have updated unless there is already a spec that does that.

state_file_1099.federal_income_tax_withheld = '-1'
expect(state_file_1099.save).to eq false
end
it "validates state_income_tax_withheld" do
state_file_1099.state_income_tax_withheld = nil
expect(state_file_1099.save).to eq false
expect(state_file_1099.save).to eq true
state_file_1099.state_income_tax_withheld = '-1'
expect(state_file_1099.save).to eq false
end
Expand Down Expand Up @@ -141,6 +141,8 @@
it "validates unemployment_compensation" do
state_file_1099.valid?
expect(state_file_1099.errors[:unemployment_compensation]).to include "must be greater than or equal to 1"
expect(state_file_1099.errors[:federal_income_tax_withheld]).to be_empty
expect(state_file_1099.errors[:state_income_tax_withheld]).to be_empty
end
end
end
Expand Down