Skip to content

Commit 42f6b50

Browse files
authored
Merge pull request #396 from Shopify/add-has-provinces
Add has_provinces? method to Region
2 parents 025f6d4 + 43739e8 commit 42f6b50

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2727

2828
## [Unreleased]
2929

30+
- Add has_provinces? method to Region [#396](https://github.com/Shopify/worldwide/pull/396)
31+
3032
---
3133

3234
## [1.19.0] - 2025-10-15

lib/worldwide/region.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ def has_cities?
401401
!!format["show"]&.include?("{city}")
402402
end
403403

404+
# Does this region have provinces in their addresses?
405+
def has_provinces?
406+
!!format["show"]&.include?("{province}")
407+
end
408+
404409
# Is this Region considered a "province" (political subdivision of a "country")?
405410
def province?
406411
@province

test/worldwide/region_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,5 +589,17 @@ class RegionTest < ActiveSupport::TestCase
589589
refute_predicate Worldwide.region(code: "AR"), :has_zip_prefixes? # zones but no prefixes
590590
assert_predicate Worldwide.region(code: "US"), :has_zip_prefixes? # zones and prefixes
591591
end
592+
593+
test "#has_provinces? returns true when region has provinces and they are not hidden from addresses" do
594+
assert_predicate Worldwide.region(code: "CA"), :has_provinces?
595+
end
596+
597+
test "#has_provinces? returns false when region has provinces but they are hidden from addresses" do
598+
refute_predicate Worldwide.region(code: "GB"), :has_provinces?
599+
end
600+
601+
test "#has_provinces? returns false when region has no provinces" do
602+
refute_predicate Worldwide.region(code: "AD"), :has_provinces?
603+
end
592604
end
593605
end

0 commit comments

Comments
 (0)