Repository navigation
Accept Panama's 10-character postal codes and release 2.1.0 #678
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Worldwide | ||
| VERSION = "2.0.1" | ||
| VERSION = "2.1.0" | ||
| end |
This file contains hidden or 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 hidden or 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,54 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "test_helper" | ||
|
|
||
| module Worldwide | ||
| class PaTest < ActiveSupport::TestCase | ||
| setup do | ||
| @region = Worldwide.region(code: "PA") | ||
| end | ||
|
|
||
| test "four digit postal codes are valid" do | ||
| assert @region.valid_zip?("0815") # Correos y Telégrafos, Avenida Central y Calle 34 | ||
| end | ||
|
|
||
| test "ten character postal codes are valid" do | ||
| assert @region.valid_zip?("ADC96-M8H44") # Municipio de Panamá, Avenida Justo Arosemena | ||
| end | ||
|
|
||
| test "ten character postal codes are valid without the hyphen, in lowercase, or with spaces" do | ||
| ["ADC96M8H44", "adc96-m8h44", "ADC96 M8H44", "ADC96M-8H44", "ADC96\u2013M8H44"].each do |zip| | ||
| assert @region.valid_zip?(zip), "Expected #{zip.inspect} to be valid" | ||
| end | ||
| end | ||
|
|
||
| test "zip_regex accepts a hyphen, a space, or nothing between the two groups" do | ||
| regex = Regexp.new(@region.zip_regex) | ||
|
|
||
| ["ADC96-M8H44", "ADC96 M8H44", "ADC96M8H44"].each do |zip| | ||
| assert_match regex, zip | ||
| end | ||
| ["ADC96--M8H44", "ADC96 M8H44", "ADC96_M8H44"].each do |zip| | ||
| assert_no_match regex, zip | ||
| end | ||
| end | ||
|
|
||
| test "blank postal codes are valid because the postal code is optional" do | ||
| assert @region.valid_zip?(nil) | ||
| assert @region.valid_zip?("") | ||
| end | ||
|
|
||
| test "ten character postal codes with characters outside the official alphabet are invalid" do | ||
| # After the 2-character prefix, codes use only 23456789ABCDEFGHJKLMNPQRSTVWXZ | ||
| ["AD096-M8H44", "ADC16-M8H44", "ADC96-I8H44", "ADC96-M8O44", "ADC96-M8H4U", "ADC96-Y8H44"].each do |zip| | ||
| assert_not @region.valid_zip?(zip), "Expected #{zip.inspect} to be invalid" | ||
| end | ||
| end | ||
|
|
||
| test "codes of other lengths are invalid" do | ||
| ["815", "08150", "C96M8H44", "ADC96-M8H4", "ADC96-M8H442"].each do |zip| | ||
| assert_not @region.valid_zip?(zip), "Expected #{zip.inspect} to be invalid" | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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
Oops, something went wrong.
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.
Q: By removing PA from this set do we lose some shared normalizing capabilities?
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.
Yes, for the legacy 4-digit codes only; the 10-character codes never validated on
main, so they lose nothing.OILZSB→011258):O815used to normalize to0815; now it's rejected and the buyer sees the validation error. Keeping it would need a length-based PA special case, and that misfires on partially typed new codes (B2S5→8255, a valid 4-digit code). The legacy codes are PO-box zones that rarely appear in shipping addresses, and the field is optional, so I'd rather surface the error than silently rewrite the input.strip_extraneous_characters: trueremoved every non-digit (0815 PANAMA→0815). That can't apply once letters are valid in PA codes.Spaces and punctuation are still removed as before (
0815,0815.→0815).