validatious 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -0
- data/lib/validatious/helper_methods.rb +4 -0
- data/lib/validatious/locale/en.yml +2 -1
- data/lib/validatious/validators/email_validator.rb +19 -0
- data/lib/validatious/version.rb +1 -1
- data/lib/validatious.rb +1 -0
- data/spec/support/models/topic.rb +13 -0
- data/spec/validatious/helper_methods_spec.rb +1 -0
- data/spec/validatious/validators/email_validator_spec.rb +34 -0
- data/spec/validatious/validators/{url_spec.rb → url_validator_spec.rb} +0 -0
- metadata +9 -4
data/README.md
CHANGED
@@ -53,6 +53,18 @@ correct format of a URL.
|
|
53
53
|
or
|
54
54
|
|
55
55
|
validates_url_format_of :url
|
56
|
+
|
57
|
+
|
58
|
+
### Email
|
59
|
+
|
60
|
+
This validates the format of an email address, ensuring that the attribute conforms
|
61
|
+
to the correct format of an email address.
|
62
|
+
|
63
|
+
validates :email, :email => true
|
64
|
+
|
65
|
+
or
|
66
|
+
|
67
|
+
validates_email_format_of :email
|
56
68
|
|
57
69
|
|
58
70
|
## CONTRIBUTE
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Validatious
|
2
|
+
module Validators
|
3
|
+
|
4
|
+
# == Active Model Email Validator
|
5
|
+
class EmailValidator < ActiveModel::EachValidator
|
6
|
+
SPECIALCHARS = Regexp.escape('!#$%&\'*-/=?+-^_`{|}~')
|
7
|
+
PARTUNQUOTED = '(([[:alnum:]' + SPECIALCHARS + ']+[\.\+]+))*[[:alnum:]' + SPECIALCHARS + '+]+'
|
8
|
+
PARTQUOTED = '\"(([[:alnum:]' + SPECIALCHARS + '\.\+]*|(\\\\[\u0001-\uFFFF]))*)\"'
|
9
|
+
REGEX = Regexp.new('^((' + PARTUNQUOTED + ')|(' + PARTQUOTED + ')+)@(((\w+\-+)|(\w+\.))*\w{1,63}\.[a-z]{2,6}$)', Regexp::EXTENDED | Regexp::IGNORECASE)
|
10
|
+
|
11
|
+
def validate_each(record, attribute, value)
|
12
|
+
record.errors.add(attribute, :invalid_email, options) if value.to_s !~ REGEX
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Compatibility with ActiveModel validates method which matches option keys to their validator class
|
19
|
+
ActiveModel::Validations::EmailValidator = Validatious::Validators::EmailValidator
|
data/lib/validatious/version.rb
CHANGED
data/lib/validatious.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Validatious::Validators::EmailValidator do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
Topic.validates_email_format_of(:email)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:topic) { post = Topic.new(:title => "The title", :email => "invalid email") }
|
12
|
+
|
13
|
+
[
|
14
|
+
'bob@bones.com',
|
15
|
+
'bob.bones@bones.com'
|
16
|
+
].each do |email|
|
17
|
+
describe email.inspect do
|
18
|
+
it "should be valid" do
|
19
|
+
topic.email = email
|
20
|
+
topic.should be_valid
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
[nil, 1, "", " ", "email"].each do |email|
|
26
|
+
describe email.inspect do
|
27
|
+
it "should not be valid" do
|
28
|
+
topic.email = email
|
29
|
+
topic.should_not be_valid
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: validatious
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Joel Moss
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-29 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -54,13 +54,16 @@ files:
|
|
54
54
|
- lib/validatious.rb
|
55
55
|
- lib/validatious/helper_methods.rb
|
56
56
|
- lib/validatious/locale/en.yml
|
57
|
+
- lib/validatious/validators/email_validator.rb
|
57
58
|
- lib/validatious/validators/url_validator.rb
|
58
59
|
- lib/validatious/version.rb
|
59
60
|
- spec/spec_helper.rb
|
60
61
|
- spec/support/deferred_garbage_collection.rb
|
61
62
|
- spec/support/models/post.rb
|
63
|
+
- spec/support/models/topic.rb
|
62
64
|
- spec/validatious/helper_methods_spec.rb
|
63
|
-
- spec/validatious/validators/
|
65
|
+
- spec/validatious/validators/email_validator_spec.rb
|
66
|
+
- spec/validatious/validators/url_validator_spec.rb
|
64
67
|
- validatious.gemspec
|
65
68
|
has_rdoc: true
|
66
69
|
homepage: https://github.com/joelmoss/validatious
|
@@ -94,5 +97,7 @@ test_files:
|
|
94
97
|
- spec/spec_helper.rb
|
95
98
|
- spec/support/deferred_garbage_collection.rb
|
96
99
|
- spec/support/models/post.rb
|
100
|
+
- spec/support/models/topic.rb
|
97
101
|
- spec/validatious/helper_methods_spec.rb
|
98
|
-
- spec/validatious/validators/
|
102
|
+
- spec/validatious/validators/email_validator_spec.rb
|
103
|
+
- spec/validatious/validators/url_validator_spec.rb
|