validates_as_vat_number 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -19,6 +19,8 @@ Then install it.
19
19
  validates_as_vat_number :vat
20
20
  end
21
21
 
22
+ ## Acknowledgements
23
+ Thanks to [sborsje](http://github.com/sborsje) for fixing the instance with valid ISO 3660 but unsupported codes.
22
24
 
23
25
  ## Note on Patches/Pull Requests
24
26
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
@@ -9,8 +9,6 @@ module Develon
9
9
  }
10
10
  configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
11
11
 
12
- iso3661_country_codes = %w(AF AX AL DZ AS AD AO AI AQ AG AR AM AW AU AT AZ BS BH BD BB BY BE BZ BJ BM BT BO BA BW BV BR IO BN BG BF BI KH CM CA CV KY CF TD CL CN CX CC CO KM CG CD CK CR CI HR CU CY CZ DK DJ DM DO EC EG SV GQ ER EE ET FK FO FJ FI FR GF PF TF GA GM GE DE GH GI GR GL GD GP GU GT GG GN GW GY HT HM VA HN HK HU IS IN ID IR IQ IE IM IL IT JM JP JE JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU MO MK MG MW MY MV ML MT MH MQ MR MU YT MX FM MD MC MN ME MS MA MZ MM NA NR NP NL AN NC NZ NI NE NG NU NF MP NO OM PK PW PS PA PG PY PE PH PN PL PT PR QA RE RO RU RW BL SH KN LC MF PM VC WS SM ST SA SN RS SC SL SG SK SI SB SO ZA GS ES LK SD SR SJ SZ SE CH SY TW TJ TZ TH TL TG TK TO TT TN TR TM TC TV UG UA AE GB US UM UY UZ VU VE VN VG VI WF EH YE ZM ZW)
13
-
14
12
  structures = { 'AT' => /^ATU\w{8}$/, 'BE' => /^BE0\d{9}$/, 'BG' => /^BG\d{9,10}$/, 'CY' => /^CY\w{8}L$/,
15
13
  'CZ' => /^CZ\d{8,10}$/, 'DE' => /^DE\d{9}$/, 'DK' => /^DK\d{2}\s\d{2}\s\d{2}\s\d{2}$/,
16
14
  'EE' => /^EE\d{9}$/, 'EL' => /^EL\d{9}$/, 'ES' => /^ESX\d{7}X$/, 'FI' => /^FI\d{8}$/, 'FR' => /^FR\w{2}\s\d{9}$/,
@@ -22,7 +20,7 @@ module Develon
22
20
 
23
21
  validates_each(attr_names,configuration) do |record, attr_name, value|
24
22
  country = country_code(value)
25
- if iso3661_country_codes.include?(country)
23
+ if structures.include?(country)
26
24
  message = configuration[:message] unless structures[country].match(value) && check_vat(country, value.gsub(/^\w\w/, ''))
27
25
  else
28
26
  message = 'has an invalid country'
@@ -17,10 +17,16 @@ describe Develon::ValidatesAsVatNumber do
17
17
  fake_company.valid?.should == false
18
18
  fake_company.errors.on('vat').should == 'is an invalid VAT number'
19
19
  end
20
+
21
+ it "should invalidate a non-supported iso3661 country code" do
22
+ fake_company = Company.new(:name => 'Fake Company', :vat => 'BO123456789')
23
+ fake_company.valid?.should == false
24
+ fake_company.errors.on('vat').should == 'has an invalid country'
25
+ end
20
26
 
21
27
  it "should invalidate locally if country is not valid" do
22
28
  develon = Company.new(:name => 'Develon', :vat => 'KO03018900245')
23
29
  develon.valid?.should == false
24
30
  develon.errors.on('vat').should == 'has an invalid country'
25
31
  end
26
- end
32
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_as_vat_number
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 3
9
+ version: 1.0.3
5
10
  platform: ruby
6
11
  authors:
7
12
  - Alessandro Dal Grande
@@ -10,19 +15,23 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-02-19 00:00:00 +01:00
18
+ date: 2010-03-01 00:00:00 +01:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: rspec
18
- type: :development
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 2
31
+ - 9
24
32
  version: 1.2.9
25
- version:
33
+ type: :development
34
+ version_requirements: *id001
26
35
  description: |-
27
36
  Now you can validate VAT using the European service called VIES,
28
37
  to ensure it exists. Only require this gem and call validate_as_vat_number
@@ -63,18 +72,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
72
  requirements:
64
73
  - - ">="
65
74
  - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
66
77
  version: "0"
67
- version:
68
78
  required_rubygems_version: !ruby/object:Gem::Requirement
69
79
  requirements:
70
80
  - - ">="
71
81
  - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
72
84
  version: "0"
73
- version:
74
85
  requirements: []
75
86
 
76
87
  rubyforge_project:
77
- rubygems_version: 1.3.5
88
+ rubygems_version: 1.3.6
78
89
  signing_key:
79
90
  specification_version: 3
80
91
  summary: Permits VAT validation within ActiveRecord using EU VIES Web Service.