Skip to content

Commit

Permalink
Don't allow non zero transit numbers (#248)
Browse files Browse the repository at this point in the history
Transit numbers in Canada are 1 to 99999
  • Loading branch information
JoeSouthan committed Oct 13, 2023
1 parent 371e60b commit 8598003
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.20.0 - October 13, 2023

- Do not allow all 0 transit numbers in CA

## 1.19.0 - October 3, 2023

- Do not allow all-0 account numbers for CA
Expand Down
2 changes: 1 addition & 1 deletion data/raw/pseudo_ibans.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CA:
end: 12
excl: false
:bank_code_format: "\\d{4}"
:branch_code_format: "\\d{5}"
:branch_code_format: "0{0,4}[1-9][0-9]{0,4}"
:account_number_format: "(?!0+\\z)\\d{7,12}"
:national_id_length: 9
:pseudo_iban_bank_code_length: 4
Expand Down
2 changes: 1 addition & 1 deletion data/structures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ CA:
end: 12
excl: false
:bank_code_format: "\\d{4}"
:branch_code_format: "\\d{5}"
:branch_code_format: 0{0,4}[1-9][0-9]{0,4}
:account_number_format: "(?!0+\\z)\\d{7,12}"
:national_id_length: 9
:pseudo_iban_bank_code_length: 4
Expand Down
2 changes: 1 addition & 1 deletion lib/ibandit/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Ibandit
VERSION = "1.19.0"
VERSION = "1.20.0"
end
47 changes: 46 additions & 1 deletion spec/ibandit/iban_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,55 @@
{
country_code: "CA",
bank_code: bank_code,
branch_code: "00063",
branch_code: branch_code,
account_number: account_number,
}
end
let(:branch_code) { "00063" }

context "and a 5 digit branch code" do
let(:account_number) { "0123456" }
let(:bank_code) { "036" }
let(:branch_code) { "00063" }

its(:country_code) { is_expected.to eq("CA") }
its(:bank_code) { is_expected.to eq("0036") }
its(:branch_code) { is_expected.to eq("00063") }
its(:account_number) { is_expected.to eq("0123456") }
its(:swift_bank_code) { is_expected.to eq("0036") }
its(:swift_branch_code) { is_expected.to eq("00063") }
its(:swift_account_number) { is_expected.to eq("0123456") }
its(:swift_national_id) { is_expected.to eq("003600063") }
its(:pseudo_iban) { is_expected.to eq("CAZZ003600063_____0123456") }

its(:iban) { is_expected.to be_nil }
its(:valid?) { is_expected.to eq(true) }
its(:to_s) { is_expected.to eq("") }
end

context "for an all zero transit number" do
let(:account_number) { "0123456" }
let(:bank_code) { "036" }
let(:branch_code) { "00000" }

it "is invalid and has the correct errors" do
expect(subject.valid?).to eq(false)
expect(subject.errors).
to eq(branch_code: "format is invalid")
end
end

context "and a 4 digit branch code" do
let(:account_number) { "0123456" }
let(:bank_code) { "036" }
let(:branch_code) { "0063" }

it "is invalid and has the correct errors" do
expect(subject.valid?).to eq(false)
expect(subject.errors).
to eq(branch_code: "is the wrong length (should be 5 characters)")
end
end

context "and a 3 digit bank code" do
let(:account_number) { "0123456" }
Expand Down

0 comments on commit 8598003

Please sign in to comment.