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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73aa72dcb3b94f3f1c58f0c996406c7931eecbcd
4
- data.tar.gz: f1ec617013e30ffe8e8be14aa09ae97c163dc63e
3
+ metadata.gz: ddd75b09500230fa5fccc407ffdf8bb27033bbb8
4
+ data.tar.gz: 93a3fb9f4af678aa20ef7e93d48a58918dd7f1e2
5
5
  SHA512:
6
- metadata.gz: 6c12eb467855a4f70b83ef4c43ed3e5fd4ac2955a16041dc8ac82f729821621b1e2da68ed753af965481848c98e642e2a7a5226368d22ca372ec7ea2a98451bb
7
- data.tar.gz: 38018cdf9bc96940426dc25c18cd2dfe6a3eb5aec3538be8e710ffa985691043415011e1246ffd2388fd9a4ccadac7d9a468eac42febbe1f603f27722a9e465b
6
+ metadata.gz: eb2e939049927446444d8981164e4b4cc988f504160e3cb975548f29bb58e14c6539306b4b860b4ccff0430de22e8bf0ee02f04c424b08c6346f30479c6379b2
7
+ data.tar.gz: f3e57ca5df536bc694afb2a7186bd5aecf2ff1d05bddbb385cb566d36964e06914fab13a9a7f323174cfb3c0cb6013665394d84a9489088bb4e04db8a374b5b0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.1.0
@@ -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.6 ruby lib
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.6"
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
@@ -1,5 +1,7 @@
1
1
  require_relative './active_model/iban_validator'
2
+ require_relative './active_model/bic_validator'
2
3
 
3
4
  module ActiveModel
4
5
  autoload :IbanValidator, './active_model/iban_validator'
6
+ autoload :BicValidator, './active_model/bic_validator'
5
7
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ~/Workspace/bank-validator
3
3
  specs:
4
- bank-validator (0.0.5)
4
+ bank-validator (0.0.6)
5
5
  activemodel (>= 3.0)
6
6
  activerecord (>= 3.0)
7
7
  activesupport (>= 3.0)
@@ -1,3 +1,4 @@
1
1
  class User < ActiveRecord::Base
2
2
  validates :iban, iban: true
3
+ validates :bic, bic: true
3
4
  end
@@ -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
- it 'validates a users iban' do
9
- @user.iban = 'GB82WEST12345698765432'
10
- expect(@user.save).to be(true)
11
- end
5
+ context "validating iban" do
6
+ before :each do
7
+ @user = User.create(name: 'Adam', iban: '', bic: 'DEUTDEFF500')
8
+ end
12
9
 
13
- it 'returns false for an invalid iban' do
14
- @user.iban = 'YOLO'
15
- expect(@user.save).to be(false)
16
- end
10
+ it 'validates a users iban' do
11
+ @user.iban = 'GB82WEST12345698765432'
12
+ expect(@user.save).to be(true)
13
+ end
17
14
 
18
- it 'validates a belgian users iban' do
19
- @user.iban = 'BE62510007547061'
20
- expect(@user.save).to be(true)
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
- it 'creates a user with full iban' do
24
- user = User.create(name: 'Adam', iban: 'BE62510007547061')
25
- expect(user.iban).to eq('BE62510007547061')
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
@@ -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
- should "not save if the iban is too short" do
33
- assert_equal false, TestUser.create(iban: "GB82WEST")
33
+ def bic
34
+ @bic
35
+ end
34
36
  end
35
37
 
36
- should "save if the iban is at least 16 characters" do
37
- assert_equal true, TestUser.create(iban: "GB82WEST12345698765432")
38
- end
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
- should "returns false if the iban does not leave a remainder of 1 when divided by 97" do
41
- assert_equal false, TestUser.create(iban: "GB82WEST123456987654Df")
42
- end
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
- should "returns true if the iban returns a remainder of 1 when divided by 97" do
45
- assert_equal true, TestUser.create(iban: "GB82WEST12345698765432")
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
- should "work for different IBAN formats" do
49
- #Belgium
50
- assert_equal true, TestUser.create(iban: "BE62510007547061")
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
- #Bulgaria
53
- assert_equal true, TestUser.create(iban: "BG80BNBG96611020345678")
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.6
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