Browse Source

add or alter step on numeric questions in sales, amend one test given step changes

validations-copy
Arthur Campbell 2 years ago
parent
commit
af739dd5b8
  1. 1
      app/models/form/sales/questions/age1.rb
  2. 1
      app/models/form/sales/questions/age2.rb
  3. 3
      app/models/form/sales/questions/deposit_amount.rb
  4. 1
      app/models/form/sales/questions/deposit_discount.rb
  5. 1
      app/models/form/sales/questions/discount.rb
  6. 1
      app/models/form/sales/questions/equity.rb
  7. 1
      app/models/form/sales/questions/grant.rb
  8. 5
      app/models/form/sales/questions/leasehold_charges.rb
  9. 1
      app/models/form/sales/questions/monthly_rent.rb
  10. 1
      app/models/form/sales/questions/mortgage_amount.rb
  11. 1
      app/models/form/sales/questions/number_of_others_in_property.rb
  12. 1
      app/models/form/sales/questions/previous_bedrooms.rb
  13. 1
      app/models/form/sales/questions/property_number_of_bedrooms.rb
  14. 1
      app/models/form/sales/questions/purchase_price.rb
  15. 2
      app/models/form/sales/questions/savings.rb
  16. 1
      app/models/form/sales/questions/staircase_bought.rb
  17. 1
      app/models/form/sales/questions/staircase_owned.rb
  18. 1
      app/models/form/sales/questions/value.rb
  19. 2
      app/models/validations/shared_validations.rb
  20. 6
      spec/models/validations/shared_validations_spec.rb

1
app/models/form/sales/questions/age1.rb

@ -19,6 +19,7 @@ class Form::Sales::Questions::Age1 < ::Form::Question
@check_answers_card_number = 1 @check_answers_card_number = 1
@min = 16 @min = 16
@max = 110 @max = 110
@step = 1
@question_number = 20 @question_number = 20
end end
end end

1
app/models/form/sales/questions/age2.rb

@ -13,6 +13,7 @@ class Form::Sales::Questions::Age2 < ::Form::Question
@check_answers_card_number = 2 @check_answers_card_number = 2
@max = 110 @max = 110
@min = 0 @min = 0
@step = 1
@question_number = 28 @question_number = 28
end end
end end

3
app/models/form/sales/questions/deposit_amount.rb

@ -6,8 +6,9 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question
@header = "How much cash deposit was paid on the property?" @header = "How much cash deposit was paid on the property?"
@type = "numeric" @type = "numeric"
@min = 0 @min = 0
@width = 5
@max = 999_999 @max = 999_999
@step = 1
@width = 5
@prefix = "£" @prefix = "£"
@hint_text = "Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage" @hint_text = "Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage"
@derived = true @derived = true

1
app/models/form/sales/questions/deposit_discount.rb

@ -7,6 +7,7 @@ class Form::Sales::Questions::DepositDiscount < ::Form::Question
@type = "numeric" @type = "numeric"
@min = 0 @min = 0
@max = 999_999 @max = 999_999
@step = 1
@width = 5 @width = 5
@prefix = "£" @prefix = "£"
@hint_text = "Enter the total cash discount given on the property being purchased through the Social HomeBuy scheme" @hint_text = "Enter the total cash discount given on the property being purchased through the Social HomeBuy scheme"

1
app/models/form/sales/questions/discount.rb

@ -7,6 +7,7 @@ class Form::Sales::Questions::Discount < ::Form::Question
@type = "numeric" @type = "numeric"
@min = 0 @min = 0
@max = 100 @max = 100
@step = 1
@width = 5 @width = 5
@suffix = "%" @suffix = "%"
@hint_text = "For Right to Buy (RTB), Preserved Right to Buy (PRTB), and Voluntary Right to Buy (VRTB)</br></br> @hint_text = "For Right to Buy (RTB), Preserved Right to Buy (PRTB), and Voluntary Right to Buy (VRTB)</br></br>

1
app/models/form/sales/questions/equity.rb

@ -7,6 +7,7 @@ class Form::Sales::Questions::Equity < ::Form::Question
@type = "numeric" @type = "numeric"
@min = 0 @min = 0
@max = 100 @max = 100
@step = 1
@width = 5 @width = 5
@suffix = "%" @suffix = "%"
@hint_text = "Enter the amount of initial equity held by the purchaser (for example, 25% or 50%)" @hint_text = "Enter the amount of initial equity held by the purchaser (for example, 25% or 50%)"

1
app/models/form/sales/questions/grant.rb

@ -7,6 +7,7 @@ class Form::Sales::Questions::Grant < ::Form::Question
@type = "numeric" @type = "numeric"
@min = 0 @min = 0
@max = 999_999 @max = 999_999
@step = 1
@width = 5 @width = 5
@prefix = "£" @prefix = "£"
@hint_text = "For all schemes except Right to Buy (RTB), Preserved Right to Buy (PRTB), Voluntary Right to Buy (VRTB) and Rent to Buy" @hint_text = "For all schemes except Right to Buy (RTB), Preserved Right to Buy (PRTB), Voluntary Right to Buy (VRTB) and Rent to Buy"

5
app/models/form/sales/questions/leasehold_charges.rb

@ -5,7 +5,12 @@ class Form::Sales::Questions::LeaseholdCharges < ::Form::Question
@check_answer_label = "Monthly leasehold charges" @check_answer_label = "Monthly leasehold charges"
@header = "Enter the total monthly charge" @header = "Enter the total monthly charge"
@type = "numeric" @type = "numeric"
<<<<<<< HEAD
@min = 1 @min = 1
=======
@min = 0
@step = 0.01
>>>>>>> a59c771e (add or alter step on numeric questions in sales, amend one test given step changes)
@width = 5 @width = 5
@prefix = "£" @prefix = "£"
@ownershipsch = ownershipsch @ownershipsch = ownershipsch

1
app/models/form/sales/questions/monthly_rent.rb

@ -6,6 +6,7 @@ class Form::Sales::Questions::MonthlyRent < ::Form::Question
@header = "What is the basic monthly rent?" @header = "What is the basic monthly rent?"
@type = "numeric" @type = "numeric"
@min = 0 @min = 0
@step = 0.01
@width = 5 @width = 5
@prefix = "£" @prefix = "£"
@hint_text = "Amount paid before any charges" @hint_text = "Amount paid before any charges"

1
app/models/form/sales/questions/mortgage_amount.rb

@ -6,6 +6,7 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question
@header = "What is the mortgage amount?" @header = "What is the mortgage amount?"
@type = "numeric" @type = "numeric"
@min = 1 @min = 1
@step = 1
@width = 5 @width = 5
@prefix = "£" @prefix = "£"
@hint_text = "Enter the amount of mortgage agreed with the mortgage lender. Exclude any deposits or cash payments. Numeric in pounds. Rounded to the nearest pound." @hint_text = "Enter the amount of mortgage agreed with the mortgage lender. Exclude any deposits or cash payments. Numeric in pounds. Rounded to the nearest pound."

1
app/models/form/sales/questions/number_of_others_in_property.rb

@ -9,6 +9,7 @@ class Form::Sales::Questions::NumberOfOthersInProperty < ::Form::Question
@width = 2 @width = 2
@min = 0 @min = 0
@max = 15 @max = 15
@step = 1
@question_number = 35 @question_number = 35
end end

1
app/models/form/sales/questions/previous_bedrooms.rb

@ -8,6 +8,7 @@ class Form::Sales::Questions::PreviousBedrooms < ::Form::Question
@width = 5 @width = 5
@min = 1 @min = 1
@max = 6 @max = 6
@step = 1
@hint_text = "For bedsits enter 1" @hint_text = "For bedsits enter 1"
@question_number = 85 @question_number = 85
end end

1
app/models/form/sales/questions/property_number_of_bedrooms.rb

@ -9,6 +9,7 @@ class Form::Sales::Questions::PropertyNumberOfBedrooms < ::Form::Question
@width = 10 @width = 10
@min = 1 @min = 1
@max = 9 @max = 9
@step = 1
@question_number = 11 @question_number = 11
end end
end end

1
app/models/form/sales/questions/purchase_price.rb

@ -6,6 +6,7 @@ class Form::Sales::Questions::PurchasePrice < ::Form::Question
@header = "What is the full purchase price?" @header = "What is the full purchase price?"
@type = "numeric" @type = "numeric"
@min = 0 @min = 0
@step = 0.01
@width = 5 @width = 5
@prefix = "£" @prefix = "£"
@hint_text = "For all schemes, including Right to Acquire (RTA), Right to Buy (RTB), Voluntary Right to Buy (VRTB) or Preserved Right to Buy (PRTB) sales, enter the full price of the property without any discount" @hint_text = "For all schemes, including Right to Acquire (RTA), Right to Buy (RTB), Voluntary Right to Buy (VRTB) or Preserved Right to Buy (PRTB) sales, enter the full price of the property without any discount"

2
app/models/form/sales/questions/savings.rb

@ -7,7 +7,7 @@ class Form::Sales::Questions::Savings < ::Form::Question
@type = "numeric" @type = "numeric"
@width = 5 @width = 5
@prefix = "£" @prefix = "£"
@step = 1 @step = 10
@min = 0 @min = 0
@question_number = 72 @question_number = 72
end end

1
app/models/form/sales/questions/staircase_bought.rb

@ -8,6 +8,7 @@ class Form::Sales::Questions::StaircaseBought < ::Form::Question
@width = 5 @width = 5
@min = 0 @min = 0
@max = 100 @max = 100
@step = 1
@suffix = "%" @suffix = "%"
@question_number = 77 @question_number = 77
end end

1
app/models/form/sales/questions/staircase_owned.rb

@ -8,6 +8,7 @@ class Form::Sales::Questions::StaircaseOwned < ::Form::Question
@width = 5 @width = 5
@min = 0 @min = 0
@max = 100 @max = 100
@step = 1
@suffix = "%" @suffix = "%"
@question_number = 78 @question_number = 78
end end

1
app/models/form/sales/questions/value.rb

@ -6,6 +6,7 @@ class Form::Sales::Questions::Value < ::Form::Question
@header = "What was the full purchase price?" @header = "What was the full purchase price?"
@type = "numeric" @type = "numeric"
@min = 0 @min = 0
@step = 1
@width = 5 @width = 5
@prefix = "£" @prefix = "£"
@hint_text = "Enter the full purchase price of the property before any discounts are applied. For shared ownership, enter the full purchase price paid for 100% equity (this is equal to the value of the share owned by the PRP plus the value bought by the purchaser)" @hint_text = "Enter the full purchase price of the property before any discounts are applied. For shared ownership, enter the full purchase price paid for 100% equity (this is equal to the value of the share owned by the PRP plus the value bought by the purchaser)"

2
app/models/validations/shared_validations.rb

@ -60,7 +60,7 @@ module Validations::SharedValidations
if user_input.is_a?(String) && user_input.include?("e") if user_input.is_a?(String) && user_input.include?("e")
record.errors.add question.id.to_sym, I18n.t("validations.numeric.normal_format") record.errors.add question.id.to_sym, I18n.t("validations.numeric.normal_format")
end end
end end
end end
def validate_property_postcode(record) def validate_property_postcode(record)

6
spec/models/validations/shared_validations_spec.rb

@ -145,13 +145,13 @@ RSpec.describe Validations::SharedValidations do
context "when validating a question with a step of 0.01" do context "when validating a question with a step of 0.01" do
it "adds an error if input has more than 2 decimal places" do it "adds an error if input has more than 2 decimal places" do
sales_log.deposit = 630.7418 sales_log.mscharge = 30.7418
shared_validator.validate_numeric_step(sales_log) shared_validator.validate_numeric_step(sales_log)
expect(sales_log.errors[:deposit]).to include I18n.t("validations.numeric.nearest_penny", field: "Cash deposit") expect(sales_log.errors[:mscharge]).to include I18n.t("validations.numeric.nearest_penny", field: "Monthly leasehold charges")
end end
it "does not add an error if input has 2 or fewer decimal places" do it "does not add an error if input has 2 or fewer decimal places" do
sales_log.deposit = 630.74 sales_log.mscharge = 30.74
shared_validator.validate_numeric_step(sales_log) shared_validator.validate_numeric_step(sales_log)
expect(sales_log.errors).to be_empty expect(sales_log.errors).to be_empty
end end

Loading…
Cancel
Save