-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add spanish citizen number validation
- Loading branch information
Showing
4 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
SimpleCov.start do | ||
root ENV.fetch("ENGINE_ROOT", nil) | ||
|
||
add_filter "/spec" | ||
end | ||
|
||
SimpleCov.command_name ENV.fetch("COMMAND_NAME", nil) || File.basename(Dir.pwd) | ||
|
||
SimpleCov.merge_timeout 1800 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe Decidim::AccountForm do | ||
subject do | ||
described_class.new( | ||
name: user.name, | ||
nickname: user.nickname, | ||
email: user.email, | ||
password: user.password, | ||
password_confirmation: user.password, | ||
tos_agreement: "1", | ||
center_id: user.center.id, | ||
scope_id: user.scope.id, | ||
document_id: document_id | ||
).with_context( | ||
current_organization: organization, | ||
current_user: user | ||
) | ||
end | ||
|
||
let(:organization) { create :organization, extra_user_fields: { "enabled" => true, "document_id" => { "enabled" => true } } } | ||
let(:user) { create :user, organization: organization } | ||
let!(:center_user) { create :center_user, user: user } | ||
let!(:scope_user) { create :scope_user, user: user } | ||
|
||
context "with valid citizen number" do | ||
let(:document_id) { Faker::IDNumber.spanish_citizen_number } | ||
|
||
it { is_expected.to be_valid } | ||
end | ||
|
||
context "with invalid citizen number" do | ||
let(:document_id) { "12345678-A" } | ||
|
||
it { is_expected.not_to be_valid } | ||
end | ||
|
||
context "with valid foreign citizen number" do | ||
let(:document_id) { Faker::IDNumber.spanish_foreign_citizen_number } | ||
|
||
it { is_expected.to be_valid } | ||
end | ||
|
||
context "with invalid foreign citizen number" do | ||
let(:document_id) { "Z-1234567-A" } | ||
|
||
it { is_expected.not_to be_valid } | ||
end | ||
|
||
context "with invalid document id" do | ||
let(:document_id) { "foo" } | ||
|
||
it { is_expected.not_to be_valid } | ||
end | ||
|
||
context "with document id disabled" do | ||
let(:organization) { create :organization, extra_user_fields: { "enabled" => false } } | ||
|
||
context "with invalid citizen number" do | ||
let(:document_id) { "12345678-A" } | ||
|
||
it { is_expected.to be_valid } | ||
end | ||
|
||
context "with invalid foreign citizen number" do | ||
let(:document_id) { "Z-1234567-A" } | ||
|
||
it { is_expected.to be_valid } | ||
end | ||
|
||
context "with invalid document id" do | ||
let(:document_id) { "foo" } | ||
|
||
it { is_expected.to be_valid } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters