Add new fields to signature

- Add :date_of_birth and :postal_code to Signature to allow send these
  fields to CustomCensusAPI

- Add new model presence validates: Only validate :date_of_birth and
  :postal_code presence when the application has configured Remote Census
  and their alias fields has values.
This commit is contained in:
taitus
2019-05-14 11:12:29 +02:00
committed by Javi Martín
parent 837c45599d
commit 5d68e1a43d
5 changed files with 56 additions and 0 deletions

View File

@@ -3,6 +3,8 @@ class Signature < ApplicationRecord
belongs_to :user
validates :document_number, presence: true
validates :date_of_birth, presence: true, if: -> { Setting.force_presence_date_of_birth? }
validates :postal_code, presence: true, if: -> { Setting.force_presence_postal_code? }
validates :signature_sheet, presence: true
scope :verified, -> { where(verified: true) }

View File

@@ -0,0 +1,5 @@
class AddDateOfBirthToSignatures < ActiveRecord::Migration
def change
add_column :signatures, :date_of_birth, :date
end
end

View File

@@ -0,0 +1,5 @@
class AddPostalCodeToSignatures < ActiveRecord::Migration
def change
add_column :signatures, :postal_code, :string
end
end

View File

@@ -1476,6 +1476,8 @@ ActiveRecord::Schema.define(version: 20190607160900) do
t.boolean "verified", default: false
t.datetime "created_at"
t.datetime "updated_at"
t.date "date_of_birth"
t.string "postal_code"
end
create_table "site_customization_content_blocks", force: :cascade do |t|

View File

@@ -28,6 +28,48 @@ describe Signature do
end
describe "custom validations" do
let(:signature) { build(:signature,
document_number: "12345678Z",
date_of_birth: "31/12/1980",
postal_code: "28013") }
before do
Setting["feature.remote_census"] = true
Setting["remote_census.request.date_of_birth"] = "some.value"
Setting["remote_census.request.postal_code"] = "some.value"
end
after do
Setting["feature.remote_census"] = nil
Setting["remote_census.request.date_of_birth"] = nil
Setting["remote_census.request.postal_code"] = nil
end
it "is valid" do
expect(signature).to be_valid
end
it "is not valid without a document number" do
signature.document_number = nil
expect(signature).not_to be_valid
end
it "is not valid without a date of birth" do
signature.date_of_birth = nil
expect(signature).not_to be_valid
end
it "is not valid without a postal_code" do
signature.postal_code = nil
expect(signature).not_to be_valid
end
end
describe "#clean_document_number" do
it "removes non alphanumeric characters" do
signature = create(:signature, document_number: "123-[;,9]")