Browse Source

Implement other tenancy type validation

pull/68/head
Kat 4 years ago
parent
commit
dcb16bd771
  1. 4
      app/models/case_log.rb
  2. 27
      spec/models/case_log_spec.rb

4
app/models/case_log.rb

@ -101,6 +101,10 @@ class CaseLogValidator < ActiveModel::Validator
conditions.each { |condition| condition[:condition] ? (record.errors.add :fixed_term_tenancy, condition[:error]) : nil } conditions.each { |condition| condition[:condition] ? (record.errors.add :fixed_term_tenancy, condition[:error]) : nil }
end end
def validate_other_tenancy_type(record)
validate_other_field(record, "tenancy_type", "other_tenancy_type")
end
def validate(record) def validate(record)
# If we've come from the form UI we only want to validate the specific fields # If we've come from the form UI we only want to validate the specific fields
# that have just been submitted. If we're submitting a log via API or Bulk Upload # that have just been submitted. If we're submitting a log via API or Bulk Upload

27
spec/models/case_log_spec.rb

@ -201,7 +201,32 @@ RSpec.describe Form, type: :model do
expect { expect {
CaseLog.create!(armed_forces: "Yes - a regular", CaseLog.create!(armed_forces: "Yes - a regular",
armed_forces_active: "Yes", armed_forces_active: "Yes",
armed_forces_injured: "Yes") armed_forces_injured: "Yes")}
end
end
context "other tenancy type validation" do
it "must be provided if tenancy type was given as other" do
expect {
CaseLog.create!(tenancy_type: "Other",
other_tenancy_type: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy_type: "Other",
other_tenancy_type: "type")
}.not_to raise_error
end
it "must not be provided if tenancy type is not other" do
expect {
CaseLog.create!(tenancy_type: "Fixed",
other_tenancy_type: "the other reason provided")
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy_type: "Fixed",
other_tenancy_type: nil)
}.not_to raise_error }.not_to raise_error
end end
end end

Loading…
Cancel
Save