Files
sure/test/models/address_test.rb
Will Wilson ad23820a2e fix: change postal_code column from integer to string (#1585)
* fix: change postal_code column from integer to string

Allows non-numeric postal codes such as UK format (e.g. SW1A 2AA).
The integer column was silently dropping any alphanumeric input.

The migration is marked irreversible — once alphanumeric postal codes
exist, they cannot be safely cast back to integer.

* fix: update schema.rb, quote fixture postal_code, and add alphanumeric test

* fix: use conventional migration timestamp
2026-04-29 15:30:04 +02:00

57 lines
1.3 KiB
Ruby

require "test_helper"
class AddressTest < ActiveSupport::TestCase
test "can print a formatted address" do
address = Address.new(
line1: "123 Main St",
locality: "San Francisco",
region: "CA",
country: "US",
postal_code: "94101"
)
assert_equal "123 Main St, San Francisco, CA 94101 US", address.to_s
end
test "can print a formatted address with line2" do
address = Address.new(
line1: "123 Main St",
line2: "Apt 1",
locality: "San Francisco",
region: "CA",
country: "US",
postal_code: "94101"
)
assert_equal "123 Main St Apt 1, San Francisco, CA 94101 US", address.to_s
end
test "can print empty when address is empty" do
address = Address.new(
line1: nil,
line2: nil,
locality: nil,
region: nil,
country: nil,
postal_code: nil
)
assert_equal "", address.to_s
end
test "accepts alphanumeric postal codes" do
address = addresses(:one)
address.update!(postal_code: "SW1A 2AA")
assert_equal "SW1A 2AA", address.reload.postal_code
end
test "can strip extras commas and spaces" do
address = Address.new(
line1: "123 Main St ,",
locality: " San Francisco, ",
)
assert_equal "123 Main St, San Francisco", address.to_s
end
end