Skip to content

Commit

Permalink
Fix failing specs
Browse files Browse the repository at this point in the history
  • Loading branch information
hiboabd committed Jan 13, 2025
1 parent a5ad9e7 commit 63b9599
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
17 changes: 5 additions & 12 deletions app/forms/concerns/steps/payment_fieldset_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@ module PaymentFieldsetValidation
extend ActiveSupport::Concern

def validate_frequency
if frequency.blank?
errors.add(:frequency, :blank, payment_type: payment_type_label)
elsif frequencies.exclude?(frequency)
errors.add(:frequency, :inclusion, payment_type: payment_type_label&.capitalize)
end
errors.add(:frequency, :blank, payment_type: payment_type_label) if frequency.blank?
errors.add(:frequency, :inclusion, payment_type: payment_type_label&.capitalize) if frequencies.exclude?(frequency)
end

def validate_amount
if amount.blank?
errors.add(:amount, :blank, payment_type: payment_type_label)
elsif Type::Pence.new.serialize(amount).nil?
errors.add(:amount, :not_a_number, payment_type: payment_type_label)
elsif amount.to_i <= 0
errors.add(:amount, :greater_than, payment_type: payment_type_label)
end
errors.add(:amount, :blank, payment_type: payment_type_label) if amount.blank?
errors.add(:amount, :not_a_number, payment_type: payment_type_label) if Type::Pence.new.serialize(amount).nil?
errors.add(:amount, :greater_than, payment_type: payment_type_label) if amount.to_i <= 0
end
end
end
2 changes: 1 addition & 1 deletion app/validators/income_payments_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def add_errors(income_payment)

# We define the attribute getter as it doesn't really exist
record.define_singleton_method(attr_name) do
outgoings_payment.public_send(error.attribute)
income_payment.public_send(error.attribute)
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/forms/steps/income/income_benefits_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@
end

it 'has error messages' do
expect(subject.errors.count).to be(4)
expect(subject.errors.count).to be(5)
expect(subject.errors.of_kind?('child-amount', :blank)).to be(true)
expect(subject.errors.of_kind?('child-amount', :not_a_number)).to be(true)
expect(subject.errors.of_kind?('child-amount', :greater_than)).to be(true)
expect(subject.errors.of_kind?('child-frequency', :inclusion)).to be(true)
expect(subject.errors.of_kind?('jsa-details', :invalid)).to be(true)

Expand Down
3 changes: 2 additions & 1 deletion spec/forms/steps/income/income_payments_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@
end

it 'has error messages' do
expect(subject.errors.count).to be(4)
expect(subject.errors.count).to be(5)
expect(subject.errors.of_kind?('maintenance-amount', :blank)).to be(true)
expect(subject.errors.of_kind?('maintenance-amount', :not_a_number)).to be(true)
expect(subject.errors.of_kind?('maintenance-amount', :greater_than)).to be(true)
expect(subject.errors.of_kind?('maintenance-frequency', :inclusion)).to be(true)
expect(subject.errors.of_kind?('student-loan-grant-details', :invalid)).to be(true)

Expand Down
3 changes: 2 additions & 1 deletion spec/forms/steps/income/partner/income_payments_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@
end

it 'has error messages' do
expect(subject.errors.count).to be(4)
expect(subject.errors.count).to be(5)
expect(subject.errors.of_kind?('maintenance-amount', :blank)).to be(true)
expect(subject.errors.of_kind?('maintenance-amount', :not_a_number)).to be(true)
expect(subject.errors.of_kind?('maintenance-amount', :greater_than)).to be(true)
expect(subject.errors.of_kind?('maintenance-frequency', :inclusion)).to be(true)
expect(subject.errors.of_kind?('student-loan-grant-details', :invalid)).to be(true)

Expand Down
4 changes: 3 additions & 1 deletion spec/forms/steps/outgoings/outgoings_payments_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@
end

it 'has error messages' do
expect(subject.errors.count).to be(2)
expect(subject.errors.count).to be(4)
expect(subject.errors.of_kind?('childcare-amount', :blank)).to be(true)
expect(subject.errors.of_kind?('childcare-amount', :not_a_number)).to be(true)
expect(subject.errors.of_kind?('childcare-amount', :greater_than)).to be(true)
expect(subject.errors.of_kind?('childcare-frequency', :inclusion)).to be(true)

# Error attributes should respond
Expand Down

0 comments on commit 63b9599

Please sign in to comment.