Validate inclusion of document type in allowed document types
* Add custom message for inclusion validation to include the allowed values. * Force user to choose document_type from select lik the one shown at verification form. * Convert stored document_type to a human readable text
This commit is contained in:
@@ -3,6 +3,7 @@ class LocalCensusRecord < ApplicationRecord
|
|||||||
|
|
||||||
validates :document_number, presence: true
|
validates :document_number, presence: true
|
||||||
validates :document_type, presence: true
|
validates :document_type, presence: true
|
||||||
|
validates :document_type, inclusion: { in: ["1", "2", "3"], allow_blank: true }
|
||||||
validates :date_of_birth, presence: true
|
validates :date_of_birth, presence: true
|
||||||
validates :postal_code, presence: true
|
validates :postal_code, presence: true
|
||||||
validates :document_number, uniqueness: { scope: :document_type }
|
validates :document_number, uniqueness: { scope: :document_type }
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="small-12">
|
<div class="small-12">
|
||||||
<%= f.text_field :document_type %>
|
<%= f.select :document_type, document_types, prompt: "" %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<tr id="<%= dom_id(local_census_record) %>" class="local_census_record">
|
<tr id="<%= dom_id(local_census_record) %>" class="local_census_record">
|
||||||
<td>
|
<td>
|
||||||
<%= local_census_record.document_type %>
|
<%= humanize_document_type(local_census_record.document_type) %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= local_census_record.document_number %>
|
<%= local_census_record.document_number %>
|
||||||
|
|||||||
@@ -514,6 +514,10 @@ en:
|
|||||||
invalid_date_range: must be on or after the draft start date
|
invalid_date_range: must be on or after the draft start date
|
||||||
allegations_end_date:
|
allegations_end_date:
|
||||||
invalid_date_range: must be on or after the comments start date
|
invalid_date_range: must be on or after the comments start date
|
||||||
|
local_census_record:
|
||||||
|
attributes:
|
||||||
|
document_type:
|
||||||
|
inclusion: is not included in the list, allowed values are 1 for DNI, 2 for passport and 3 for residence card.
|
||||||
proposal:
|
proposal:
|
||||||
attributes:
|
attributes:
|
||||||
tag_list:
|
tag_list:
|
||||||
|
|||||||
@@ -516,6 +516,10 @@ es:
|
|||||||
invalid_date_range: tiene que ser igual o posterior a la fecha de inicio del borrador
|
invalid_date_range: tiene que ser igual o posterior a la fecha de inicio del borrador
|
||||||
allegations_end_date:
|
allegations_end_date:
|
||||||
invalid_date_range: tiene que ser igual o posterior a la fecha de inicio de los comentarios
|
invalid_date_range: tiene que ser igual o posterior a la fecha de inicio de los comentarios
|
||||||
|
local_census_record:
|
||||||
|
attributes:
|
||||||
|
document_type:
|
||||||
|
inclusion: no está incluido en la lista, los valores permitidos son 1 para DNI, 2 para pasaporte y 3 para tarjeta de residencia.
|
||||||
proposal:
|
proposal:
|
||||||
attributes:
|
attributes:
|
||||||
tag_list:
|
tag_list:
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ describe "Imports" do
|
|||||||
click_button "Save"
|
click_button "Save"
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(page).to have_content "Errored rows (4)"
|
expect(page).to have_content "Errored rows (5)"
|
||||||
expect(page).to have_selector("#invalid-local-census-records tbody tr", count: 4)
|
expect(page).to have_selector("#invalid-local-census-records tbody tr", count: 5)
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Should show error messages inside cells at errored group" do
|
scenario "Should show error messages inside cells at errored group" do
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ describe "Admin local census records" do
|
|||||||
scenario "Should show existing local census records" do
|
scenario "Should show existing local census records" do
|
||||||
visit admin_local_census_records_path
|
visit admin_local_census_records_path
|
||||||
|
|
||||||
expect(page).to have_content(local_census_record.document_type)
|
expect(page).to have_content("DNI")
|
||||||
expect(page).to have_content(local_census_record.document_number)
|
expect(page).to have_content(local_census_record.document_number)
|
||||||
expect(page).to have_content(local_census_record.date_of_birth)
|
expect(page).to have_content(local_census_record.date_of_birth)
|
||||||
expect(page).to have_content(local_census_record.postal_code)
|
expect(page).to have_content(local_census_record.postal_code)
|
||||||
@@ -85,7 +85,7 @@ describe "Admin local census records" do
|
|||||||
scenario "Should show successful notice after create valid record" do
|
scenario "Should show successful notice after create valid record" do
|
||||||
visit new_admin_local_census_record_path
|
visit new_admin_local_census_record_path
|
||||||
|
|
||||||
fill_in :local_census_record_document_type, with: "DNI"
|
select "DNI", from: :local_census_record_document_type
|
||||||
fill_in :local_census_record_document_number, with: "#DOCUMENT"
|
fill_in :local_census_record_document_number, with: "#DOCUMENT"
|
||||||
select "1982", from: :local_census_record_date_of_birth_1i
|
select "1982", from: :local_census_record_date_of_birth_1i
|
||||||
select "July", from: :local_census_record_date_of_birth_2i
|
select "July", from: :local_census_record_date_of_birth_2i
|
||||||
@@ -117,7 +117,7 @@ describe "Admin local census records" do
|
|||||||
scenario "Should show successful notice after valid update" do
|
scenario "Should show successful notice after valid update" do
|
||||||
visit edit_admin_local_census_record_path(local_census_record)
|
visit edit_admin_local_census_record_path(local_census_record)
|
||||||
|
|
||||||
fill_in :local_census_record_document_type, with: "NIE"
|
select "Passport", from: :local_census_record_document_type
|
||||||
fill_in :local_census_record_document_number, with: "#NIE_NUMBER"
|
fill_in :local_census_record_document_number, with: "#NIE_NUMBER"
|
||||||
select "1982", from: :local_census_record_date_of_birth_1i
|
select "1982", from: :local_census_record_date_of_birth_1i
|
||||||
select "August", from: :local_census_record_date_of_birth_2i
|
select "August", from: :local_census_record_date_of_birth_2i
|
||||||
@@ -126,7 +126,7 @@ describe "Admin local census records" do
|
|||||||
click_on "Save"
|
click_on "Save"
|
||||||
|
|
||||||
expect(page).to have_content "Local census record updated successfully!"
|
expect(page).to have_content "Local census record updated successfully!"
|
||||||
expect(page).to have_content "NIE"
|
expect(page).to have_content "Passport"
|
||||||
expect(page).to have_content "#NIE_NUMBER"
|
expect(page).to have_content "#NIE_NUMBER"
|
||||||
expect(page).to have_content "1982-08-08"
|
expect(page).to have_content "1982-08-08"
|
||||||
expect(page).to have_content "07007"
|
expect(page).to have_content "07007"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"document_type","document_number","date_of_birth","postal_code"
|
"document_type","document_number","date_of_birth","postal_code"
|
||||||
,"44556678T","07/08/1984",7008
|
,"44556678T","07/08/1984",7008
|
||||||
"DNI",,"07/08/1985",7009
|
"1",,"07/08/1985",7009
|
||||||
"Passport","22556678T",,7010
|
"2","22556678T",,7010
|
||||||
"NIE","X11556678","07/08/1987",
|
"3","X11556678","07/08/1987",
|
||||||
|
"DNI","Z11556678","07/08/1987",7011
|
||||||
|
|||||||
|
@@ -1,5 +1,5 @@
|
|||||||
"document_type","document_number","date_of_birth","postal_code"
|
"document_type","document_number","date_of_birth","postal_code"
|
||||||
"DNI","44556678T","07/08/1984",7008
|
"1","44556678T","07/08/1984",7008
|
||||||
"DNI","33556678T","07/08/1985",7008
|
"1","33556678T","07/08/1985",7008
|
||||||
"DNI","22556678T","07/08/1986",7008
|
"1","22556678T","07/08/1986",7008
|
||||||
"NIE","X11556678","07/08/1987",7008
|
"2","X11556678","07/08/1987",7008
|
||||||
|
|||||||
|
@@ -20,6 +20,12 @@ describe LocalCensusRecord do
|
|||||||
expect(local_census_record).not_to be_valid
|
expect(local_census_record).not_to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "is not valid when value is not included in allowed document types" do
|
||||||
|
local_census_record.document_type = "NIE"
|
||||||
|
|
||||||
|
expect(local_census_record).not_to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it "is not valid without date_of_birth" do
|
it "is not valid without date_of_birth" do
|
||||||
local_census_record.date_of_birth = nil
|
local_census_record.date_of_birth = nil
|
||||||
|
|
||||||
@@ -33,9 +39,9 @@ describe LocalCensusRecord do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "is not valid when a record already exists with same document_number and document_type" do
|
it "is not valid when a record already exists with same document_number and document_type" do
|
||||||
create(:local_census_record, document_number: "#DOC_NUMBER", document_type: "#DOC_TYPE")
|
create(:local_census_record, document_number: "#DOC_NUMBER", document_type: "1")
|
||||||
local_census_record = build(:local_census_record, document_number: "#DOC_NUMBER",
|
local_census_record = build(:local_census_record, document_number: "#DOC_NUMBER",
|
||||||
document_type: "#DOC_TYPE")
|
document_type: "1")
|
||||||
|
|
||||||
expect(local_census_record).not_to be_valid
|
expect(local_census_record).not_to be_valid
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ describe LocalCensusRecords::Import do
|
|||||||
local_census_record = LocalCensusRecord.find_by(document_number: "X11556678")
|
local_census_record = LocalCensusRecord.find_by(document_number: "X11556678")
|
||||||
|
|
||||||
expect(local_census_record).not_to be_nil
|
expect(local_census_record).not_to be_nil
|
||||||
expect(local_census_record.document_type).to eq("NIE")
|
expect(local_census_record.document_type).to eq("2")
|
||||||
expect(local_census_record.document_number).to eq("X11556678")
|
expect(local_census_record.document_number).to eq("X11556678")
|
||||||
expect(local_census_record.date_of_birth).to eq(Date.parse("07/08/1987"))
|
expect(local_census_record.date_of_birth).to eq(Date.parse("07/08/1987"))
|
||||||
expect(local_census_record.postal_code).to eq("7008")
|
expect(local_census_record.postal_code).to eq("7008")
|
||||||
@@ -69,11 +69,11 @@ describe LocalCensusRecords::Import do
|
|||||||
|
|
||||||
import.save!
|
import.save!
|
||||||
|
|
||||||
invalid_records_document_types = [nil, "DNI", "Passport", "NIE"]
|
invalid_records_document_types = [nil, "1", "2", "3", "DNI"]
|
||||||
invalid_records_document_numbers = ["44556678T", nil, "22556678T", "X11556678"]
|
invalid_records_document_numbers = ["44556678T", nil, "22556678T", "X11556678", "Z11556678"]
|
||||||
invalid_records_date_of_births = [Date.parse("07/08/1984"), Date.parse("07/08/1985"), nil,
|
invalid_records_date_of_births = [Date.parse("07/08/1984"), Date.parse("07/08/1985"), nil,
|
||||||
Date.parse("07/08/1987")]
|
Date.parse("07/08/1987"), Date.parse("07/08/1987")]
|
||||||
invalid_records_postal_codes = ["7008", "7009", "7010", nil]
|
invalid_records_postal_codes = ["7008", "7009", "7010", nil, "7011"]
|
||||||
expect(import.invalid_records.map(&:document_type))
|
expect(import.invalid_records.map(&:document_type))
|
||||||
.to eq(invalid_records_document_types)
|
.to eq(invalid_records_document_types)
|
||||||
expect(import.invalid_records.map(&:document_number))
|
expect(import.invalid_records.map(&:document_number))
|
||||||
|
|||||||
Reference in New Issue
Block a user