Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added AddressCA for Canada-specific info
info includes Canadian provinces, province abbreviations and postal codes
- Loading branch information
1 parent
325d188
commit 4ac5bbe
Showing
3 changed files
with
46 additions
and
0 deletions.
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,30 @@ | ||
module Faker | ||
module AddressCA | ||
include Faker::Address | ||
extend ModuleUtils | ||
extend self | ||
|
||
def postal_code | ||
Faker.bothify(POSTAL_CODE_FORMATS.rand).upcase | ||
end | ||
|
||
def province | ||
PROVINCE.rand | ||
end | ||
|
||
def province_abbr | ||
PROVINCE_ABBRS.rand | ||
end | ||
|
||
POSTAL_CODE_FORMATS = k ['?#? #?#'] | ||
|
||
PROVINCE = k [ | ||
'Newfoundland and Labrador', 'Nova Scotia', 'Prince Edward Island', | ||
'New Brunswick', 'Quebec', 'Ontario', 'Manitoba', 'Saskatchewan', | ||
'Alberta', 'British Columbia', 'Yukon', 'Northwest Territories', | ||
'Nunavut' | ||
] | ||
|
||
PROVINCE_ABBRS = k %w(NL NS PE NB QC ON MB SK AB BC YT NT NU) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'helper' | ||
|
||
class TestAddressCA < Test::Unit::TestCase | ||
def test_province | ||
assert_match /[ a-z]/, Faker::AddressCA.province | ||
end | ||
|
||
def test_province_abbr | ||
assert_match /[A-Z][A-Z]/, Faker::AddressCA.province_abbr | ||
end | ||
|
||
def test_postal_code | ||
assert_match /[A-Z]\d[A-Z]\W\d[A-Z]\d/, Faker::AddressCA.postal_code | ||
end | ||
end |