rails_validations 1.3 → 1.4.1

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: 951d63d5356bcdf895cef31ec5726e049079bc7a
4
- data.tar.gz: bbfbf7c0b5e64858ad78723f1990d205aa40918b
3
+ metadata.gz: 8bec571f7a49e06d0474ab65d15f2e6313daae4d
4
+ data.tar.gz: 5e1e0f575fc60fc008966542af827038e1592e14
5
5
  SHA512:
6
- metadata.gz: 563d7dfa6e1f2cc9035a7c3b761f8b86a08f452b63ccc8725442f7d6abd7c60a4dc5ca28ff4f5ca2abacbf488fb0098bdae3b1bc42e41c1d6627a6f232e06449
7
- data.tar.gz: 09f588a7881780926db041f19f4e8edce501cc1c8d12cc878f06f7bcb087f620a5502820d6eb0734c2440a1590994f85ccf63683ddeb63502cea17c4c4110330
6
+ metadata.gz: 0238a93909c34d8b8ad6707bbb3abb834c5aaaf89b01cf2fa02d1cf21f6b531fd52f2ceda0686e0f4c2506163e3bdb4f942df3ec18a63ad97314548574241256
7
+ data.tar.gz: f2d3c0499d7f7f5f7ef74094a5b9706db0463a15ab13dcbc3ce2646d1c11144e2e97f57f71940f2199001afb581c9c09623e368d578fc64fc77194b1bae4f75a
data/README.markdown CHANGED
@@ -4,7 +4,8 @@
4
4
  [![Inline docs](http://inch-ci.org/github/bluerail/rails_validations.svg?branch=master)](http://inch-ci.org/github/bluerail/rails_validations)
5
5
 
6
6
 
7
- A few extra validations for Ruby on Rails.
7
+ A few extra validations for Ruby on Rails. Works with Ruby 1.9 and newer, and
8
+ Rails 3 and newer (including Rails 4).
8
9
 
9
10
  We try to do the sane thing by not being too strict, when in doubt, we accept
10
11
  input as being valid. We never want to reject valid input as invalid.
@@ -141,6 +142,11 @@ Currently implemented countries:
141
142
  ChangeLog
142
143
  =========
143
144
 
145
+ Version 1.4, 2015-08-11
146
+ -----------------------
147
+ - Make it work with Ruby 1.9 and Rails 3.0
148
+
149
+
144
150
  Version 1.3, 2015-05-22
145
151
  -----------------------
146
152
  - Add `commerce_number` validation.
@@ -1,5 +1,8 @@
1
1
  en:
2
2
  rails_validations:
3
+ postal_code:
4
+ invalid: not a valid postal code
5
+
3
6
  email:
4
7
  invalid: not a valid email address
5
8
 
@@ -1,5 +1,8 @@
1
1
  nl:
2
2
  rails_validations:
3
+ postal_code:
4
+ invalid: geen geldige postcode
5
+
3
6
  email:
4
7
  invalid: geen geldig e-mailaddress
5
8
 
@@ -3,7 +3,7 @@ class CommerceNumberValidator < ActiveModel::EachValidator
3
3
  # keys are ISO-3366-1 alpha2
4
4
  REGEXP = {
5
5
  # KvK nummer; 8 digits. Allow space, -, and . for formatting
6
- nl: -> (v) { v.gsub(/[.\- ]/, '') =~ /\A\d{8}\z/ },
6
+ nl: ->(v) { v.gsub(/[.\- ]/, '') =~ /\A\d{8}\z/ },
7
7
  }.freeze
8
8
 
9
9
 
@@ -34,11 +34,15 @@ class DateValidator < ActiveModel::EachValidator
34
34
  elsif raw_value.respond_to? :to_date
35
35
  begin
36
36
  raw_value.to_date
37
- rescue ArgumentError
37
+ rescue
38
38
  false
39
39
  end
40
40
  else
41
- false
41
+ begin
42
+ Date.parse raw_value
43
+ rescue
44
+ false
45
+ end
42
46
  end
43
47
  end
44
48
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+ #
1
3
  # Validate if a string is a valid domain. This should work with IDN.
2
4
  #
3
5
  # validates :domain_column, domain: true
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+ #
1
3
  # Validate email, also works with UTF-8/IDN.
2
4
  #
3
5
  # The validation is intentionally simply, you can never be sure an email is
@@ -6,7 +6,7 @@ class VatNumberValidator < ActiveModel::EachValidator
6
6
  # 'NL' + 9 digits + B + 2-digit company index – e.g. NL999999999B99
7
7
  # Allow space, -, and . for formatting
8
8
  # TODO: I think this also has a check digit?
9
- nl: -> (v) { v.upcase.gsub(/[.\- ]/, '') =~ /\ANL\d{9}B\d{2}\z/ },
9
+ nl: ->(v) { v.upcase.gsub(/[.\- ]/, '') =~ /\ANL\d{9}B\d{2}\z/ },
10
10
  }.freeze
11
11
 
12
12
 
data/spec/spec_helper.rb CHANGED
@@ -59,7 +59,10 @@ module ValidationsSpecHelper
59
59
 
60
60
 
61
61
  def with_validation validate_string
62
- described_class.clear_validators!
62
+ #Rails 4: described_class.clear_validators!
63
+ described_class.reset_callbacks(:validate)
64
+ described_class._validators.clear
65
+
63
66
  described_class.class_eval "validates :v, #{validate_string}"
64
67
 
65
68
  yield
@@ -75,7 +78,7 @@ RSpec::Matchers.define :be_invalid do |i18n_key, i18n_params={}|
75
78
  match do |record|
76
79
  record.valid? == false &&
77
80
  record.errors.first.present? &&
78
- record.errors.first[1] == I18n.t("rails_validations.#{i18n_key}", **i18n_params)
81
+ record.errors.first[1] == I18n.t("rails_validations.#{i18n_key}", i18n_params)
79
82
  end
80
83
  end
81
84
 
@@ -77,4 +77,25 @@ describe ValidationsSpecHelper::Date do
77
77
  expect(model(Date.today.to_s, (Date.today - 2.days).to_s)).to be_valid
78
78
  end
79
79
  end
80
+
81
+ it 'works when giving a string' do
82
+ with_validation 'date: true' do
83
+ [
84
+ '2015-01-01',
85
+ '01-09-2015',
86
+ ].each do |str|
87
+ expect(model(str)).to be_valid
88
+ end
89
+ end
90
+ end
91
+
92
+ it "sets an errors when a string isn't quite a valid date" do
93
+ with_validation 'date: true' do
94
+ [
95
+ '6-2015',
96
+ ].each do |str|
97
+ expect(model(str)).to be_invalid('date.invalid')
98
+ end
99
+ end
100
+ end
80
101
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module ValidationsSpecHelper
@@ -38,7 +40,7 @@ describe ValidationsSpecHelper::Domain do
38
40
  end
39
41
  end
40
42
 
41
-
43
+
42
44
  it 'works with :max_domain_parts' do
43
45
  with_validation 'domain: { max_domain_parts: 3 }' do
44
46
  expect(model('not.many')).to be_valid
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module ValidationsSpecHelper
@@ -16,6 +16,7 @@ describe ValidationsSpecHelper::Iban do
16
16
  %w{
17
17
  NL65AEGO0721647952
18
18
  NL43ABNA0841376913
19
+ NL29INGB0006303043
19
20
  }.each do |v|
20
21
  expect(model(v)).to be_valid
21
22
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.3'
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Tournoij
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-22 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">"
32
32
  - !ruby/object:Gem::Version
33
- version: '4.0'
33
+ version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">"
39
39
  - !ruby/object:Gem::Version
40
- version: '4.0'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: iban-tools
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
- version: '2.0'
112
+ version: '1.9'
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="