Skip to content

Commit

Permalink
Stricter UK postcode generation. Fixes #44
Browse files Browse the repository at this point in the history
  • Loading branch information
stympy committed Dec 27, 2011
1 parent 4902607 commit 23303df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/locales/en-gb.yml
@@ -1,7 +1,7 @@
en-gb:
faker:
address:
postcode: ['??# #??', '??## #??']
postcode: /[A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}/
county: [Avon, Bedfordshire, Berkshire, Borders, Buckinghamshire, Cambridgeshire, Central, Cheshire, Cleveland, Clwyd, Cornwall, County Antrim, County Armagh, County Down, County Fermanagh, County Londonderry, County Tyrone, Cumbria, Derbyshire, Devon, Dorset, Dumfries and Galloway, Durham, Dyfed, East Sussex, Essex, Fife, Gloucestershire, Grampian, Greater Manchester, Gwent, Gwynedd County, Hampshire, Herefordshire, Hertfordshire, Highlands and Islands, Humberside, Isle of Wight, Kent, Lancashire, Leicestershire, Lincolnshire, Lothian, Merseyside, Mid Glamorgan, Norfolk, North Yorkshire, Northamptonshire, Northumberland, Nottinghamshire, Oxfordshire, Powys, Rutland, Shropshire, Somerset, South Glamorgan, South Yorkshire, Staffordshire, Strathclyde, Suffolk, Surrey, Tayside, Tyne and Wear, Warwickshire, West Glamorgan, West Midlands, West Sussex, West Yorkshire, Wiltshire, Worcestershire]
uk_country: [England, Scotland, Wales, Northern Ireland]
default_country: [England, Scotland, Wales, Northern Ireland]
Expand Down
12 changes: 9 additions & 3 deletions test/test_locale.rb
Expand Up @@ -16,20 +16,26 @@ def test_locale_separate_from_i18n
assert Faker::PhoneNumber.phone_number.match(/\(0\d+\) \d+|\+49-\d+-\d+/)
assert Faker::Address.street_name.match(//)
end

def test_configured_locale_translation
Faker::Config.locale = 'en-bork'
assert_equal Faker::Base.translate('faker.lorem.words').first, LoadedYaml['en-bork']['lorem']['words'].first
end

def test_locale_override_when_calling_translate
Faker::Config.locale = 'en-bork'
assert_equal Faker::Base.translate('faker.lorem.words', :locale => :en).first, LoadedYaml['en']['lorem']['words'].first
end

def test_translation_fallback
Faker::Config.locale = 'en-bork'
assert_nil LoadedYaml['en-bork']['name']
assert_equal Faker::Base.translate('faker.name.first_name').first, LoadedYaml['en']['name']['first_name'].first
end

def test_regex
Faker::Config.locale = 'en-gb'
re = /[A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}/
assert re.match(result = Faker::Address.postcode), "#{result} didn't match #{re}"
end
end

0 comments on commit 23303df

Please sign in to comment.