diff --git a/spec/features/verification/residence_spec.rb b/spec/features/verification/residence_spec.rb index 07fbdcd35..7bdd44425 100644 --- a/spec/features/verification/residence_spec.rb +++ b/spec/features/verification/residence_spec.rb @@ -32,6 +32,26 @@ feature 'Residence' do expect(page).to have_content /\d errors? prevented your residence verification/ end + scenario 'Error on postal code not in Madrid census' do + user = create(:user) + login_as(user) + + visit account_path + click_link 'Verify my account' + + fill_in 'residence_document_number', with: "12345678Z" + select 'Spanish ID', from: 'residence_document_type' + select '1997', from: 'residence_date_of_birth_1i' + select 'January', from: 'residence_date_of_birth_2i' + select '1', from: 'residence_date_of_birth_3i' + fill_in 'residence_postal_code', with: '12345' + check 'residence_terms_of_service' + + click_button 'Verify residence' + + expect(page).to have_content 'Please, to verify your account you need to be in the census of the Madrid town.' + end + scenario 'Error on Madrid census' do user = create(:user) login_as(user) diff --git a/spec/models/residence_spec.rb b/spec/models/residence_spec.rb index 9ccc3c2f3..619e6b7d5 100644 --- a/spec/models/residence_spec.rb +++ b/spec/models/residence_spec.rb @@ -29,6 +29,25 @@ describe Verification::Residence do expect(residence.errors[:date_of_birth]).to include("You need yo be at least 16 years old") end + describe "postal code" do + it "should be valid with postal codes starting with 280" do + residence.postal_code = "28012" + expect(residence.errors[:postal_code].size).to eq(0) + + residence.postal_code = "28023" + expect(residence.errors[:postal_code].size).to eq(0) + end + + it "should not be valid with postal codes not starting with 280" do + residence.postal_code = "12345" + expect(residence.errors[:postal_code].size).to eq(1) + + residence.postal_code = "13280" + expect(residence.errors[:postal_code].size).to eq(1) + expect(residence.errors[:postal_code]).to include("Please, to verify your account you need to be in the census of the Madrid town.") + end + end + it "should validate uniquness of document_number" do user = create(:user) residence.user = user