validates_formatting_of 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -50,7 +50,7 @@ This call will ensure that the user-provided email is a valid email. This way, y
50
50
  validates_formatting_of :text, :using => :alphanum
51
51
  end
52
52
 
53
- ### Credit Card (Visa, Mastercard, Discver, and American Express)
53
+ ### Credit Card (Visa, Mastercard, Discover, and American Express)
54
54
 
55
55
  class Purchases < ActiveRecord::Base
56
56
  validates_formatting_of :cc, :using => :credit_card
@@ -73,7 +73,11 @@ This call will ensure that the user-provided email is a valid email. This way, y
73
73
  class Location < ActiveRecord::Base
74
74
  validates_formatting_of :website, :using => :url
75
75
  end
76
-
76
+ ### Social Security Number
77
+
78
+ class User < ActiveRecord::Base
79
+ validates_formatting_of :ssn, :using => :ssn
80
+ end
77
81
  # Customizable
78
82
 
79
83
  If, for any reason, you want to use your own regex instead of Rail's built-in methods, you can specify what you want to use with the `:regex` option. For example,
@@ -40,5 +40,10 @@ module ValidatesFormattingOf
40
40
  /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
41
41
  end
42
42
 
43
+ # Social Security Number pattern
44
+ def ssn
45
+ /^\d{3}([-.]){1}\d{2}([-.]){1}\d{4}$/
46
+ end
47
+
43
48
  end
44
49
  end
@@ -1,3 +1,3 @@
1
1
  module ValidatesFormattingOf
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -21,7 +21,7 @@ describe ValidatesFormattingOf::ModelAdditions do
21
21
  class Webpage < SuperModel::Base
22
22
  validates_formatting_of :url, :using => :url
23
23
  end
24
- it "validates that the email provided is valid" do
24
+ it "validates that the url provided is valid" do
25
25
  Webpage.new(:url => 'http://something.com').should be_valid
26
26
  Webpage.new(:url => "something else").should_not be_valid
27
27
  end
@@ -32,7 +32,7 @@ describe ValidatesFormattingOf::ModelAdditions do
32
32
  class USZip < SuperModel::Base
33
33
  validates_formatting_of :zipcode, :using => :us_zip
34
34
  end
35
- it "validates that the email provided is valid" do
35
+ it "validates that the zipcode provided is valid" do
36
36
  USZip.new(:zipcode => '92348').should be_valid
37
37
  USZip.new(:zipcode => '23434-2348').should be_valid
38
38
  USZip.new(:zipcode => '234').should_not be_valid
@@ -46,7 +46,7 @@ describe ValidatesFormattingOf::ModelAdditions do
46
46
  class Alpha < SuperModel::Base
47
47
  validates_formatting_of :letters, :using => :alpha
48
48
  end
49
- it "validates that the email provided is valid" do
49
+ it "validates that the letters provided is valid" do
50
50
  Alpha.new(:letters => 'abscdsofjsdpfahdsofkajlsdfaspdhjfads').should be_valid
51
51
  Alpha.new(:letters => 'asdfalskdfjhas-dlfhasdksdfaldhfadsfasdfa').should be_valid
52
52
  Alpha.new(:letters => 'adsufasodfksadjfskjdfha98').should_not be_valid
@@ -59,7 +59,7 @@ describe ValidatesFormattingOf::ModelAdditions do
59
59
  class Alphanum < SuperModel::Base
60
60
  validates_formatting_of :letters_and_numbers, :using => :alphanum
61
61
  end
62
- it "validates that the email provided is valid" do
62
+ it "validates that the letters provided is valid" do
63
63
  Alphanum.new(:letters_and_numbers => 'numbersandlettersarevalid1234567890').should be_valid
64
64
  Alphanum.new(:letters_and_numbers => 'justletters').should be_valid
65
65
  Alphanum.new(:letters_and_numbers => 'letters and numbers 123 with spaces').should be_valid
@@ -72,7 +72,7 @@ describe ValidatesFormattingOf::ModelAdditions do
72
72
  class USPhone < SuperModel::Base
73
73
  validates_formatting_of :phone_number, :using => :us_phone
74
74
  end
75
- it "validates that the email provided is valid" do
75
+ it "validates that the phone number provided is valid" do
76
76
  USPhone.new(:phone_number => '(234) 234-3456').should be_valid
77
77
  USPhone.new(:phone_number => '123 123 3456').should be_valid
78
78
  USPhone.new(:phone_number => '(223)123-2347').should be_valid
@@ -81,12 +81,12 @@ describe ValidatesFormattingOf::ModelAdditions do
81
81
  end
82
82
 
83
83
  end
84
- describe "us_phone" do
84
+ describe "ip_address" do
85
85
 
86
86
  class IPAddress < SuperModel::Base
87
87
  validates_formatting_of :ip, :using => :ip_address
88
88
  end
89
- it "validates that the email provided is valid" do
89
+ it "validates that the IP address provided is valid" do
90
90
  IPAddress.new(:ip => '10.10.10').should_not be_valid
91
91
  IPAddress.new(:ip => '999.10.10.20').should_not be_valid
92
92
  IPAddress.new(:ip => '2222.22.22.22').should_not be_valid
@@ -96,21 +96,6 @@ describe ValidatesFormattingOf::ModelAdditions do
96
96
  end
97
97
 
98
98
  end
99
- describe "us_phone" do
100
-
101
- class IPAddress < SuperModel::Base
102
- validates_formatting_of :ip, :using => :ip_address
103
- end
104
- it "validates that the email provided is valid" do
105
- IPAddress.new(:ip => '10.10.10').should_not be_valid
106
- IPAddress.new(:ip => '999.10.10.20').should_not be_valid
107
- IPAddress.new(:ip => '2222.22.22.22').should_not be_valid
108
- IPAddress.new(:ip => '22.2222.22.2').should_not be_valid
109
- IPAddress.new(:ip => '127.0.0.1').should be_valid
110
- IPAddress.new(:ip => '132.254.111.10').should be_valid
111
- end
112
-
113
- end
114
99
  # For clarification, NONE of the following numbers are real credit card numbers.
115
100
  # They only match the pattern. These were randomly made for testing.
116
101
  describe "credit_card" do
@@ -126,4 +111,17 @@ describe ValidatesFormattingOf::ModelAdditions do
126
111
  end
127
112
 
128
113
  end
114
+ describe "ssn" do
115
+ class AnotherPerson < SuperModel::Base
116
+ validates_formatting_of :ssn, :using => :ssn
117
+ end
118
+ it "validates that the social security number provided is valid" do
119
+ AnotherPerson.new(:ssn => "145.47.0191").should be_valid
120
+ AnotherPerson.new(:ssn => "223-43-2343").should be_valid
121
+ AnotherPerson.new(:ssn => "999.55.8888").should be_valid
122
+ AnotherPerson.new(:ssn => "28934").should_not be_valid
123
+ AnotherPerson.new(:ssn => "228934828934934").should_not be_valid
124
+ AnotherPerson.new(:ssn => "23498.7234").should_not be_valid
125
+ end
126
+ end
129
127
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_formatting_of
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70104641807780 !ruby/object:Gem::Requirement
16
+ requirement: &70275563895740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70104641807780
24
+ version_requirements: *70275563895740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70104641807320 !ruby/object:Gem::Requirement
27
+ requirement: &70275563895280 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70104641807320
35
+ version_requirements: *70275563895280
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: supermodel
38
- requirement: &70104641806840 !ruby/object:Gem::Requirement
38
+ requirement: &70275563894780 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70104641806840
46
+ version_requirements: *70275563894780
47
47
  description: Common Rails validations for different types of data
48
48
  email:
49
49
  - mbridges.91@gmail.com