validates_formatting_of 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,6 @@ script: bundle exec rspec spec
2
2
  rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
- - rbx
6
- - jruby
7
- - ruby-head
5
+ - 2.0.0
6
+ - rbx-19mode
7
+ - jruby-19mode
@@ -1,3 +1,11 @@
1
+ ## v0.7.2
2
+
3
+ * Bugfix: Changed \Z to \z anchor and added some test assertions. Not valid with newline in some formats
4
+
5
+ ## v0.7.1
6
+
7
+ * Removed :ip_address ArgumentError. Already fails since it is missing
8
+
1
9
  ## v0.7.0
2
10
 
3
11
  * Removed :ip_address validation method
@@ -189,12 +189,12 @@ end
189
189
 
190
190
  # Development and Contribution
191
191
 
192
- To add a simple regex validation, all that is necessary is to add a single line to the `Method` module in the `lib/method.rb` file (with a line or two of documentation explaining it's use).
192
+ To add a simple regex validation, all that is necessary is to add a single line to the `ValidatesFormattingOf::Method` module in the `lib/method.rb` file (with a line or two of documentation explaining it's use).
193
193
 
194
194
  For example:
195
195
 
196
196
  ```ruby
197
- module Method
197
+ module ValidatesFormattingOf::Method
198
198
  # This :validation_name method is for example purposes only.
199
199
  # You can use this in production, but it would require a value of 'example regex' to pass.
200
200
  add :validation_name, %r{example regex}iux, "is a message for validation method :validation_name"
@@ -7,16 +7,16 @@ module ValidatesFormattingOf
7
7
  extend ValidationAddition
8
8
 
9
9
  # This method is very close to allowing what is specified in RFC 5322 and RFC 5321
10
- add :email, %r{\A([^@\s]+)@((?:(?!-)[-a-z0-9]+(?<!-)\.)+[a-z]{2,})\Z}i, "is not a valid email"
10
+ add :email, %r{\A([^@\s]+)@((?:(?!-)[-a-z0-9]+(?<!-)\.)+[a-z]{2,})\z}i, "is not a valid email"
11
11
 
12
12
  # Thie version of the email exists to support common validation libraries (such
13
13
  # as client_side_validations) that require access to Rails' validation. Look-behinds
14
14
  # are not supported in javascript.
15
- add :simple_email, %r{\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z}i, "is not a valid email"
15
+ add :simple_email, %r{\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z}i, "is not a valid email"
16
16
 
17
17
  # Taken from Ryan Bates' screencast on extracting gems. Works extremely well. Thanks Ryan!
18
18
  # (slightly revised to work on MRI 1.8.7 and ree)
19
- add :url, %r{\Ahttps?:\/\/([^\s:@]+:[^\s:@]*@)?[A-Za-z\d\-]+(\.[A-Za-z\d\-]+)+\.?(:\d{1,5})?([\/?]\S*)?\Z}i, "is not a valid URL"
19
+ add :url, %r{\Ahttps?:\/\/([^\s:@]+:[^\s:@]*@)?[A-Za-z\d\-]+(\.[A-Za-z\d\-]+)+\.?(:\d{1,5})?([\/?]\S*)?\z}i, "is not a valid URL"
20
20
 
21
21
  # No numbers of symbols. allows "-"
22
22
  add :alpha, %r{\A([^\d\W]|[-])*\Z}, "must be only letters or dashes"
@@ -25,10 +25,10 @@ module ValidatesFormattingOf
25
25
  add :alphanum, %r{\A[A-Z0-9\s]+\Z}i, "must be letters, numbers"
26
26
 
27
27
  # Visa, Mastercard, Discver, and American Express
28
- add :credit_card, %r{\A((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7]\d{13}\Z}, "is not a valid credit card number"
28
+ add :credit_card, %r{\A(((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7]\d{13})\z}, "is not a valid credit card number"
29
29
 
30
30
  # US Zip code. ##### or #####-####
31
- add :us_zip, %r{\A\d{5}(-\d{4})?\Z}, "is not a valid zipcode"
31
+ add :us_zip, %r{\A\d{5}(-\d{4})?\z}, "is not a valid zipcode"
32
32
 
33
33
  # US Phone numbers.
34
34
  # Examples of valid formats:
@@ -38,19 +38,19 @@ module ValidatesFormattingOf
38
38
  # * (###)###-####
39
39
  # * #########
40
40
  # * ### ###-####
41
- add :us_phone, %r{\A(\((\d{3})\)|\d{3})[ |\.|\-]?(\d{3})[ |\.|\-]?(\d{4})\Z}, "is not a valid phone number"
41
+ add :us_phone, %r{\A(\((\d{3})\)|\d{3})[ |\.|\-]?(\d{3})[ |\.|\-]?(\d{4})\z}, "is not a valid phone number"
42
42
 
43
43
  # IP Address validation
44
- add :ip_address_v4, %r{\A(\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])\Z}, "is not a valid IPv4 address"
44
+ add :ip_address_v4, %r{\A(\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])\z}, "is not a valid IPv4 address"
45
45
 
46
46
  # Social Security Number pattern
47
- add :ssn, %r{\A\d{3}([-.]){1}\d{2}([-.]){1}\d{4}\Z}, "is not a valid social security number"
47
+ add :ssn, %r{\A\d{3}([-.]){1}\d{2}([-.]){1}\d{4}\z}, "is not a valid social security number"
48
48
 
49
49
  # Matches CSS colors either in three or six digit formats
50
- add :hex_color, %r{\A([A-F0-9]{6}|[A-F0-9]{3})\Z}i, "is not a valid hex color"
50
+ add :hex_color, %r{\A([A-F0-9]{6}|[A-F0-9]{3})\z}i, "is not a valid hex color"
51
51
 
52
52
  # Ensures that what value is passed is a dollar amount of some kind
53
- add :dollars, %r{\A\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?\Z}, "is not a valid dollar amount"
53
+ add :dollars, %r{\A\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?\z}, "is not a valid dollar amount"
54
54
 
55
55
  end
56
56
  end
@@ -1,3 +1,3 @@
1
1
  module ValidatesFormattingOf
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
@@ -18,6 +18,7 @@ describe ValidatesFormattingOf::ModelAdditions do
18
18
  Email.new(:email => "info@-samoa.travel").should_not be_valid
19
19
  Email.new(:email => "info@samoa-.travel").should_not be_valid
20
20
  Email.new(:email => "info@123-samoa.travel").should be_valid
21
+ Email.new(:email => "info@123-samoa.travel\n").should_not be_valid
21
22
  end
22
23
  end
23
24
 
@@ -27,16 +28,17 @@ describe ValidatesFormattingOf::ModelAdditions do
27
28
  validates_formatting_of :email, :using => :simple_email
28
29
  end
29
30
  it "validates that the email provided is valid" do
30
- Email.new(:email => "example@example.com").should be_valid
31
- Email.new(:email => "badexample.com").should_not be_valid
32
- Email.new(:email => "mbridges.91@gmail.com").should be_valid
33
- Email.new(:email => "some-random%%%strangely-formatted-email@lots.of.subdomains.com").should be_valid
34
- Email.new(:email => "this__???{}|__should@be-valid.com").should be_valid
35
- Email.new(:email => "visitorservices@vmfa.museum").should be_valid
36
- Email.new(:email => "info@samoa.travel").should be_valid
37
- Email.new(:email => "info@-samoa.travel").should_not be_valid
38
- Email.new(:email => "info@samoa-.travel").should_not be_valid
39
- Email.new(:email => "info@123-samoa.travel").should be_valid
31
+ SimpleEmail.new(:email => "example@example.com").should be_valid
32
+ SimpleEmail.new(:email => "badexample.com").should_not be_valid
33
+ SimpleEmail.new(:email => "mbridges.91@gmail.com").should be_valid
34
+ SimpleEmail.new(:email => "some-random%%%strangely-formatted-email@lots.of.subdomains.com").should be_valid
35
+ SimpleEmail.new(:email => "this__???{}|__should@be-valid.com").should be_valid
36
+ SimpleEmail.new(:email => "visitorservices@vmfa.museum").should be_valid
37
+ SimpleEmail.new(:email => "info@samoa.travel").should be_valid
38
+ SimpleEmail.new(:email => "info@-samoa.travel").should be_valid
39
+ SimpleEmail.new(:email => "info@samoa-.travel").should be_valid
40
+ SimpleEmail.new(:email => "info@123-samoa.travel").should be_valid
41
+ SimpleEmail.new(:email => "info@123-samoa.travel\n").should_not be_valid
40
42
  end
41
43
  end
42
44
  describe "url" do
@@ -49,6 +51,7 @@ describe ValidatesFormattingOf::ModelAdditions do
49
51
  Webpage.new(:url => 'http://something-else.com').should be_valid
50
52
  Webpage.new(:url => 'http://sub.domains.something-else.com').should be_valid
51
53
  Webpage.new(:url => 'http://username:password@something-else.com').should be_valid
54
+ Webpage.new(:url => "http://username:password@something-else.com\n").should_not be_valid
52
55
  Webpage.new(:url => "something else").should_not be_valid
53
56
  end
54
57
  end
@@ -61,6 +64,7 @@ describe ValidatesFormattingOf::ModelAdditions do
61
64
  it "validates that the zipcode provided is valid" do
62
65
  USZip.new(:zipcode => '92348').should be_valid
63
66
  USZip.new(:zipcode => '23434-2348').should be_valid
67
+ USZip.new(:zipcode => "23434-2348\n").should_not be_valid
64
68
  USZip.new(:zipcode => '234').should_not be_valid
65
69
  USZip.new(:zipcode => '23408234').should_not be_valid
66
70
  USZip.new(:zipcode => 'invalid').should_not be_valid
@@ -104,6 +108,7 @@ describe ValidatesFormattingOf::ModelAdditions do
104
108
  USPhone.new(:phone_number => '1231233456').should be_valid
105
109
  USPhone.new(:phone_number => '123.123.3456').should be_valid
106
110
  USPhone.new(:phone_number => '(223)123-2347').should be_valid
111
+ USPhone.new(:phone_number => "(223)123-2347\n").should_not be_valid
107
112
  USPhone.new(:phone_number => '(223 123-2347').should_not be_valid
108
113
  USPhone.new(:phone_number => '12349870238').should_not be_valid
109
114
  end
@@ -121,6 +126,7 @@ describe ValidatesFormattingOf::ModelAdditions do
121
126
  IPAddress.new(:ipv4 => '22.2222.22.2').should_not be_valid
122
127
  IPAddress.new(:ipv4 => '127.0.0.1').should be_valid
123
128
  IPAddress.new(:ipv4 => '132.254.111.10').should be_valid
129
+ IPAddress.new(:ipv4 => "132.254.111.10\n").should_not be_valid
124
130
  end
125
131
  end
126
132
 
@@ -135,6 +141,7 @@ describe ValidatesFormattingOf::ModelAdditions do
135
141
  Client.new(:cc => '4264-2879-1230-0000').should be_valid # Visa style
136
142
  Client.new(:cc => '6011-1111-0000-2391').should be_valid # Discover style
137
143
  Client.new(:cc => '5422434400828888').should be_valid # Mastercard style
144
+ Client.new(:cc => "5422434400828889\n").should_not be_valid # Mastercard style
138
145
  Client.new(:cc => '1233444444444444').should_not be_valid # fake
139
146
  end
140
147
  end
@@ -148,6 +155,7 @@ describe ValidatesFormattingOf::ModelAdditions do
148
155
  AnotherPerson.new(:ssn => "145.47.0191").should be_valid
149
156
  AnotherPerson.new(:ssn => "223-43-2343").should be_valid
150
157
  AnotherPerson.new(:ssn => "999.55.8888").should be_valid
158
+ AnotherPerson.new(:ssn => "999.55.8888\n").should_not be_valid
151
159
  AnotherPerson.new(:ssn => "28934").should_not be_valid
152
160
  AnotherPerson.new(:ssn => "228934828934934").should_not be_valid
153
161
  AnotherPerson.new(:ssn => "23498.7234").should_not be_valid
@@ -165,6 +173,7 @@ describe ValidatesFormattingOf::ModelAdditions do
165
173
  Color.new(:color => "000011").should be_valid
166
174
  Color.new(:color => "132").should be_valid
167
175
  Color.new(:color => "eef").should be_valid
176
+ Color.new(:color => "eef\n").should_not be_valid
168
177
  Color.new(:color => "efefe").should_not be_valid
169
178
  Color.new(:color => "zsdfsd").should_not be_valid
170
179
  Color.new(:color => "p98hul;").should_not be_valid
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.7.1
4
+ version: 0.7.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-10 00:00:00.000000000 Z
12
+ date: 2013-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -132,4 +132,3 @@ test_files:
132
132
  - spec/validates_formatting_of/model_additions_spec.rb
133
133
  - spec/validates_formatting_of/validation_addition_spec.rb
134
134
  - spec/validates_formatting_of/validation_spec.rb
135
- has_rdoc: