bank-validator 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddd75b09500230fa5fccc407ffdf8bb27033bbb8
4
- data.tar.gz: 93a3fb9f4af678aa20ef7e93d48a58918dd7f1e2
3
+ metadata.gz: ce72710f7f5b48fe94d61e369c631410fd437571
4
+ data.tar.gz: c70fa8f2e6775e95b94b6df61d28013eb9c064a1
5
5
  SHA512:
6
- metadata.gz: eb2e939049927446444d8981164e4b4cc988f504160e3cb975548f29bb58e14c6539306b4b860b4ccff0430de22e8bf0ee02f04c424b08c6346f30479c6379b2
7
- data.tar.gz: f3e57ca5df536bc694afb2a7186bd5aecf2ff1d05bddbb385cb566d36964e06914fab13a9a7f323174cfb3c0cb6013665394d84a9489088bb4e04db8a374b5b0
6
+ metadata.gz: 9b2818360426dde18ed7da0613ef33b993e789c94a5e537d5991226d69973359802a5abebb207bcecbde8db64235ed4f5e3946c07663d7e1d9c656c2a0bd998b
7
+ data.tar.gz: 9160b86ea2a11feb65ffcbfe40e0f048fdf3d30d8c73111e813367661ed93e2970c4ff5b6957d694563374fa63afdef61a200f6b0fe6040cb98454043e0c01ae
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: bank-validator 0.1.0 ruby lib
5
+ # stub: bank-validator 0.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "bank-validator"
9
- s.version = "0.1.0"
9
+ s.version = "0.2.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Adam Bahlke"]
14
- s.date = "2015-03-30"
14
+ s.date = "2015-03-31"
15
15
  s.description = "Validates IBAN and BIC account numbers. Still a work in progress"
16
16
  s.email = "adam.bahlke@hitfoxgroup.com"
17
17
  s.extra_rdoc_files = [
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "bank-validator.gemspec",
30
30
  "lib/active_model/bic_validator.rb",
31
31
  "lib/active_model/iban_validator.rb",
32
+ "lib/active_model/routing_number_validator.rb",
32
33
  "lib/bank-validator.rb",
33
34
  "test/dummy/.gitignore",
34
35
  "test/dummy/.rspec",
@@ -72,6 +73,7 @@ Gem::Specification.new do |s|
72
73
  "test/dummy/config/routes.rb",
73
74
  "test/dummy/config/secrets.yml",
74
75
  "test/dummy/db/migrate/20150330083818_create_users.rb",
76
+ "test/dummy/db/migrate/20150331083155_add_routing_number_to_users.rb",
75
77
  "test/dummy/db/schema.rb",
76
78
  "test/dummy/db/seeds.rb",
77
79
  "test/dummy/lib/assets/.keep",
@@ -0,0 +1,24 @@
1
+ require 'active_model'
2
+
3
+ class RoutingNumberValidator < ActiveModel::EachValidator
4
+
5
+ def validate_each(record, attribute, value)
6
+ record_error(record, attribute, value) unless value =~ regexp && valid_routing_number?(value)
7
+ end
8
+
9
+ private
10
+
11
+ def record_error(record, attribute, value)
12
+ record.errors.add(attribute, :invalid_iban)
13
+ end
14
+
15
+ def regexp
16
+ /^[0-9]{9}$/
17
+ end
18
+
19
+ def valid_routing_number?(route_number)
20
+ d = route_number.split(//)
21
+
22
+ ((3 * (d[0].to_i + d[3].to_i + d[6].to_i)) + (7 * (d[1].to_i + d[4].to_i + d[7].to_i)) + (d[2].to_i + d[5].to_i + d[8].to_i)) % 10 == 0
23
+ end
24
+ end
@@ -1,7 +1,9 @@
1
1
  require_relative './active_model/iban_validator'
2
2
  require_relative './active_model/bic_validator'
3
+ require_relative './active_model/routing_number_validator'
3
4
 
4
5
  module ActiveModel
5
6
  autoload :IbanValidator, './active_model/iban_validator'
6
7
  autoload :BicValidator, './active_model/bic_validator'
8
+ autoload :RoutingNumberValidator, './active_model/routing_number_validator'
7
9
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ~/Workspace/bank-validator
3
3
  specs:
4
- bank-validator (0.0.6)
4
+ bank-validator (0.1.0)
5
5
  activemodel (>= 3.0)
6
6
  activerecord (>= 3.0)
7
7
  activesupport (>= 3.0)
@@ -1,4 +1,5 @@
1
1
  class User < ActiveRecord::Base
2
2
  validates :iban, iban: true
3
3
  validates :bic, bic: true
4
+ validates :routing_number, routing_number: true
4
5
  end
@@ -0,0 +1,5 @@
1
+ class AddRoutingNumberToUsers < ActiveRecord::Migration
2
+ def change
3
+ add_column :users, :routing_number, :string
4
+ end
5
+ end
@@ -11,14 +11,15 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20150330083818) do
14
+ ActiveRecord::Schema.define(version: 20150331083155) do
15
15
 
16
16
  create_table "users", force: :cascade do |t|
17
17
  t.string "name"
18
18
  t.string "iban"
19
19
  t.string "bic"
20
- t.datetime "created_at", null: false
21
- t.datetime "updated_at", null: false
20
+ t.datetime "created_at", null: false
21
+ t.datetime "updated_at", null: false
22
+ t.string "routing_number"
22
23
  end
23
24
 
24
25
  end
@@ -4,7 +4,7 @@ RSpec.describe 'testing the gem', type: :feature do
4
4
 
5
5
  context "validating iban" do
6
6
  before :each do
7
- @user = User.create(name: 'Adam', iban: '', bic: 'DEUTDEFF500')
7
+ @user = User.create(name: 'Adam', iban: '', bic: 'DEUTDEFF500', routing_number: '226073523')
8
8
  end
9
9
 
10
10
  it 'validates a users iban' do
@@ -30,7 +30,7 @@ RSpec.describe 'testing the gem', type: :feature do
30
30
 
31
31
  context "validating bic" do
32
32
  before :each do
33
- @user = User.create(name: 'Adam', iban: 'BE62510007547061', bic: '')
33
+ @user = User.create(name: 'Adam', iban: 'BE62510007547061', bic: '', routing_number: '226073523')
34
34
  end
35
35
 
36
36
  it 'validates a users bic' do
@@ -59,4 +59,26 @@ RSpec.describe 'testing the gem', type: :feature do
59
59
  expect(user.bic).to eq('DEUTDEFF500')
60
60
  end
61
61
  end
62
+
63
+ context "validating routing number" do
64
+ before :each do
65
+ @user = User.create(name: 'Adam', iban: 'BE62510007547061', bic: 'DEUTDEFF500', routing_number: '')
66
+ end
67
+
68
+ it 'validates a users routing number' do
69
+ @user.routing_number = '226073523'
70
+ expect(@user.save).to be(true)
71
+ end
72
+
73
+ it 'returns false for an invalid routing number' do
74
+ @user.routing_number = '22607352'
75
+ expect(@user.save).to be(false)
76
+
77
+ @user.routing_number = '2260735233'
78
+ expect(@user.save).to be(false)
79
+
80
+ @user.routing_number = '2260-7352-3'
81
+ expect(@user.save).to be(false)
82
+ end
83
+ end
62
84
  end
@@ -6,12 +6,14 @@ class TestBankValidator < MiniTest::Test
6
6
  include ActiveModel::Validations
7
7
  validates :iban, iban: true
8
8
  validates :bic, bic: true
9
+ validates :routing_number, routing_number: true
9
10
 
10
11
  attr_accessor :iban
11
12
 
12
13
  def initialize(attributes = {})
13
14
  @iban = attributes[:iban]
14
15
  @bic = attributes[:bic]
16
+ @routing_number = attributes[:routing_number]
15
17
  end
16
18
 
17
19
  def save
@@ -33,47 +35,61 @@ class TestBankValidator < MiniTest::Test
33
35
  def bic
34
36
  @bic
35
37
  end
38
+
39
+ def routing_number
40
+ @routing_number
41
+ end
36
42
  end
37
43
 
38
44
  context "iban validator" do
39
45
  should "not save if the iban is too short" do
40
- assert_equal false, TestUser.create(iban: "GB82WEST", bic: "DEUTDEBR")
46
+ assert_equal false, TestUser.create(iban: "GB82WEST", bic: "DEUTDEBR", routing_number: "026009593")
41
47
  end
42
48
 
43
49
  should "save if the iban is at least 16 characters" do
44
- assert_equal true, TestUser.create(iban: "GB82WEST12345698765432", bic: "DEUTDEBR")
50
+ assert_equal true, TestUser.create(iban: "GB82WEST12345698765432", bic: "DEUTDEBR", routing_number: "026009593")
45
51
  end
46
52
 
47
53
  should "returns false if the iban does not leave a remainder of 1 when divided by 97" do
48
- assert_equal false, TestUser.create(iban: "GB82WEST123456987654Df", bic: "DEUTDEBR")
54
+ assert_equal false, TestUser.create(iban: "GB82WEST123456987654Df", bic: "DEUTDEBR", routing_number: "026009593")
49
55
  end
50
56
 
51
57
  should "returns true if the iban returns a remainder of 1 when divided by 97" do
52
- assert_equal true, TestUser.create(iban: "GB82WEST12345698765432", bic: "DEUTDEBR")
58
+ assert_equal true, TestUser.create(iban: "GB82WEST12345698765432", bic: "DEUTDEBR", routing_number: "026009593")
53
59
  end
54
60
 
55
61
  should "work for different IBAN formats" do
56
62
  #Belgium
57
- assert_equal true, TestUser.create(iban: "BE62510007547061", bic: "DEUTDEBR")
63
+ assert_equal true, TestUser.create(iban: "BE62510007547061", bic: "DEUTDEBR", routing_number: "026009593")
58
64
 
59
65
  #Bulgaria
60
- assert_equal true, TestUser.create(iban: "BG80BNBG96611020345678", bic: "DEUTDEBR")
66
+ assert_equal true, TestUser.create(iban: "BG80BNBG96611020345678", bic: "DEUTDEBR", routing_number: "026009593")
61
67
 
62
68
  #Germany
63
- assert_equal true, TestUser.create(iban: "DE89370400440532013000", bic: "DEUTDEBR")
69
+ assert_equal true, TestUser.create(iban: "DE89370400440532013000", bic: "DEUTDEBR", routing_number: "026009593")
64
70
  end
65
71
  end
66
72
 
67
73
  context "bic validator" do
68
74
  should "be between 8 and 11 characters" do
69
- assert_equal true, TestUser.create(bic: "DEUTDEBR", iban: "BE62510007547061")
70
- assert_equal true, TestUser.create(bic: "DEUTDEBR123", iban: "BE62510007547061")
75
+ assert_equal true, TestUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "026009593")
76
+ assert_equal true, TestUser.create(bic: "DEUTDEBR123", iban: "BE62510007547061", routing_number: "026009593")
71
77
  end
72
78
 
73
79
  should "start with 6 letters" do
74
- assert_equal true, TestUser.create(bic: "DEUTDEBR", iban: "BE62510007547061")
75
- assert_equal false, TestUser.create(bic: "DEUT22BR", iban: "BE62510007547061")
80
+ assert_equal true, TestUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "026009593")
81
+ assert_equal false, TestUser.create(bic: "DEUT22BR", iban: "BE62510007547061", routing_number: "026009593")
82
+ end
83
+ end
84
+
85
+ context "routing number" do
86
+ should "be 9 digits long" do
87
+ assert_equal true, TestUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "026009593")
76
88
  end
77
89
 
90
+ should "return false if not 9 digits long" do
91
+ assert_equal false, TestUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "02600959")
92
+ assert_equal false, TestUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "0260095933")
93
+ end
78
94
  end
79
95
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bank-validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Bahlke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-30 00:00:00.000000000 Z
11
+ date: 2015-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -154,6 +154,7 @@ files:
154
154
  - bank-validator.gemspec
155
155
  - lib/active_model/bic_validator.rb
156
156
  - lib/active_model/iban_validator.rb
157
+ - lib/active_model/routing_number_validator.rb
157
158
  - lib/bank-validator.rb
158
159
  - test/dummy/.gitignore
159
160
  - test/dummy/.rspec
@@ -197,6 +198,7 @@ files:
197
198
  - test/dummy/config/routes.rb
198
199
  - test/dummy/config/secrets.yml
199
200
  - test/dummy/db/migrate/20150330083818_create_users.rb
201
+ - test/dummy/db/migrate/20150331083155_add_routing_number_to_users.rb
200
202
  - test/dummy/db/schema.rb
201
203
  - test/dummy/db/seeds.rb
202
204
  - test/dummy/lib/assets/.keep