-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Spanish citizen id and docs #1147
Merged
Merged
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
57c09d3
update rake
PuZZleDucK c0ae74e
Merge branch 'master' of https://github.com/stympy/faker
PuZZleDucK e39e1d3
Merge branch 'master' of https://github.com/stympy/faker
PuZZleDucK 0870f25
add id_number docs
PuZZleDucK cdd1d1a
add tests for ssn
PuZZleDucK fbf1f7a
add failing tests for spanish IDs
PuZZleDucK 34e89c6
add spanish citizen ids for issue #872
PuZZleDucK efee22a
cleanup comments
PuZZleDucK 90c6f95
give spanish_citizen_number correct checksum
PuZZleDucK 09e414d
add validation checksum to Spanish NIE
PuZZleDucK a9abb2b
convert asserts into asert_equals
PuZZleDucK 7b4ef33
replacing string concatenation with interpolation
PuZZleDucK a8c54ad
Merge branch 'spanish-id-and-docs' of github.com:PuZZleDucK/faker int…
vbrazo eb48864
Minor changes
vbrazo b7481df
Fix merge conflicts
vbrazo a5f05a7
Run rubocop and fix lint
vbrazo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,15 @@ | ||
# Faker::IDNumber | ||
|
||
```ruby | ||
# Generate a valid US Social Security number | ||
Faker::IDNumber.valid #=> "552-56-3593" | ||
|
||
# Generate an invalid US Social Security number | ||
Faker::IDNumber.invalid #=> "311-72-0000" | ||
|
||
# Generate a Spanish citizen identifier (DNI) | ||
Faker::IDNumber.spanish_citizen_number | ||
|
||
# Generate a Spanish foreign born citizen identifier (NIE) | ||
Faker::IDNumber.spanish_foreign_citizen_number | ||
``` |
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,50 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb') | ||
|
||
class TestFakerIdNumber < Test::Unit::TestCase | ||
|
||
def setup | ||
@tester = Faker::IDNumber | ||
end | ||
|
||
def test_valid_ssn | ||
sample = @tester.valid | ||
assert sample.length == 11 | ||
assert_equal "-", sample[3] | ||
assert_equal "-", sample[6] | ||
assert sample[0..2].split().map{:to_i}.all?{:is_digit?} | ||
assert sample[4..5].split().map{:to_i}.all?{:is_digit?} | ||
assert sample[7..9].split().map{:to_i}.all?{:is_digit?} | ||
end | ||
|
||
def test_invalid_ssn | ||
sample = @tester.invalid | ||
assert sample.length == 11 | ||
assert_equal "-", sample[3] | ||
assert_equal "-", sample[6] | ||
assert sample[0..2].split().map{:to_i}.all?{:is_digit?} | ||
assert sample[4..5].split().map{:to_i}.all?{:is_digit?} | ||
assert sample[7..9].split().map{:to_i}.all?{:is_digit?} | ||
end | ||
|
||
def test_spanish_DNI | ||
sample = @tester.spanish_citizen_number | ||
assert_equal 10, sample.length | ||
assert sample[0..7].split().map{:to_i}.all?{:is_digit?} | ||
assert_equal sample[8], "-" | ||
mod = sample[0..7].to_i % 23 | ||
assert_equal "TRWAGMYFPDXBNJZSQVHLCKE"[mod], sample[9] | ||
end | ||
|
||
def test_spanish_NIE | ||
sample = @tester.spanish_foreign_citizen_number | ||
assert_equal 11, sample.length | ||
assert "XYZ".include?(sample[0]) | ||
assert_equal "-", sample[1] | ||
assert sample[2..8].split().map{:to_i}.all?{:is_digit?} | ||
assert_equal "-", sample[9] | ||
prefix = "XYZ".index(sample[0]).to_s | ||
mod = ("#{prefix}#{sample[2..8]}").to_i % 23 | ||
assert_equal "TRWAGMYFPDXBNJZSQVHLCKE"[mod], sample[10] | ||
end | ||
|
||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that you're repeating this line
checks = "TRWAGMYFPDXBNJZSQVHLCKE"
a few times. Could we write a constant instead?