bank-validator 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bank-validator.gemspec +3 -2
- data/lib/active_model/bic_validator.rb +18 -0
- data/lib/bank-validator.rb +2 -0
- data/test/dummy/Gemfile.lock +1 -1
- data/test/dummy/app/models/user.rb +1 -0
- data/test/dummy/spec/features/gem_testing_spec.rb +52 -17
- data/test/test_bank-validator.rb +39 -18
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddd75b09500230fa5fccc407ffdf8bb27033bbb8
|
4
|
+
data.tar.gz: 93a3fb9f4af678aa20ef7e93d48a58918dd7f1e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb2e939049927446444d8981164e4b4cc988f504160e3cb975548f29bb58e14c6539306b4b860b4ccff0430de22e8bf0ee02f04c424b08c6346f30479c6379b2
|
7
|
+
data.tar.gz: f3e57ca5df536bc694afb2a7186bd5aecf2ff1d05bddbb385cb566d36964e06914fab13a9a7f323174cfb3c0cb6013665394d84a9489088bb4e04db8a374b5b0
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/bank-validator.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
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.0
|
5
|
+
# stub: bank-validator 0.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "bank-validator"
|
9
|
-
s.version = "0.0
|
9
|
+
s.version = "0.1.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"]
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
29
|
"bank-validator.gemspec",
|
30
|
+
"lib/active_model/bic_validator.rb",
|
30
31
|
"lib/active_model/iban_validator.rb",
|
31
32
|
"lib/bank-validator.rb",
|
32
33
|
"test/dummy/.gitignore",
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
|
3
|
+
class BicValidator < ActiveModel::EachValidator
|
4
|
+
|
5
|
+
def validate_each(record, attribute, value)
|
6
|
+
record_error(record, attribute, value) unless value =~ regexp
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def record_error(record, attribute, value)
|
12
|
+
record.errors.add(attribute, :invalid_bic)
|
13
|
+
end
|
14
|
+
|
15
|
+
def regexp
|
16
|
+
/[A-Z]{6}[A-Z0-9]{2,}/
|
17
|
+
end
|
18
|
+
end
|
data/lib/bank-validator.rb
CHANGED
data/test/dummy/Gemfile.lock
CHANGED
@@ -1,27 +1,62 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
RSpec.describe 'testing the gem', type: :feature do
|
4
|
-
before :each do
|
5
|
-
@user = User.create(name: 'Adam', iban: '', bic: '')
|
6
|
-
end
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
context "validating iban" do
|
6
|
+
before :each do
|
7
|
+
@user = User.create(name: 'Adam', iban: '', bic: 'DEUTDEFF500')
|
8
|
+
end
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
it 'validates a users iban' do
|
11
|
+
@user.iban = 'GB82WEST12345698765432'
|
12
|
+
expect(@user.save).to be(true)
|
13
|
+
end
|
17
14
|
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
it 'returns false for an invalid iban' do
|
16
|
+
@user.iban = 'YOLO'
|
17
|
+
expect(@user.save).to be(false)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'validates a belgian users iban' do
|
21
|
+
@user.iban = 'BE62510007547061'
|
22
|
+
expect(@user.save).to be(true)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'creates a user with full iban' do
|
26
|
+
user = User.create(name: 'Adam', iban: 'BE62510007547061')
|
27
|
+
expect(user.iban).to eq('BE62510007547061')
|
28
|
+
end
|
21
29
|
end
|
22
30
|
|
23
|
-
|
24
|
-
|
25
|
-
|
31
|
+
context "validating bic" do
|
32
|
+
before :each do
|
33
|
+
@user = User.create(name: 'Adam', iban: 'BE62510007547061', bic: '')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'validates a users bic' do
|
37
|
+
@user.bic = 'DEUTDEBR'
|
38
|
+
expect(@user.save).to be(true)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns false for an invalid bic' do
|
42
|
+
@user.bic = 'YOLO'
|
43
|
+
expect(@user.save).to be(false)
|
44
|
+
|
45
|
+
@user.bic = 'D3UTDEBR'
|
46
|
+
expect(@user.save).to be(false)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'validates a different bic types' do
|
50
|
+
@user.bic = 'DEUTDEDBBER'
|
51
|
+
expect(@user.save).to be(true)
|
52
|
+
|
53
|
+
@user.bic = 'DEUTDEFF500'
|
54
|
+
expect(@user.save).to be(true)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'saves the bic' do
|
58
|
+
user = User.create(name: 'Adam', iban: 'BE62510007547061', bic: 'DEUTDEFF500')
|
59
|
+
expect(user.bic).to eq('DEUTDEFF500')
|
60
|
+
end
|
26
61
|
end
|
27
62
|
end
|
data/test/test_bank-validator.rb
CHANGED
@@ -5,11 +5,13 @@ class TestBankValidator < MiniTest::Test
|
|
5
5
|
class TestUser
|
6
6
|
include ActiveModel::Validations
|
7
7
|
validates :iban, iban: true
|
8
|
+
validates :bic, bic: true
|
8
9
|
|
9
10
|
attr_accessor :iban
|
10
11
|
|
11
12
|
def initialize(attributes = {})
|
12
13
|
@iban = attributes[:iban]
|
14
|
+
@bic = attributes[:bic]
|
13
15
|
end
|
14
16
|
|
15
17
|
def save
|
@@ -27,32 +29,51 @@ class TestBankValidator < MiniTest::Test
|
|
27
29
|
def iban
|
28
30
|
@iban
|
29
31
|
end
|
30
|
-
end
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
def bic
|
34
|
+
@bic
|
35
|
+
end
|
34
36
|
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
context "iban validator" do
|
39
|
+
should "not save if the iban is too short" do
|
40
|
+
assert_equal false, TestUser.create(iban: "GB82WEST", bic: "DEUTDEBR")
|
41
|
+
end
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
should "save if the iban is at least 16 characters" do
|
44
|
+
assert_equal true, TestUser.create(iban: "GB82WEST12345698765432", bic: "DEUTDEBR")
|
45
|
+
end
|
46
|
+
|
47
|
+
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")
|
49
|
+
end
|
43
50
|
|
44
|
-
|
45
|
-
|
51
|
+
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")
|
53
|
+
end
|
54
|
+
|
55
|
+
should "work for different IBAN formats" do
|
56
|
+
#Belgium
|
57
|
+
assert_equal true, TestUser.create(iban: "BE62510007547061", bic: "DEUTDEBR")
|
58
|
+
|
59
|
+
#Bulgaria
|
60
|
+
assert_equal true, TestUser.create(iban: "BG80BNBG96611020345678", bic: "DEUTDEBR")
|
61
|
+
|
62
|
+
#Germany
|
63
|
+
assert_equal true, TestUser.create(iban: "DE89370400440532013000", bic: "DEUTDEBR")
|
64
|
+
end
|
46
65
|
end
|
47
66
|
|
48
|
-
|
49
|
-
|
50
|
-
|
67
|
+
context "bic validator" do
|
68
|
+
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")
|
71
|
+
end
|
51
72
|
|
52
|
-
|
53
|
-
|
73
|
+
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")
|
76
|
+
end
|
54
77
|
|
55
|
-
#Germany
|
56
|
-
assert_equal true, TestUser.create(iban: "DE89370400440532013000")
|
57
78
|
end
|
58
79
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bank-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Bahlke
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- Rakefile
|
153
153
|
- VERSION
|
154
154
|
- bank-validator.gemspec
|
155
|
+
- lib/active_model/bic_validator.rb
|
155
156
|
- lib/active_model/iban_validator.rb
|
156
157
|
- lib/bank-validator.rb
|
157
158
|
- test/dummy/.gitignore
|