missing_validators 0.8.2 → 0.8.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: 28a7af981a1a7fdb56740a472e9ece734cc2246d
4
- data.tar.gz: 76aa9c1a9ada749f079041f2f6fa8f09e09151ca
3
+ metadata.gz: c8965924e44993f7bfad6dcfd4a63917f544e417
4
+ data.tar.gz: 3a114c7b78f19d3384012dcefc5d7656514a5613
5
5
  SHA512:
6
- metadata.gz: 23ed45c14ba0c9339194e9e0ac9c143903dc07ef275fd8a59e54ce3e4787fa7054e3d99d5b655dc4b48ab5dfd3d442b0f5b3b6e7f56b91e1ce7807252c322a0d
7
- data.tar.gz: 57d9ac4dd04bc1a57f54139cad40a70fe8584aadd3a7674509e66c697c09775f646d0f436d4092a0a70f4987096f9a27e3f5d2fca004664c9eb1bb673f33b4a0
6
+ metadata.gz: 3a6b1635cb5c6980b98cca25389c6f1b1a903197684d20ee4adb1de3e50674c50749d3dab2619cc50d3b31e05e353e44ee3f8fe3fa2dd262617a8e69b0edfaf3
7
+ data.tar.gz: 455faa6aa3d3a22b9ed992dc6d2a6bf4e9e67aff8391eca21e3ea86da435d9d0e14777cffe1841ddada8f1112557d5cf4edb999a002340148e270ec3145799d8
@@ -21,12 +21,12 @@ class MacAddressValidator < ActiveModel::EachValidator
21
21
  end
22
22
 
23
23
  def self.validate_format(mac_address)
24
- !!(mac_address =~ /^([\h]{2}[:]){5}[\h]{2}?$/i) || # 08:00:2b:01:02:03
25
- !!(mac_address =~ /^([\h]{2}[-]){5}[\h]{2}?$/i) || # 08-00-2b-01-02-03
26
- !!(mac_address =~ /^([\h]{6}):[\h]{6}?$/i) || # 08002b:010203
27
- !!(mac_address =~ /^([\h]{6})-[\h]{6}?$/i) || # 08002b-010203
28
- !!(mac_address =~ /^([\h]{4}[\.]){2}[\h]{4}?$/i) || # 0800.2b01.0203
29
- !!(mac_address =~ /^[\h]{12}?$/i) # 08002b010203
24
+ !!(mac_address =~ /^([\h]{2}:){5}[\h]{2}?$/i) || # 08:00:2b:01:02:03
25
+ !!(mac_address =~ /^([\h]{2}[-|\.|\s]){5}[\h]{2}?$/i) || # 08-00-2b-01-02-03 or 08.00.2b.01.02.03
26
+ !!(mac_address =~ /^([\h]{6})[-|\.][\h]{6}?$/i) || # 08002b-010203 or 08002b.010203
27
+ !!(mac_address =~ /^([\h]{6}):[\h]{6}?$/i) || # 08002b:010203
28
+ !!(mac_address =~ /^([\h]{4}[-|\.|\s]){2}[\h]{4}?$/i) || # 0800.2b01.0203 or 0800-2b01-0203 0800 2b01 0203
29
+ !!(mac_address =~ /^[\h]{12}?$/i) # 08002b010203
30
30
  end
31
31
 
32
32
  private
@@ -1,5 +1,5 @@
1
1
  # Provides a collection of custom validators that are often required in Rails applications.
2
2
  module MissingValidators
3
3
  # Gem version.
4
- VERSION = "0.8.2"
4
+ VERSION = "0.8.3"
5
5
  end
@@ -1,4 +1,5 @@
1
1
  require 'active_model'
2
+ require 'rspec/matchers'
2
3
  require 'missing_validators/version'
3
4
  require 'missing_validators/validators/inequality_validator'
4
5
  require 'missing_validators/matchers/ensure_inequality_of_matcher' if defined?(RSpec)
@@ -15,18 +15,36 @@ describe MacAddressValidator do
15
15
  it { should ensure_valid_mac_address_format_of(:mac) }
16
16
  it { should_not ensure_valid_mac_address_format_of(:name) }
17
17
 
18
+ # Valid formats
18
19
  it { should allow_value("08:00:2b:01:02:03").for(:mac) }
19
20
  it { should allow_value("08-00-2b-01-02-03").for(:mac) }
21
+ it { should allow_value("08.00.2b.01.02.03").for(:mac) }
22
+ it { should allow_value("08 00 2b 01 02 03").for(:mac) }
20
23
  it { should allow_value("08002b:010203").for(:mac) }
24
+ it { should allow_value("08002b.010203").for(:mac) }
21
25
  it { should allow_value("08002b-010203").for(:mac) }
22
26
  it { should allow_value("0800.2b01.0203").for(:mac) }
27
+ it { should allow_value("0800-2b01-0203").for(:mac) }
28
+ it { should allow_value("0800 2b01 0203").for(:mac) }
23
29
  it { should allow_value("08002b010203").for(:mac) }
24
30
 
31
+ # Mixed Separators
32
+ it { should_not allow_value("08-00:2b:01:02:03").for(:mac) }
33
+ it { should_not allow_value("08.00:2b:01:02:03").for(:mac) }
34
+ it { should_not allow_value("08 00:2b:01:02:03").for(:mac) }
35
+ it { should_not allow_value("0800-2b01:0203").for(:mac) }
36
+ it { should_not allow_value("0800 2b01:0203").for(:mac) }
37
+
38
+ # Too Short
25
39
  it { should_not allow_value("08:00:2b:01:02").for(:mac) }
40
+ it { should_not allow_value("08-00-2b-01-02").for(:mac) }
41
+
42
+ # Too Long
26
43
  it { should_not allow_value("08:00:2b:01:02:03:04").for(:mac) }
44
+
45
+ # Non-Hex Characters
27
46
  it { should_not allow_value("qq:00:00:00:00:00").for(:mac) }
28
47
 
29
- it { should_not allow_value("08-00-2b-01-02").for(:mac) }
30
48
 
31
49
  it { should_not allow_value("invalid").for(:mac) }
32
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: missing_validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Gridnev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-26 00:00:00.000000000 Z
11
+ date: 2014-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec