bank-validator 0.2.2 → 0.2.3

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: 4e50ae23a715911b48b2719007826a9cade6f052
4
- data.tar.gz: ff4026eb0d5ade84c6d5d60e48f68d7589e6b0e2
3
+ metadata.gz: a12a8cb39e85cd7d3095f4531e93280815e1c6ad
4
+ data.tar.gz: 696ef669eda1a6b45c321d8370ed271f40604ad5
5
5
  SHA512:
6
- metadata.gz: fe563fd57de306b2a158ea02fc43e22e573b863ea9174f89d79df90ce534290d9d2b82b63e6b7f8343d37c11ef7c06101c282089c94571c069386b6c73e7fd38
7
- data.tar.gz: 4846d208591cde4ec4168882b0cc2a76e668d295fbc8cbbab55a2835299e13ef601ffbcc27c6024c0edf431984bf01823dd6e31975631f16e27565d8b10bb73b
6
+ metadata.gz: 4bf523388656b2848daf70438f5be12aae3255a29f8ac84351545097408af1c03960f71cf83d2b01b7b24252d143b4153737b5ad88136d956f24dfc08b5d2965
7
+ data.tar.gz: 6ec35e9c6495af57215244c1c00d7924ad1cd5ae2bf7a0e944ac3bb388cc651db54803fbbf2c0df56bc508e233a128f1e15568d6516913de147abdff4d7eb6fc
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -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.2.2 ruby lib
5
+ # stub: bank-validator 0.2.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "bank-validator"
9
- s.version = "0.2.2"
9
+ s.version = "0.2.3"
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-31"
14
+ s.date = "2015-04-01"
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 = [
@@ -89,6 +89,9 @@ Gem::Specification.new do |s|
89
89
  "test/dummy/spec/spec_helper.rb",
90
90
  "test/dummy/vendor/assets/javascripts/.keep",
91
91
  "test/dummy/vendor/assets/stylesheets/.keep",
92
+ "test/dummy_classes.rb",
93
+ "test/dummy_classes/dummy_user.rb",
94
+ "test/dummy_classes/dummy_user2.rb",
92
95
  "test/helper.rb",
93
96
  "test/test_bank-validator.rb"
94
97
  ]
@@ -9,7 +9,7 @@ class BicValidator < ActiveModel::EachValidator
9
9
  private
10
10
 
11
11
  def record_error(record, attribute, value)
12
- record.errors.add(attribute, (:invalid_bic || options[:message]))
12
+ record.errors.add(attribute, (options[:message] || :invalid_bic))
13
13
  end
14
14
 
15
15
  def regexp
@@ -9,7 +9,7 @@ class IbanValidator < ActiveModel::EachValidator
9
9
  private
10
10
 
11
11
  def record_error(record, attribute, value)
12
- record.errors.add(attribute, (:invalid_iban || options[:message]))
12
+ record.errors.add(attribute, (options[:message] || :invalid_iban))# || options[:message]))
13
13
  end
14
14
 
15
15
  def regexp
@@ -9,7 +9,7 @@ class RoutingNumberValidator < ActiveModel::EachValidator
9
9
  private
10
10
 
11
11
  def record_error(record, attribute, value)
12
- record.errors.add(attribute, (:invalid_routing_number || options[:message]))
12
+ record.errors.add(attribute, (options[:message] || :invalid_routing_number))
13
13
  end
14
14
 
15
15
  def regexp
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ~/Workspace/bank-validator
3
3
  specs:
4
- bank-validator (0.2.1)
4
+ bank-validator (0.2.2)
5
5
  activemodel (>= 3.0)
6
6
  activerecord (>= 3.0)
7
7
  activesupport (>= 3.0)
@@ -0,0 +1,3 @@
1
+ require 'helper'
2
+ require 'dummy_classes/dummy_user'
3
+ require 'dummy_classes/dummy_user2'
@@ -0,0 +1,38 @@
1
+ class DummyUser
2
+ include ActiveModel::Validations
3
+ validates :iban, iban: true
4
+ validates :bic, bic: true
5
+ validates :routing_number, routing_number: true
6
+
7
+ attr_accessor :iban
8
+
9
+ def initialize(attributes = {})
10
+ @iban = attributes[:iban]
11
+ @bic = attributes[:bic]
12
+ @routing_number = attributes[:routing_number]
13
+ end
14
+
15
+ def save
16
+ if valid?
17
+ return true
18
+ else
19
+ return false
20
+ end
21
+ end
22
+
23
+ def self.create(attributes = {})
24
+ new(attributes).save
25
+ end
26
+
27
+ def iban
28
+ @iban
29
+ end
30
+
31
+ def bic
32
+ @bic
33
+ end
34
+
35
+ def routing_number
36
+ @routing_number
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ class DummyUser2
2
+ include ActiveModel::Validations
3
+ validates :iban, iban: {:message => 'custom iban error message'}
4
+ validates :bic, bic: {:message => 'custom bic error message'}
5
+ validates :routing_number, routing_number: {:message => 'custom routing number error message'}
6
+
7
+ attr_accessor :iban
8
+
9
+ def initialize(attributes = {})
10
+ @iban = attributes[:iban]
11
+ @bic = attributes[:bic]
12
+ @routing_number = attributes[:routing_number]
13
+ end
14
+
15
+ def save
16
+ if valid?
17
+ return true
18
+ else
19
+ return false
20
+ end
21
+ end
22
+
23
+ def self.create(attributes = {})
24
+ new(attributes).save
25
+ end
26
+
27
+ def iban
28
+ @iban
29
+ end
30
+
31
+ def bic
32
+ @bic
33
+ end
34
+
35
+ def routing_number
36
+ @routing_number
37
+ end
38
+ end
@@ -1,95 +1,75 @@
1
- require 'helper'
2
-
1
+ require 'dummy_classes'
3
2
  class TestBankValidator < MiniTest::Test
4
3
 
5
- class TestUser
6
- include ActiveModel::Validations
7
- validates :iban, iban: true
8
- validates :bic, bic: true
9
- validates :routing_number, routing_number: true
10
-
11
- attr_accessor :iban
12
-
13
- def initialize(attributes = {})
14
- @iban = attributes[:iban]
15
- @bic = attributes[:bic]
16
- @routing_number = attributes[:routing_number]
17
- end
18
-
19
- def save
20
- if valid?
21
- return true
22
- else
23
- return false
24
- end
25
- end
26
-
27
- def self.create(attributes = {})
28
- new(attributes).save
29
- end
30
-
31
- def iban
32
- @iban
4
+ context "test custom messages" do
5
+ should "display custom iban error message" do
6
+ user = DummyUser2.new(iban: "GB82WEST", bic: "DEUTDEBR", routing_number: "026009593")
7
+ user.valid?
8
+ assert_equal ['custom iban error message'], user.errors[:iban]
33
9
  end
34
10
 
35
- def bic
36
- @bic
11
+ should "display custom bic error message" do
12
+ user = DummyUser2.new(iban: "GB82WEST12345698765432", bic: "DEUTDE", routing_number: "026009593")
13
+ user.valid?
14
+ assert_equal ['custom bic error message'], user.errors[:bic]
37
15
  end
38
16
 
39
- def routing_number
40
- @routing_number
17
+ should "display custom routing number error message" do
18
+ user = DummyUser2.new(iban: "GB82WEST12345698765432", bic: "DEUTDEBR", routing_number: "02600959")
19
+ user.valid?
20
+ assert_equal ['custom routing number error message'], user.errors[:routing_number]
41
21
  end
42
22
  end
43
23
 
44
24
  context "iban validator" do
45
25
  should "not save if the iban is too short" do
46
- assert_equal false, TestUser.create(iban: "GB82WEST", bic: "DEUTDEBR", routing_number: "026009593")
26
+ assert_equal false, DummyUser.create(iban: "GB82WEST", bic: "DEUTDEBR", routing_number: "026009593")
47
27
  end
48
28
 
49
29
  should "save if the iban is at least 16 characters" do
50
- assert_equal true, TestUser.create(iban: "GB82WEST12345698765432", bic: "DEUTDEBR", routing_number: "026009593")
30
+ assert_equal true, DummyUser.create(iban: "GB82WEST12345698765432", bic: "DEUTDEBR", routing_number: "026009593")
51
31
  end
52
32
 
53
33
  should "returns false if the iban does not leave a remainder of 1 when divided by 97" do
54
- assert_equal false, TestUser.create(iban: "GB82WEST123456987654Df", bic: "DEUTDEBR", routing_number: "026009593")
34
+ assert_equal false, DummyUser.create(iban: "GB82WEST123456987654Df", bic: "DEUTDEBR", routing_number: "026009593")
55
35
  end
56
36
 
57
37
  should "returns true if the iban returns a remainder of 1 when divided by 97" do
58
- assert_equal true, TestUser.create(iban: "GB82WEST12345698765432", bic: "DEUTDEBR", routing_number: "026009593")
38
+ assert_equal true, DummyUser.create(iban: "GB82WEST12345698765432", bic: "DEUTDEBR", routing_number: "026009593")
59
39
  end
60
40
 
61
41
  should "work for different IBAN formats" do
62
42
  #Belgium
63
- assert_equal true, TestUser.create(iban: "BE62510007547061", bic: "DEUTDEBR", routing_number: "026009593")
43
+ assert_equal true, DummyUser.create(iban: "BE62510007547061", bic: "DEUTDEBR", routing_number: "026009593")
64
44
 
65
45
  #Bulgaria
66
- assert_equal true, TestUser.create(iban: "BG80BNBG96611020345678", bic: "DEUTDEBR", routing_number: "026009593")
46
+ assert_equal true, DummyUser.create(iban: "BG80BNBG96611020345678", bic: "DEUTDEBR", routing_number: "026009593")
67
47
 
68
48
  #Germany
69
- assert_equal true, TestUser.create(iban: "DE89370400440532013000", bic: "DEUTDEBR", routing_number: "026009593")
49
+ assert_equal true, DummyUser.create(iban: "DE89370400440532013000", bic: "DEUTDEBR", routing_number: "026009593")
70
50
  end
71
51
  end
72
52
 
73
53
  context "bic validator" do
74
54
  should "be between 8 and 11 characters" do
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")
55
+ assert_equal true, DummyUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "026009593")
56
+ assert_equal true, DummyUser.create(bic: "DEUTDEBR123", iban: "BE62510007547061", routing_number: "026009593")
77
57
  end
78
58
 
79
59
  should "start with 6 letters" do
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")
60
+ assert_equal true, DummyUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "026009593")
61
+ assert_equal false, DummyUser.create(bic: "DEUT22BR", iban: "BE62510007547061", routing_number: "026009593")
82
62
  end
83
63
  end
84
64
 
85
65
  context "routing number" do
86
66
  should "be 9 digits long" do
87
- assert_equal true, TestUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "026009593")
67
+ assert_equal true, DummyUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "026009593")
88
68
  end
89
69
 
90
70
  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")
71
+ assert_equal false, DummyUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "02600959")
72
+ assert_equal false, DummyUser.create(bic: "DEUTDEBR", iban: "BE62510007547061", routing_number: "0260095933")
93
73
  end
94
74
  end
95
75
  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.2.2
4
+ version: 0.2.3
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-31 00:00:00.000000000 Z
11
+ date: 2015-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -214,6 +214,9 @@ files:
214
214
  - test/dummy/spec/spec_helper.rb
215
215
  - test/dummy/vendor/assets/javascripts/.keep
216
216
  - test/dummy/vendor/assets/stylesheets/.keep
217
+ - test/dummy_classes.rb
218
+ - test/dummy_classes/dummy_user.rb
219
+ - test/dummy_classes/dummy_user2.rb
217
220
  - test/helper.rb
218
221
  - test/test_bank-validator.rb
219
222
  homepage: http://github.com/declarus/bank-validator