validators 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +53 -44
- data/lib/validators/constants.rb +1 -1
- data/lib/validators/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/emails.rb +0 -15
- data/spec/validators/ip_spec.rb +3 -3
- data/spec/validators/validates_datetime_spec.rb +25 -25
- data/spec/validators/validates_email_format_of_spec.rb +26 -26
- data/spec/validators/validates_ip_address_spec.rb +18 -18
- data/spec/validators/validates_ownership_of_spec.rb +17 -17
- data/spec/validators/validates_url_format_of_spec.rb +12 -12
- data/validators.gemspec +1 -1
- metadata +38 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 712947e2a6947bc19c7da7bba7833e5ba9065d87
|
4
|
+
data.tar.gz: 10b12a9b882a88024a6d3c86f7344d0804c8979b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dba5cb7ea24051b776f0d6243be9a86316fafcb0daf21c3f078a56ece3cb74846105105c22f2320b94439d8d62893130fad767e0132af9b8c88245c2b7f7be29
|
7
|
+
data.tar.gz: 906ac8b658b4424c4bfb25636c5d4cdc088f272463b65e6fd1584e26533fdf20f62ac650975cc251f851cbcf633ab1d8f5602fbc671096d3d0d09187bba628bf
|
data/Gemfile.lock
CHANGED
@@ -1,67 +1,76 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
validators (2.
|
4
|
+
validators (2.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activemodel (4.0
|
10
|
-
activesupport (= 4.0
|
11
|
-
builder (~> 3.1
|
12
|
-
activerecord (4.0
|
13
|
-
activemodel (= 4.0
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
minitest (~> 4.2)
|
21
|
-
multi_json (~> 1.3)
|
9
|
+
activemodel (4.1.0)
|
10
|
+
activesupport (= 4.1.0)
|
11
|
+
builder (~> 3.1)
|
12
|
+
activerecord (4.1.0)
|
13
|
+
activemodel (= 4.1.0)
|
14
|
+
activesupport (= 4.1.0)
|
15
|
+
arel (~> 5.0.0)
|
16
|
+
activesupport (4.1.0)
|
17
|
+
i18n (~> 0.6, >= 0.6.9)
|
18
|
+
json (~> 1.7, >= 1.7.7)
|
19
|
+
minitest (~> 5.1)
|
22
20
|
thread_safe (~> 0.1)
|
23
|
-
tzinfo (~>
|
24
|
-
arel (
|
25
|
-
atomic (1.1.14)
|
21
|
+
tzinfo (~> 1.1)
|
22
|
+
arel (5.0.1.20140414130214)
|
26
23
|
awesome_print (1.2.0)
|
27
|
-
builder (3.
|
28
|
-
coderay (1.0
|
24
|
+
builder (3.2.2)
|
25
|
+
coderay (1.1.0)
|
26
|
+
columnize (0.8.9)
|
29
27
|
cpf_cnpj (0.2.0)
|
28
|
+
debugger (1.6.6)
|
29
|
+
columnize (>= 0.3.1)
|
30
|
+
debugger-linecache (~> 1.2.0)
|
31
|
+
debugger-ruby_core_source (~> 1.3.2)
|
32
|
+
debugger-linecache (1.2.0)
|
33
|
+
debugger-ruby_core_source (1.3.2)
|
30
34
|
diff-lcs (1.2.5)
|
31
|
-
i18n (0.6.
|
35
|
+
i18n (0.6.9)
|
36
|
+
json (1.8.1)
|
32
37
|
method_source (0.8.2)
|
33
|
-
minitest (
|
34
|
-
|
35
|
-
|
36
|
-
coderay (~> 1.0.5)
|
38
|
+
minitest (5.3.3)
|
39
|
+
pry (0.9.12.6)
|
40
|
+
coderay (~> 1.0)
|
37
41
|
method_source (~> 0.8)
|
38
42
|
slop (~> 3.4)
|
39
|
-
pry-
|
43
|
+
pry-debugger (0.2.2)
|
44
|
+
debugger (~> 1.3)
|
45
|
+
pry (~> 0.9.10)
|
46
|
+
pry-meta (0.0.6)
|
40
47
|
awesome_print
|
41
48
|
pry
|
42
|
-
pry-
|
49
|
+
pry-debugger
|
43
50
|
pry-remote
|
44
|
-
pry-
|
45
|
-
pry (~> 0.9.10)
|
46
|
-
pry-remote (0.1.7)
|
51
|
+
pry-remote (0.1.8)
|
47
52
|
pry (~> 0.9)
|
48
53
|
slop (~> 3.0)
|
49
|
-
rake (10.1
|
50
|
-
rspec (
|
51
|
-
rspec-core (
|
52
|
-
rspec-expectations (
|
53
|
-
rspec-mocks (
|
54
|
-
rspec-core (
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
rake (10.3.1)
|
55
|
+
rspec (3.0.0.beta2)
|
56
|
+
rspec-core (= 3.0.0.beta2)
|
57
|
+
rspec-expectations (= 3.0.0.beta2)
|
58
|
+
rspec-mocks (= 3.0.0.beta2)
|
59
|
+
rspec-core (3.0.0.beta2)
|
60
|
+
rspec-support (= 3.0.0.beta2)
|
61
|
+
rspec-expectations (3.0.0.beta2)
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
+
rspec-support (= 3.0.0.beta2)
|
64
|
+
rspec-mocks (3.0.0.beta2)
|
65
|
+
rspec-support (= 3.0.0.beta2)
|
66
|
+
rspec-support (3.0.0.beta2)
|
67
|
+
slop (3.5.0)
|
68
|
+
sqlite3 (1.3.9)
|
60
69
|
sqlite3-ruby (1.3.3)
|
61
70
|
sqlite3 (>= 1.3.3)
|
62
|
-
thread_safe (0.
|
63
|
-
|
64
|
-
|
71
|
+
thread_safe (0.3.3)
|
72
|
+
tzinfo (1.1.0)
|
73
|
+
thread_safe (~> 0.1)
|
65
74
|
|
66
75
|
PLATFORMS
|
67
76
|
ruby
|
@@ -71,6 +80,6 @@ DEPENDENCIES
|
|
71
80
|
cpf_cnpj
|
72
81
|
pry-meta
|
73
82
|
rake
|
74
|
-
rspec
|
83
|
+
rspec (= 3.0.0.beta2)
|
75
84
|
sqlite3-ruby
|
76
85
|
validators!
|
data/lib/validators/constants.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Validators
|
2
|
-
EMAIL_FORMAT = /\A([
|
2
|
+
EMAIL_FORMAT = /\A[a-z0-9]+([-._][a-z0-9]+)*(\+[^@]+)?@[a-z0-9]+([.-][a-z0-9]+)*\.[a-z]{2,4}\z/i
|
3
3
|
|
4
4
|
# Source: https://github.com/henrik/validates_url_format_of
|
5
5
|
IPv4_PART = /\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]/ # 0-255
|
data/lib/validators/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "bundler/setup"
|
2
|
-
Bundler.setup
|
3
2
|
|
4
3
|
require "active_record"
|
5
4
|
require "validators"
|
@@ -12,6 +11,7 @@ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
|
12
11
|
ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:"
|
13
12
|
load "schema.rb"
|
14
13
|
|
14
|
+
I18n.enforce_available_locales = false
|
15
15
|
I18n.load_path << File.dirname(__FILE__) + "/support/translations.yml"
|
16
16
|
|
17
17
|
RSpec.configure do |config|
|
data/spec/support/emails.rb
CHANGED
@@ -35,22 +35,7 @@ VALID_EMAILS = [
|
|
35
35
|
'valid@example.co.uk',
|
36
36
|
'v@example.com',
|
37
37
|
'valid@example.ca',
|
38
|
-
'valid_@example.com',
|
39
38
|
'valid123.456@example.org',
|
40
|
-
'valid123.456@example.travel',
|
41
|
-
'valid123.456@example.museum',
|
42
39
|
'valid@example.mobi',
|
43
40
|
'valid@example.info',
|
44
|
-
'valid-@example.com',
|
45
|
-
# from RFC 3696, page 6
|
46
|
-
'customer/department=shipping@example.com',
|
47
|
-
'$A12345@example.com',
|
48
|
-
'!def!xyz%abc@example.com',
|
49
|
-
'_somename@example.com',
|
50
|
-
# apostrophes
|
51
|
-
"test'test@example.com",
|
52
|
-
# '"Abc\@def"@example.com',
|
53
|
-
# from http://www.rfc-editor.org/errata_search.php?rfc=3696
|
54
|
-
# '"Fred\ Bloggs"@example.com',
|
55
|
-
'"Joe.\\Blow"@example.com'
|
56
41
|
]
|
data/spec/validators/ip_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe Validators::Ip do
|
|
4
4
|
context "IPv4" do
|
5
5
|
VALID_IPV4.each do |ip|
|
6
6
|
it "should accept #{ip.inspect} as ip address" do
|
7
|
-
Validators::Ip.
|
7
|
+
expect(Validators::Ip).to be_v4(ip)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -12,14 +12,14 @@ describe Validators::Ip do
|
|
12
12
|
context "IPv6" do
|
13
13
|
VALID_IPV6.each do |ip|
|
14
14
|
it "should accept #{ip.inspect} as ip address" do
|
15
|
-
Validators::Ip.
|
15
|
+
expect(Validators::Ip).to be_v6(ip)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
(VALID_IPV4 + VALID_IPV6).each do |ip|
|
21
21
|
it "should accept #{ip.inspect} as ip address" do
|
22
|
-
Validators::Ip.
|
22
|
+
expect(Validators::Ip).to be_valid(ip)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -14,7 +14,7 @@ describe ".validates_datetime" do
|
|
14
14
|
subject.registered_at = date
|
15
15
|
subject.birthday = date
|
16
16
|
|
17
|
-
subject.
|
17
|
+
expect(subject).to be_valid
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -22,18 +22,18 @@ describe ".validates_datetime" do
|
|
22
22
|
it "rejects #{date.inspect} as valid date" do
|
23
23
|
subject.registered_at = date
|
24
24
|
subject.birthday = date
|
25
|
-
subject.
|
25
|
+
expect(subject).not_to be_valid
|
26
26
|
|
27
|
-
subject.errors[:registered_at].
|
28
|
-
subject.errors[:birthday].
|
27
|
+
expect(subject.errors[:registered_at]).not_to be_empty
|
28
|
+
expect(subject.errors[:birthday]).not_to be_empty
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
it "includes default error message" do
|
33
33
|
subject.registered_at = nil
|
34
|
-
subject.
|
34
|
+
expect(subject).not_to be_valid
|
35
35
|
|
36
|
-
subject.errors[:registered_at].
|
36
|
+
expect(subject.errors[:registered_at]).to eq(["is not a valid date"])
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -42,47 +42,47 @@ describe ".validates_datetime" do
|
|
42
42
|
User.validates_datetime :registered_at, :after => 1.week.from_now
|
43
43
|
subject.registered_at = Time.now
|
44
44
|
|
45
|
-
subject.
|
46
|
-
subject.errors[:registered_at].
|
45
|
+
expect(subject).not_to be_valid
|
46
|
+
expect(subject.errors[:registered_at]).to eq(["needs to be after #{I18n.l(1.week.from_now)}"])
|
47
47
|
end
|
48
48
|
|
49
49
|
it "accepts when date is set accordingly to the :after option" do
|
50
50
|
User.validates_datetime :registered_at, :after => 1.week.from_now
|
51
51
|
subject.registered_at = 2.weeks.from_now
|
52
52
|
|
53
|
-
subject.
|
53
|
+
expect(subject).to be_valid
|
54
54
|
end
|
55
55
|
|
56
56
|
it "validates using today as date" do
|
57
57
|
User.validates_datetime :registered_at, :after => :today
|
58
58
|
|
59
59
|
subject.registered_at = Time.now
|
60
|
-
subject.
|
60
|
+
expect(subject).not_to be_valid
|
61
61
|
|
62
62
|
subject.registered_at = Date.today
|
63
|
-
subject.
|
63
|
+
expect(subject).not_to be_valid
|
64
64
|
|
65
65
|
subject.registered_at = Date.tomorrow
|
66
|
-
subject.
|
66
|
+
expect(subject).to be_valid
|
67
67
|
|
68
68
|
subject.registered_at = 1.day.from_now
|
69
|
-
subject.
|
69
|
+
expect(subject).to be_valid
|
70
70
|
end
|
71
71
|
|
72
72
|
it "validates using now as date" do
|
73
73
|
User.validates_datetime :registered_at, :after => :now
|
74
74
|
|
75
75
|
subject.registered_at = Time.now
|
76
|
-
subject.
|
76
|
+
expect(subject).not_to be_valid
|
77
77
|
|
78
78
|
subject.registered_at = Date.today
|
79
|
-
subject.
|
79
|
+
expect(subject).not_to be_valid
|
80
80
|
|
81
81
|
subject.registered_at = Date.tomorrow
|
82
|
-
subject.
|
82
|
+
expect(subject).to be_valid
|
83
83
|
|
84
84
|
subject.registered_at = 1.day.from_now
|
85
|
-
subject.
|
85
|
+
expect(subject).to be_valid
|
86
86
|
end
|
87
87
|
|
88
88
|
it "validates using method as date" do
|
@@ -91,17 +91,17 @@ describe ".validates_datetime" do
|
|
91
91
|
|
92
92
|
subject.starts_at = nil
|
93
93
|
subject.ends_at = Time.now
|
94
|
-
subject.
|
95
|
-
subject.errors[:ends_at].
|
94
|
+
expect(subject).not_to be_valid
|
95
|
+
expect(subject.errors[:ends_at]).to be_empty
|
96
96
|
|
97
97
|
subject.starts_at = Time.parse("Apr 26 2010")
|
98
98
|
subject.ends_at = Time.parse("Apr 25 2010")
|
99
|
-
subject.
|
100
|
-
subject.errors[:ends_at].
|
99
|
+
expect(subject).not_to be_valid
|
100
|
+
expect(subject.errors[:ends_at]).to eq(["needs to be after #{I18n.l(Time.parse("Apr 26 2010"))}"])
|
101
101
|
|
102
102
|
subject.starts_at = Time.now
|
103
103
|
subject.ends_at = 1.hour.from_now
|
104
|
-
subject.
|
104
|
+
expect(subject).to be_valid
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
@@ -110,15 +110,15 @@ describe ".validates_datetime" do
|
|
110
110
|
User.validates_datetime :registered_at, :before => 1.week.ago
|
111
111
|
subject.registered_at = Time.now
|
112
112
|
|
113
|
-
subject.
|
114
|
-
subject.errors[:registered_at].
|
113
|
+
expect(subject).not_to be_valid
|
114
|
+
expect(subject.errors[:registered_at]).to eq(["needs to be before #{I18n.l(1.week.ago)}"])
|
115
115
|
end
|
116
116
|
|
117
117
|
it "accepts when date is set accordingly to the :before option" do
|
118
118
|
User.validates_datetime :registered_at, :before => 1.week.ago
|
119
119
|
subject.registered_at = 2.weeks.ago
|
120
120
|
|
121
|
-
subject.
|
121
|
+
expect(subject).to be_valid
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
@@ -9,63 +9,63 @@ describe ".validates_email_format_of" do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
VALID_EMAILS.each do |email|
|
12
|
-
it "
|
12
|
+
it "accepts #{email.inspect} as a valid email" do
|
13
13
|
user = User.new(:email => email, :corporate_email => email)
|
14
|
-
user.
|
14
|
+
expect(user).to be_valid
|
15
15
|
|
16
16
|
user = Person.new(:email => email)
|
17
|
-
user.
|
17
|
+
expect(user).to be_valid
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
INVALID_EMAILS.each do |email|
|
22
|
-
it "
|
22
|
+
it "rejects #{email.inspect} as a valid email" do
|
23
23
|
user = User.new(:email => "invalid", :corporate_email => "invalid")
|
24
|
-
user.
|
24
|
+
expect(user).not_to be_valid
|
25
25
|
|
26
26
|
user = Person.new(:email => "invalid")
|
27
|
-
user.
|
27
|
+
expect(user).not_to be_valid
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
it "
|
31
|
+
it "uses default error message" do
|
32
32
|
user = User.new(:email => "invalid")
|
33
|
-
user.
|
34
|
-
user.errors[:email].
|
33
|
+
expect(user).not_to be_valid
|
34
|
+
expect(user.errors[:email]).to eq(["is not a valid address"])
|
35
35
|
end
|
36
36
|
|
37
|
-
it "
|
37
|
+
it "rejects nil value" do
|
38
38
|
user = User.new(:email => nil)
|
39
|
-
user.
|
40
|
-
user.errors[:email].
|
39
|
+
expect(user).not_to be_valid
|
40
|
+
expect(user.errors[:email]).not_to be_empty
|
41
41
|
end
|
42
42
|
|
43
|
-
it "
|
43
|
+
it "rejects empty value" do
|
44
44
|
user = User.new(:email => "")
|
45
|
-
user.
|
46
|
-
user.errors[:email].
|
45
|
+
expect(user).not_to be_valid
|
46
|
+
expect(user.errors[:email]).not_to be_empty
|
47
47
|
end
|
48
48
|
|
49
|
-
it "
|
49
|
+
it "validates multiple attributes" do
|
50
50
|
user = User.new(:corporate_email => "invalid")
|
51
|
-
user.
|
52
|
-
user.errors[:corporate_email].
|
51
|
+
expect(user).not_to be_valid
|
52
|
+
expect(user.errors[:corporate_email]).to eq(["is not a valid address"])
|
53
53
|
end
|
54
54
|
|
55
|
-
it "
|
55
|
+
it "uses custom error message as :message options" do
|
56
56
|
buyer = Buyer.new(:email => "invalid")
|
57
|
-
buyer.
|
58
|
-
buyer.errors[:email].
|
57
|
+
expect(buyer).not_to be_valid
|
58
|
+
expect(buyer.errors[:email]).to eq(["is not a valid e-mail"])
|
59
59
|
end
|
60
60
|
|
61
|
-
it "
|
61
|
+
it "uses I18n string as error message [pt-BR]" do
|
62
62
|
I18n.locale = :'pt-BR'
|
63
63
|
user = User.new(:email => "invalid")
|
64
|
-
user.
|
65
|
-
user.errors[:email].
|
64
|
+
expect(user).not_to be_valid
|
65
|
+
expect(user.errors[:email]).to eq(["não parece ser um e-mail válido"])
|
66
66
|
end
|
67
67
|
|
68
|
-
it "
|
69
|
-
User.
|
68
|
+
it "defines alias method" do
|
69
|
+
expect(User).to respond_to(:validates_email)
|
70
70
|
end
|
71
71
|
end
|
@@ -4,56 +4,56 @@ describe ".validates_ip_address" do
|
|
4
4
|
subject { User.new }
|
5
5
|
|
6
6
|
context "IPv4" do
|
7
|
-
it "
|
7
|
+
it "is valid" do
|
8
8
|
User.validates_ip_address :url, :only => :v4
|
9
9
|
subject.url = "192.168.1.2"
|
10
|
-
subject.
|
10
|
+
expect(subject).to be_valid
|
11
11
|
end
|
12
12
|
|
13
|
-
it "
|
13
|
+
it "is invalid" do
|
14
14
|
User.validates_ip_address :url, :only => :v4
|
15
15
|
subject.url = "FE80:0000:0000:0000:0202:B3FF:FE1E:8329"
|
16
|
-
subject.
|
17
|
-
subject.errors[:url].
|
16
|
+
expect(subject).not_to be_valid
|
17
|
+
expect(subject.errors[:url]).to eq(["is not a valid IPv4 address"])
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
context "IPv6" do
|
22
|
-
it "
|
22
|
+
it "is valid" do
|
23
23
|
User.validates_ip_address :url, :only => :v6
|
24
24
|
subject.url = "FE80:0000:0000:0000:0202:B3FF:FE1E:8329"
|
25
|
-
subject.
|
25
|
+
expect(subject).to be_valid
|
26
26
|
end
|
27
27
|
|
28
|
-
it "
|
28
|
+
it "is invalid" do
|
29
29
|
User.validates_ip_address :url, :only => :v6
|
30
30
|
subject.url = "192.168.1.2"
|
31
|
-
subject.
|
32
|
-
subject.errors[:url].
|
31
|
+
expect(subject).not_to be_valid
|
32
|
+
expect(subject.errors[:url]).to eq(["is not a valid IPv6 address"])
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
it "
|
36
|
+
it "is valid with IPv4" do
|
37
37
|
User.validates_ip_address :url
|
38
38
|
subject.url = "192.168.1.2"
|
39
|
-
subject.
|
39
|
+
expect(subject).to be_valid
|
40
40
|
end
|
41
41
|
|
42
|
-
it "
|
42
|
+
it "is valid with IPv6" do
|
43
43
|
User.validates_ip_address :url
|
44
44
|
subject.url = "FE80:0000:0000:0000:0202:B3FF:FE1E:8329"
|
45
|
-
subject.
|
45
|
+
expect(subject).to be_valid
|
46
46
|
end
|
47
47
|
|
48
|
-
it "
|
48
|
+
it "allows blank values" do
|
49
49
|
User.validates_ip_address :url, :allow_blank => true
|
50
50
|
subject.url = ""
|
51
|
-
subject.
|
51
|
+
expect(subject).to be_valid
|
52
52
|
end
|
53
53
|
|
54
|
-
it "
|
54
|
+
it "allows nil values" do
|
55
55
|
User.validates_ip_address :url, :allow_nil => true
|
56
56
|
subject.url = nil
|
57
|
-
subject.
|
57
|
+
expect(subject).to be_valid
|
58
58
|
end
|
59
59
|
end
|
@@ -11,59 +11,59 @@ describe ".validates_ownership_of" do
|
|
11
11
|
Task.validates_ownership_of :category, :with => :user
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
15
|
-
subject.
|
14
|
+
it "is valid when record is owned by the correct user" do
|
15
|
+
expect(subject).to be_valid
|
16
16
|
end
|
17
17
|
|
18
|
-
it "
|
18
|
+
it "is invalid when record is owned by a different user" do
|
19
19
|
subject.category = another_category
|
20
|
-
subject.
|
20
|
+
expect(subject).not_to be_valid
|
21
21
|
end
|
22
22
|
|
23
|
-
it "
|
23
|
+
it "raises error without :with option" do
|
24
24
|
expect {
|
25
25
|
Task.validates_ownership_of :category
|
26
26
|
}.to raise_error(ArgumentError)
|
27
27
|
end
|
28
28
|
|
29
|
-
it "
|
29
|
+
it "raises error when :with options is not a valid type" do
|
30
30
|
expect {
|
31
31
|
Task.validates_ownership_of :category, :with => user
|
32
32
|
}.to raise_error(ArgumentError)
|
33
33
|
end
|
34
34
|
|
35
|
-
it "
|
35
|
+
it "is invalid when owner is not present" do
|
36
36
|
expect {
|
37
37
|
subject.user = nil
|
38
|
-
subject.
|
38
|
+
expect(subject).not_to be_valid
|
39
39
|
}.to_not raise_error
|
40
40
|
end
|
41
41
|
|
42
|
-
it "
|
42
|
+
it "is invalid when attribute owner is not present" do
|
43
43
|
expect {
|
44
44
|
subject.category.user = nil
|
45
|
-
subject.
|
45
|
+
expect(subject).not_to be_valid
|
46
46
|
}.to_not raise_error
|
47
47
|
end
|
48
48
|
|
49
|
-
it "
|
49
|
+
it "is valid when both owners are nil" do
|
50
50
|
expect {
|
51
51
|
subject.category.user = nil
|
52
52
|
subject.user = nil
|
53
|
-
subject.
|
53
|
+
expect(subject).to be_valid
|
54
54
|
}.to_not raise_error
|
55
55
|
end
|
56
56
|
|
57
|
-
it "
|
57
|
+
it "is valid when attribute is nil" do
|
58
58
|
expect {
|
59
59
|
subject.category = nil
|
60
|
-
subject.
|
60
|
+
expect(subject).to be_valid
|
61
61
|
}.to_not raise_error
|
62
62
|
end
|
63
63
|
|
64
|
-
it "
|
64
|
+
it "sets error message" do
|
65
65
|
subject.user = nil
|
66
|
-
subject.
|
67
|
-
subject.errors[:category].
|
66
|
+
expect(subject).not_to be_valid
|
67
|
+
expect(subject.errors[:category]).to eq(["is not associated with your user"])
|
68
68
|
end
|
69
69
|
end
|
@@ -7,33 +7,33 @@ describe ".validates_url_format_of" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
VALID_URLS.each do |url|
|
10
|
-
it "
|
10
|
+
it "accepts #{url.inspect} as a valid url" do
|
11
11
|
user = User.new(:url => url)
|
12
|
-
user.
|
12
|
+
expect(user).to be_valid
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
INVALID_URLS.each do |url|
|
17
|
-
it "
|
17
|
+
it "rejects #{url.inspect} as a valid url" do
|
18
18
|
user = User.new(:url => url)
|
19
|
-
user.
|
19
|
+
expect(user).not_to be_valid
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
it "
|
24
|
-
User.
|
23
|
+
it "defines alias method" do
|
24
|
+
expect(User).to respond_to(:validates_url)
|
25
25
|
end
|
26
26
|
|
27
|
-
it "
|
27
|
+
it "uses default error message" do
|
28
28
|
user = User.new(:url => "invalid")
|
29
|
-
user.
|
30
|
-
user.errors[:url].
|
29
|
+
expect(user).not_to be_valid
|
30
|
+
expect(user.errors[:url]).to eq(["is not a valid address"])
|
31
31
|
end
|
32
32
|
|
33
|
-
it "
|
33
|
+
it "uses I18n string as error message [pt-BR]" do
|
34
34
|
I18n.locale = :'pt-BR'
|
35
35
|
user = User.new(:url => "invalid")
|
36
|
-
user.
|
37
|
-
user.errors[:url].
|
36
|
+
expect(user).not_to be_valid
|
37
|
+
expect(user.errors[:url]).to eq(["não parece ser uma URL válida"])
|
38
38
|
end
|
39
39
|
end
|
data/validators.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
19
|
s.add_development_dependency "activerecord", ">= 3.0"
|
20
|
-
s.add_development_dependency "rspec"
|
20
|
+
s.add_development_dependency "rspec", "3.0.0.beta2"
|
21
21
|
s.add_development_dependency "sqlite3-ruby"
|
22
22
|
s.add_development_dependency "rake"
|
23
23
|
s.add_development_dependency "pry-meta"
|
metadata
CHANGED
@@ -1,97 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - '
|
31
|
+
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.0.0.beta2
|
34
34
|
type: :development
|
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:
|
40
|
+
version: 3.0.0.beta2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sqlite3-ruby
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry-meta
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: cpf_cnpj
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
description: Add some nice ActiveRecord validators.
|
@@ -101,8 +101,8 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
-
- .gitignore
|
105
|
-
- .rspec
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
106
|
- Gemfile
|
107
107
|
- Gemfile.lock
|
108
108
|
- README.md
|
@@ -144,19 +144,34 @@ require_paths:
|
|
144
144
|
- lib
|
145
145
|
required_ruby_version: !ruby/object:Gem::Requirement
|
146
146
|
requirements:
|
147
|
-
- -
|
147
|
+
- - ">="
|
148
148
|
- !ruby/object:Gem::Version
|
149
149
|
version: '1.9'
|
150
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
|
-
- -
|
152
|
+
- - ">="
|
153
153
|
- !ruby/object:Gem::Version
|
154
154
|
version: '0'
|
155
155
|
requirements: []
|
156
156
|
rubyforge_project:
|
157
|
-
rubygems_version: 2.
|
157
|
+
rubygems_version: 2.2.2
|
158
158
|
signing_key:
|
159
159
|
specification_version: 4
|
160
160
|
summary: Add some nice ActiveRecord validators.
|
161
|
-
test_files:
|
162
|
-
|
161
|
+
test_files:
|
162
|
+
- spec/schema.rb
|
163
|
+
- spec/spec_helper.rb
|
164
|
+
- spec/support/dates.rb
|
165
|
+
- spec/support/emails.rb
|
166
|
+
- spec/support/ips.rb
|
167
|
+
- spec/support/models.rb
|
168
|
+
- spec/support/translations.yml
|
169
|
+
- spec/support/urls.rb
|
170
|
+
- spec/validators/ip_spec.rb
|
171
|
+
- spec/validators/validates_cnpj_format_of_spec.rb
|
172
|
+
- spec/validators/validates_cpf_format_of_spec.rb
|
173
|
+
- spec/validators/validates_datetime_spec.rb
|
174
|
+
- spec/validators/validates_email_format_of_spec.rb
|
175
|
+
- spec/validators/validates_ip_address_spec.rb
|
176
|
+
- spec/validators/validates_ownership_of_spec.rb
|
177
|
+
- spec/validators/validates_url_format_of_spec.rb
|