Browse Source

Push fixes #8

pull/264/head
Stéphane Meny 3 years ago
parent
commit
e69e4ae488
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 10
      spec/models/case_log_spec.rb
  2. 35
      spec/models/validations/local_authority_validations_spec.rb

10
spec/models/case_log_spec.rb

@ -33,6 +33,16 @@ RSpec.describe CaseLog do
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "raises an error when previous_postcode is present and invalid" do
expect {
described_class.create!(
previous_postcode: "invalid_postcode",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation,
)
}.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end
it "validates age is a number" do
expect {
described_class.create!(

35
spec/models/validations/local_authority_validations_spec.rb

@ -1,54 +1,33 @@
require "rails_helper"
require_relative "../../request_helper"
RSpec.describe CaseLog do
let(:owning_organisation) { FactoryBot.create(:organisation) }
let(:managing_organisation) { owning_organisation }
before do
RequestHelper.stub_http_requests
end
describe "#new" do
it "raises an error when previous_postcode is present and invalid" do
expect {
described_class.create!(
previous_postcode: "invalid_postcode",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation,
)
}.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end
end
end
RSpec.describe Validations::LocalAuthorityValidations do
let(:subject) { subject_class.new }
let(:subject_class) { Class.new { include Validations::LocalAuthorityValidations } }
subject(:local_auth_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::LocalAuthorityValidations } }
let(:record) { FactoryBot.create(:case_log) }
describe "#validate_previous_accommodation_postcode" do
it "does not add an error if the record previous_postcode is missing" do
record.previous_postcode = nil
subject.validate_previous_accommodation_postcode(record)
local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).to be_empty
end
it "does not add an error if the record previous_postcode is valid (uppercase space)" do
record.previous_postcode = "M1 1AE"
subject.validate_previous_accommodation_postcode(record)
local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).to be_empty
end
it "does not add an error if the record previous_postcode is valid (lowercase no space)" do
record.previous_postcode = "m11ae"
subject.validate_previous_accommodation_postcode(record)
local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).to be_empty
end
it "does add an error when the postcode is invalid" do
record.previous_postcode = "invalid"
subject.validate_previous_accommodation_postcode(record)
local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).not_to be_empty
expect(record.errors["previous_postcode"]).to include(match I18n.t("validations.postcode"))
end

Loading…
Cancel
Save