yukonisuru 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +14 -0
- data/.rspec +4 -0
- data/.travis.yml +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +1101 -0
- data/Rakefile +1 -0
- data/config/locales/en.yml +113 -0
- data/lib/yukonisuru.rb +93 -0
- data/lib/yukonisuru/matchers/ensure_valid_alpha_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_alpha_numeric_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_base64_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_boolean_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_credit_card_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_currency_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_cusip_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_email_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_equality_matcher_of.rb +40 -0
- data/lib/yukonisuru/matchers/ensure_valid_gtin_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_hex_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_imei_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_ip_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_isbn_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_isin_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_latitude_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_longitude_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_mac_address_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_name_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_password_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_phone_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_sedol_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_slug_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_ssn_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_url_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_username_format_of.rb +26 -0
- data/lib/yukonisuru/matchers/ensure_valid_uuid_format_of.rb +26 -0
- data/lib/yukonisuru/validators/alpha_numeric_validator.rb +31 -0
- data/lib/yukonisuru/validators/alpha_validator.rb +31 -0
- data/lib/yukonisuru/validators/base64_validator.rb +9 -0
- data/lib/yukonisuru/validators/boolean_validator.rb +9 -0
- data/lib/yukonisuru/validators/credit_card_validator.rb +133 -0
- data/lib/yukonisuru/validators/currency_validator.rb +23 -0
- data/lib/yukonisuru/validators/cusip_validator.rb +33 -0
- data/lib/yukonisuru/validators/email_validator.rb +25 -0
- data/lib/yukonisuru/validators/equality_validator.rb +27 -0
- data/lib/yukonisuru/validators/gtin_validator.rb +59 -0
- data/lib/yukonisuru/validators/hex_validator.rb +9 -0
- data/lib/yukonisuru/validators/imei_validator.rb +37 -0
- data/lib/yukonisuru/validators/ip_validator.rb +9 -0
- data/lib/yukonisuru/validators/isbn_validator.rb +24 -0
- data/lib/yukonisuru/validators/isin_validator.rb +38 -0
- data/lib/yukonisuru/validators/latitude_validator.rb +9 -0
- data/lib/yukonisuru/validators/longitude_validator.rb +9 -0
- data/lib/yukonisuru/validators/mac_address_validator.rb +24 -0
- data/lib/yukonisuru/validators/name_validator.rb +9 -0
- data/lib/yukonisuru/validators/password_validator.rb +23 -0
- data/lib/yukonisuru/validators/phone_validator.rb +9 -0
- data/lib/yukonisuru/validators/sedol_validator.rb +32 -0
- data/lib/yukonisuru/validators/slug_validator.rb +9 -0
- data/lib/yukonisuru/validators/ssn_validator.rb +9 -0
- data/lib/yukonisuru/validators/url_validator.rb +36 -0
- data/lib/yukonisuru/validators/username_validator.rb +9 -0
- data/lib/yukonisuru/validators/uuid_validator.rb +28 -0
- data/lib/yukonisuru/version.rb +3 -0
- data/spec/lib/alpha_numeric_validator_spec.rb +91 -0
- data/spec/lib/alpha_validator_spec.rb +182 -0
- data/spec/lib/base64_validator_spec.rb +33 -0
- data/spec/lib/boolean_validator_spec.rb +35 -0
- data/spec/lib/credit_card_validator_spec.rb +686 -0
- data/spec/lib/currency_validator_spec.rb +63 -0
- data/spec/lib/cusip_validator_spec.rb +27 -0
- data/spec/lib/email_validator_spec.rb +109 -0
- data/spec/lib/equality_validator_spec.rb +334 -0
- data/spec/lib/gtin_validator_spec.rb +101 -0
- data/spec/lib/hex_validator_spec.rb +73 -0
- data/spec/lib/imei_validator_spec.rb +41 -0
- data/spec/lib/ip_validator_spec.rb +33 -0
- data/spec/lib/isbn_validator_spec.rb +41 -0
- data/spec/lib/isin_validator_spec.rb +35 -0
- data/spec/lib/latitude_validator_spec.rb +31 -0
- data/spec/lib/longitude_validator_spec.rb +31 -0
- data/spec/lib/mac_address_validator_spec.rb +54 -0
- data/spec/lib/name_validator_spec.rb +39 -0
- data/spec/lib/password_validator_spec.rb +87 -0
- data/spec/lib/phone_validator_spec.rb +42 -0
- data/spec/lib/sedol_validator_spec.rb +31 -0
- data/spec/lib/slug_validator_spec.rb +41 -0
- data/spec/lib/ssn_validator_spec.rb +36 -0
- data/spec/lib/url_validator_spec.rb +109 -0
- data/spec/lib/username_validator_spec.rb +37 -0
- data/spec/lib/uuid_validator_spec.rb +157 -0
- data/spec/spec_helper.rb +12 -0
- data/yukonisuru.gemspec +29 -0
- metadata +264 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NameValidator do
|
4
|
+
|
5
|
+
context "has a valid value" do
|
6
|
+
let(:klass) do
|
7
|
+
Class.new do
|
8
|
+
include ActiveModel::Validations
|
9
|
+
attr_accessor :name, :email
|
10
|
+
validates :name, name: true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { klass.new }
|
15
|
+
|
16
|
+
it { should allow_value("First Last").for(:name) }
|
17
|
+
it { should allow_value("First Last-Name").for(:name) }
|
18
|
+
it { should allow_value("First Middle Last").for(:name) }
|
19
|
+
it { should allow_value("Sur First Middle Last").for(:name) }
|
20
|
+
it { should allow_value("Sur First Middle Last Family").for(:name) }
|
21
|
+
it { should allow_value("Sur First Middle Last-Family").for(:name) }
|
22
|
+
|
23
|
+
it { should_not allow_value('').for(:name) }
|
24
|
+
it { should_not allow_value(' ').for(:name) }
|
25
|
+
it { should_not allow_value(nil).for(:name) }
|
26
|
+
it { should_not allow_value("First").for(:name) }
|
27
|
+
it { should_not allow_value("First Last_Name").for(:name) }
|
28
|
+
it { should_not allow_value("First1 Last").for(:name) }
|
29
|
+
it { should_not allow_value("First 1 Last").for(:name) }
|
30
|
+
it { should_not allow_value("Sur. First Middle Last Jr.").for(:name) }
|
31
|
+
it { should_not allow_value("Sur First Middle Last Family III").for(:name) }
|
32
|
+
it { should_not allow_value("! \#$%\`|").for(:name) }
|
33
|
+
it { should_not allow_value("<>@[]\`|").for(:name) }
|
34
|
+
|
35
|
+
it { should ensure_valid_name_format_of(:name) }
|
36
|
+
it { should_not ensure_valid_name_format_of(:email) }
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PasswordValidator do
|
4
|
+
|
5
|
+
context "has a valid value" do
|
6
|
+
let(:klass) do
|
7
|
+
Class.new do
|
8
|
+
include ActiveModel::Validations
|
9
|
+
attr_accessor :password, :name
|
10
|
+
validates :password, password: true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { klass.new }
|
15
|
+
|
16
|
+
it { should allow_value("password").for(:password) }
|
17
|
+
it { should allow_value("password1234").for(:password) }
|
18
|
+
it { should allow_value("pa$$word").for(:password) }
|
19
|
+
it { should allow_value("pass-word").for(:password) }
|
20
|
+
it { should allow_value("pass_word").for(:password) }
|
21
|
+
it { should allow_value("password!").for(:password) }
|
22
|
+
it { should allow_value("password@").for(:password) }
|
23
|
+
it { should allow_value("password#").for(:password) }
|
24
|
+
it { should allow_value("password%").for(:password) }
|
25
|
+
it { should allow_value("password^").for(:password) }
|
26
|
+
it { should allow_value("password&").for(:password) }
|
27
|
+
it { should allow_value("password*").for(:password) }
|
28
|
+
|
29
|
+
it { should_not allow_value('').for(:password) }
|
30
|
+
it { should_not allow_value(' ').for(:password) }
|
31
|
+
it { should_not allow_value(nil).for(:password) }
|
32
|
+
it { should_not allow_value("pass").for(:password) }
|
33
|
+
it { should_not allow_value(" password").for(:password) }
|
34
|
+
it { should_not allow_value(" password ").for(:password) }
|
35
|
+
it { should_not allow_value("password ").for(:password) }
|
36
|
+
it { should_not allow_value("pass word").for(:password) }
|
37
|
+
it { should_not allow_value("password-12345678910").for(:password) }
|
38
|
+
it { should_not allow_value("! \#$%\`|").for(:password) }
|
39
|
+
it { should_not allow_value("<>@[]\`|").for(:password) }
|
40
|
+
|
41
|
+
it { should ensure_valid_password_format_of(:password) }
|
42
|
+
it { should_not ensure_valid_password_format_of(:name) }
|
43
|
+
end
|
44
|
+
|
45
|
+
context "Password with :strict option has a valid value" do
|
46
|
+
let(:klass) do
|
47
|
+
Class.new do
|
48
|
+
include ActiveModel::Validations
|
49
|
+
attr_accessor :password, :name
|
50
|
+
validates :password, password: { strict: true }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
subject { klass.new }
|
55
|
+
|
56
|
+
it { should allow_value("Password123").for(:password) }
|
57
|
+
it { should allow_value("Password-123").for(:password) }
|
58
|
+
|
59
|
+
it { should_not allow_value('').for(:password) }
|
60
|
+
it { should_not allow_value(' ').for(:password) }
|
61
|
+
it { should_not allow_value(nil).for(:password) }
|
62
|
+
it { should_not allow_value("pass").for(:password) }
|
63
|
+
it { should_not allow_value(" password").for(:password) }
|
64
|
+
it { should_not allow_value(" password ").for(:password) }
|
65
|
+
it { should_not allow_value("password ").for(:password) }
|
66
|
+
it { should_not allow_value("pass word").for(:password) }
|
67
|
+
it { should_not allow_value("password-12345678910").for(:password) }
|
68
|
+
it { should_not allow_value("password").for(:password) }
|
69
|
+
it { should_not allow_value("password1234").for(:password) }
|
70
|
+
it { should_not allow_value("pa$$word").for(:password) }
|
71
|
+
it { should_not allow_value("pass-word").for(:password) }
|
72
|
+
it { should_not allow_value("pass_word").for(:password) }
|
73
|
+
it { should_not allow_value("password!").for(:password) }
|
74
|
+
it { should_not allow_value("password@").for(:password) }
|
75
|
+
it { should_not allow_value("password#").for(:password) }
|
76
|
+
it { should_not allow_value("password%").for(:password) }
|
77
|
+
it { should_not allow_value("password^").for(:password) }
|
78
|
+
it { should_not allow_value("password&").for(:password) }
|
79
|
+
it { should_not allow_value("password*").for(:password) }
|
80
|
+
it { should_not allow_value("! \#$%\`|").for(:password) }
|
81
|
+
it { should_not allow_value("<>@[]\`|").for(:password) }
|
82
|
+
|
83
|
+
it { should ensure_valid_password_format_of(:password) }
|
84
|
+
it { should_not ensure_valid_password_format_of(:name) }
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PhoneValidator do
|
4
|
+
|
5
|
+
context "has a valid value" do
|
6
|
+
let(:klass) do
|
7
|
+
Class.new do
|
8
|
+
include ActiveModel::Validations
|
9
|
+
attr_accessor :phone, :name
|
10
|
+
validates :phone, phone: true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { klass.new }
|
15
|
+
|
16
|
+
it { should allow_value("1234567").for(:phone) }
|
17
|
+
it { should allow_value("123-4567").for(:phone) }
|
18
|
+
it { should allow_value("123 4567").for(:phone) }
|
19
|
+
it { should allow_value("5551234567").for(:phone) }
|
20
|
+
it { should allow_value("555-123-4567").for(:phone) }
|
21
|
+
it { should allow_value("555 123 4567").for(:phone) }
|
22
|
+
it { should allow_value("(555) 123-4567").for(:phone) }
|
23
|
+
it { should allow_value("(555) 123-4567 ext 1234").for(:phone) }
|
24
|
+
it { should allow_value("(555) 123-4567 ext1234").for(:phone) }
|
25
|
+
it { should allow_value("(555) 123-4567 ext-1234").for(:phone) }
|
26
|
+
it { should allow_value("1-555-123-4567").for(:phone) }
|
27
|
+
it { should allow_value("+1-555-123-4567").for(:phone) }
|
28
|
+
it { should allow_value("+1 (555) 123-4567 ext-1234").for(:phone) }
|
29
|
+
|
30
|
+
it { should_not allow_value('').for(:phone) }
|
31
|
+
it { should_not allow_value(nil).for(:phone) }
|
32
|
+
it { should_not allow_value("123_4567").for(:phone) }
|
33
|
+
it { should_not allow_value("(555) 123-4567 ext:1234").for(:phone) }
|
34
|
+
it { should_not allow_value("(555) 123-4567 ext_1234").for(:phone) }
|
35
|
+
it { should_not allow_value("! \#$%\`|").for(:phone) }
|
36
|
+
it { should_not allow_value("<>@[]\`|").for(:phone) }
|
37
|
+
|
38
|
+
it { should ensure_valid_phone_format_of(:phone) }
|
39
|
+
it { should_not ensure_valid_phone_format_of(:name) }
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SedolValidator do
|
4
|
+
|
5
|
+
context "has a valid value" do
|
6
|
+
let(:klass) do
|
7
|
+
Class.new do
|
8
|
+
include ActiveModel::Validations
|
9
|
+
attr_accessor :sedol, :name
|
10
|
+
validates :sedol, sedol: true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { klass.new }
|
15
|
+
|
16
|
+
it { should allow_value("B0WNLY7").for(:sedol) }
|
17
|
+
|
18
|
+
it { should_not allow_value('').for(:sedol) }
|
19
|
+
it { should_not allow_value(' ').for(:sedol) }
|
20
|
+
it { should_not allow_value(nil).for(:sedol) }
|
21
|
+
it { should_not allow_value("B0WNL").for(:sedol) }
|
22
|
+
it { should_not allow_value("B0WNLY").for(:sedol) }
|
23
|
+
it { should_not allow_value("B0WNLY77").for(:sedol) }
|
24
|
+
it { should_not allow_value("! \#$%\`|").for(:sedol) }
|
25
|
+
it { should_not allow_value("<>@[]\`|").for(:sedol) }
|
26
|
+
|
27
|
+
it { should ensure_valid_sedol_format_of(:sedol) }
|
28
|
+
it { should_not ensure_valid_sedol_format_of(:name) }
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SlugValidator do
|
4
|
+
|
5
|
+
context "has a valid value" do
|
6
|
+
let(:klass) do
|
7
|
+
Class.new do
|
8
|
+
include ActiveModel::Validations
|
9
|
+
attr_accessor :slug, :name
|
10
|
+
validates :slug, slug: true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { klass.new }
|
15
|
+
|
16
|
+
it { should allow_value("slug").for(:slug) }
|
17
|
+
it { should allow_value("slug1234").for(:slug) }
|
18
|
+
it { should allow_value("slug-word").for(:slug) }
|
19
|
+
it { should allow_value("slug-1234").for(:slug) }
|
20
|
+
|
21
|
+
it { should_not allow_value('').for(:slug) }
|
22
|
+
it { should_not allow_value(' ').for(:slug) }
|
23
|
+
it { should_not allow_value(nil).for(:slug) }
|
24
|
+
it { should_not allow_value(" slug").for(:slug) }
|
25
|
+
it { should_not allow_value(" slug ").for(:slug) }
|
26
|
+
it { should_not allow_value("slug ").for(:slug) }
|
27
|
+
it { should_not allow_value(" 1234").for(:slug) }
|
28
|
+
it { should_not allow_value(" 1234 ").for(:slug) }
|
29
|
+
it { should_not allow_value("1234 ").for(:slug) }
|
30
|
+
it { should_not allow_value("slug word").for(:slug) }
|
31
|
+
it { should_not allow_value("slug 1234").for(:slug) }
|
32
|
+
it { should_not allow_value("slug_word").for(:slug) }
|
33
|
+
it { should_not allow_value("slug_1234").for(:slug) }
|
34
|
+
it { should_not allow_value("! \#$%\`|").for(:slug) }
|
35
|
+
it { should_not allow_value("<>@[]\`|").for(:slug) }
|
36
|
+
|
37
|
+
it { should ensure_valid_slug_format_of(:slug) }
|
38
|
+
it { should_not ensure_valid_slug_format_of(:name) }
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SsnValidator do
|
4
|
+
|
5
|
+
context "has a valid value" do
|
6
|
+
let(:klass) do
|
7
|
+
Class.new do
|
8
|
+
include ActiveModel::Validations
|
9
|
+
attr_accessor :ssn, :name
|
10
|
+
validates :ssn, ssn: true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { klass.new }
|
15
|
+
|
16
|
+
it { should allow_value("333-22-4444").for(:ssn) }
|
17
|
+
it { should allow_value("333224444").for(:ssn) }
|
18
|
+
|
19
|
+
it { should_not allow_value('').for(:ssn) }
|
20
|
+
it { should_not allow_value(' ').for(:ssn) }
|
21
|
+
it { should_not allow_value(nil).for(:ssn) }
|
22
|
+
it { should_not allow_value(" 333-22-4444").for(:ssn) }
|
23
|
+
it { should_not allow_value(" 333-22-4444 ").for(:ssn) }
|
24
|
+
it { should_not allow_value("333-22-4444 ").for(:ssn) }
|
25
|
+
it { should_not allow_value("333 22 4444").for(:ssn) }
|
26
|
+
it { should_not allow_value("333-22-444n").for(:ssn) }
|
27
|
+
it { should_not allow_value("333 22 4444").for(:ssn) }
|
28
|
+
it { should_not allow_value("3-2-4").for(:ssn) }
|
29
|
+
it { should_not allow_value("! \#$%\`|").for(:ssn) }
|
30
|
+
it { should_not allow_value("<>@[]\`|").for(:ssn) }
|
31
|
+
|
32
|
+
it { should ensure_valid_ssn_format_of(:ssn) }
|
33
|
+
it { should_not ensure_valid_ssn_format_of(:name) }
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UrlValidator do
|
4
|
+
|
5
|
+
context "has valid format" do
|
6
|
+
let(:klass) do
|
7
|
+
Class.new do
|
8
|
+
include ActiveModel::Validations
|
9
|
+
attr_accessor :url, :name
|
10
|
+
validates :url, url: true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { klass.new }
|
15
|
+
|
16
|
+
it { should ensure_valid_url_format_of(:url) }
|
17
|
+
it { should_not ensure_valid_url_format_of(:name) }
|
18
|
+
|
19
|
+
it { should allow_value("http://example.com").for(:url) }
|
20
|
+
it { should allow_value("http://FooBar.cOm").for(:url) }
|
21
|
+
it { should allow_value("http://foo.bar.baz.com").for(:url) }
|
22
|
+
it { should allow_value("http://123.com").for(:url) }
|
23
|
+
it { should allow_value("http://www.example.ru").for(:url) }
|
24
|
+
it { should allow_value("http://user-example.co.uk").for(:url) }
|
25
|
+
it { should allow_value("https://example.com").for(:url) }
|
26
|
+
it { should allow_value("http://example.org/").for(:url) }
|
27
|
+
it { should allow_value("https://example.net/index.html").for(:url) }
|
28
|
+
it { should allow_value("http://example.net/login.php").for(:url) }
|
29
|
+
it { should allow_value("https://example.travel/").for(:url) }
|
30
|
+
it { should allow_value("http://example.aero").for(:url) }
|
31
|
+
it { should allow_value("http://example.aero?foo=bar").for(:url) }
|
32
|
+
|
33
|
+
it { should_not allow_value('').for(:url) }
|
34
|
+
it { should_not allow_value(' ').for(:url) }
|
35
|
+
it { should_not allow_value(nil).for(:url) }
|
36
|
+
it { should_not allow_value("example").for(:url) }
|
37
|
+
it { should_not allow_value("http://user_examplecom").for(:url) }
|
38
|
+
it { should_not allow_value("http://user_example.com").for(:url) }
|
39
|
+
it { should_not allow_value("http://user_example.a").for(:url) }
|
40
|
+
it { should_not allow_value("ftp://foo.bar.baz.com").for(:url) }
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "url must be in a specific domain" do
|
44
|
+
let(:klass) do
|
45
|
+
Class.new do
|
46
|
+
include ActiveModel::Validations
|
47
|
+
attr_accessor :url1, :url2
|
48
|
+
validates :url1, url: { domain: :org }
|
49
|
+
validates :url2, url: { domain: [:org, 'edu', 'Com.Au'] }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
subject { klass.new }
|
54
|
+
|
55
|
+
it { should allow_value("http://example.org").for(:url1) }
|
56
|
+
it { should_not allow_value("http://example.com").for(:url1) }
|
57
|
+
|
58
|
+
it { should allow_value("http://example.org").for(:url2) }
|
59
|
+
it { should allow_value("http://example.edu").for(:url2) }
|
60
|
+
it { should allow_value("http://example.com.au").for(:url2) }
|
61
|
+
it { should allow_value("http://example.Com.Au").for(:url2) }
|
62
|
+
it { should_not allow_value("http://example.com").for(:url2) }
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "url must be domain root" do
|
66
|
+
let(:klass) do
|
67
|
+
Class.new do
|
68
|
+
include ActiveModel::Validations
|
69
|
+
attr_accessor :url1, :url2
|
70
|
+
validates :url1, url: { root: true }
|
71
|
+
validates :url2, url: { root: false }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
subject { klass.new }
|
76
|
+
|
77
|
+
it { should allow_value("http://example.org").for(:url1) }
|
78
|
+
it { should allow_value("http://example.org/").for(:url1) }
|
79
|
+
it { should_not allow_value("http://example.com/test").for(:url1) }
|
80
|
+
it { should_not allow_value("http://example.com/#fragment").for(:url1) }
|
81
|
+
it { should_not allow_value("http://example.com/?key=value").for(:url1) }
|
82
|
+
|
83
|
+
|
84
|
+
it { should allow_value("http://example.org").for(:url2) }
|
85
|
+
it { should allow_value("http://example.org/lorem").for(:url2) }
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "url must have a specific scheme" do
|
89
|
+
let(:klass) do
|
90
|
+
Class.new do
|
91
|
+
include ActiveModel::Validations
|
92
|
+
attr_accessor :url1, :url2
|
93
|
+
validates :url1, url: { scheme: 'http' }
|
94
|
+
validates :url2, url: { scheme: ['HTTP', :https] }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
subject { klass.new }
|
99
|
+
|
100
|
+
it { should allow_value("http://example.org").for(:url1) }
|
101
|
+
it { should_not allow_value("https://example.org").for(:url1) }
|
102
|
+
|
103
|
+
it { should allow_value("http://example.org").for(:url2) }
|
104
|
+
it { should allow_value("https://example.org").for(:url2) }
|
105
|
+
it { should allow_value("HTTPS://example.org").for(:url2) }
|
106
|
+
it { should_not allow_value("ftp://example.org").for(:url2) }
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UsernameValidator do
|
4
|
+
|
5
|
+
context "has a valid value" do
|
6
|
+
let(:klass) do
|
7
|
+
Class.new do
|
8
|
+
include ActiveModel::Validations
|
9
|
+
attr_accessor :username, :name
|
10
|
+
validates :username, username: true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { klass.new }
|
15
|
+
|
16
|
+
it { should allow_value("username").for(:username) }
|
17
|
+
it { should allow_value("username123").for(:username) }
|
18
|
+
it { should allow_value("username_123").for(:username) }
|
19
|
+
it { should allow_value("username-123").for(:username) }
|
20
|
+
|
21
|
+
it { should_not allow_value('').for(:username) }
|
22
|
+
it { should_not allow_value(' ').for(:username) }
|
23
|
+
it { should_not allow_value(nil).for(:username) }
|
24
|
+
it { should_not allow_value("u").for(:username) }
|
25
|
+
it { should_not allow_value(" username").for(:username) }
|
26
|
+
it { should_not allow_value(" username ").for(:username) }
|
27
|
+
it { should_not allow_value("username ").for(:username) }
|
28
|
+
it { should_not allow_value("user name").for(:username) }
|
29
|
+
it { should_not allow_value("username-123456789").for(:username) }
|
30
|
+
it { should_not allow_value("! \#$%\`|").for(:username) }
|
31
|
+
it { should_not allow_value("<>@[]\`|").for(:username) }
|
32
|
+
|
33
|
+
it { should ensure_valid_username_format_of(:username) }
|
34
|
+
it { should_not ensure_valid_username_format_of(:name) }
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UuidValidator do
|
4
|
+
|
5
|
+
context "has a valid value" do
|
6
|
+
let(:klass) do
|
7
|
+
Class.new do
|
8
|
+
include ActiveModel::Validations
|
9
|
+
attr_accessor :uuid, :name
|
10
|
+
validates :uuid, uuid: true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { klass.new }
|
15
|
+
|
16
|
+
it { should allow_value("6fa459ea-ee8a-3ca4-894e-db77e160355e").for(:uuid) }
|
17
|
+
it { should allow_value("16fd2706-8baf-433b-82eb-8c7fada847da").for(:uuid) }
|
18
|
+
it { should allow_value("886313e1-3b8a-5372-9b90-0c9aee199e5d").for(:uuid) }
|
19
|
+
it { should allow_value("a8098c1a-f86e-11da-bd1a-00112444be1e").for(:uuid) }
|
20
|
+
|
21
|
+
it { should_not allow_value('').for(:uuid) }
|
22
|
+
it { should_not allow_value(' ').for(:uuid) }
|
23
|
+
it { should_not allow_value(nil).for(:uuid) }
|
24
|
+
it { should_not allow_value("6fa459ea-ee8a-3ca4-894e-db77e160355e1").for(:uuid) }
|
25
|
+
it { should_not allow_value("16fd2706-8baf-433b-82eb-8c7fada847da1").for(:uuid) }
|
26
|
+
it { should_not allow_value("886313e1-3b8a-5372-9b90-0c9aee199e5d1").for(:uuid) }
|
27
|
+
it { should_not allow_value("a8098c1a-f86e-11da-bd1a-00112444be1e1").for(:uuid) }
|
28
|
+
it { should_not allow_value("6fa459ea-ee8a-3ca4-894e-db77e160355").for(:uuid) }
|
29
|
+
it { should_not allow_value("16fd2706-8baf-433b-82eb-8c7fada847d").for(:uuid) }
|
30
|
+
it { should_not allow_value("886313e1-3b8a-5372-9b90-0c9aee199e5").for(:uuid) }
|
31
|
+
it { should_not allow_value("a8098c1a-f86e-11da-bd1a-00112444be1").for(:uuid) }
|
32
|
+
it { should_not allow_value("6fa459eaee8a3ca4894edb77e160355e").for(:uuid) }
|
33
|
+
it { should_not allow_value("16fd27068baf433b82eb8c7fada847da").for(:uuid) }
|
34
|
+
it { should_not allow_value("886313e13b8a53729b900c9aee199e5d").for(:uuid) }
|
35
|
+
it { should_not allow_value("a8098c1af86e11dabd1a00112444be1e").for(:uuid) }
|
36
|
+
it { should_not allow_value("! \#$%\`|").for(:uuid) }
|
37
|
+
it { should_not allow_value("<>@[]\`|").for(:uuid) }
|
38
|
+
|
39
|
+
it { should ensure_valid_uuid_format_of(:uuid) }
|
40
|
+
it { should_not ensure_valid_uuid_format_of(:name) }
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with version: 3 option has a valid value" do
|
44
|
+
let(:klass) do
|
45
|
+
Class.new do
|
46
|
+
include ActiveModel::Validations
|
47
|
+
attr_accessor :uuid, :name
|
48
|
+
validates :uuid, uuid: { version: 3 }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
subject { klass.new }
|
53
|
+
|
54
|
+
it { should allow_value("6fa459ea-ee8a-3ca4-894e-db77e160355e").for(:uuid) }
|
55
|
+
|
56
|
+
it { should_not allow_value('').for(:uuid) }
|
57
|
+
it { should_not allow_value(' ').for(:uuid) }
|
58
|
+
it { should_not allow_value(nil).for(:uuid) }
|
59
|
+
it { should_not allow_value("16fd2706-8baf-433b-82eb-8c7fada847da").for(:uuid) }
|
60
|
+
it { should_not allow_value("886313e1-3b8a-5372-9b90-0c9aee199e5d").for(:uuid) }
|
61
|
+
it { should_not allow_value("a8098c1a-f86e-11da-bd1a-00112444be1e").for(:uuid) }
|
62
|
+
it { should_not allow_value("6fa459ea-ee8a-3ca4-894e-db77e160355e1").for(:uuid) }
|
63
|
+
it { should_not allow_value("16fd2706-8baf-433b-82eb-8c7fada847da1").for(:uuid) }
|
64
|
+
it { should_not allow_value("886313e1-3b8a-5372-9b90-0c9aee199e5d1").for(:uuid) }
|
65
|
+
it { should_not allow_value("a8098c1a-f86e-11da-bd1a-00112444be1e1").for(:uuid) }
|
66
|
+
it { should_not allow_value("6fa459ea-ee8a-3ca4-894e-db77e160355").for(:uuid) }
|
67
|
+
it { should_not allow_value("16fd2706-8baf-433b-82eb-8c7fada847d").for(:uuid) }
|
68
|
+
it { should_not allow_value("886313e1-3b8a-5372-9b90-0c9aee199e5").for(:uuid) }
|
69
|
+
it { should_not allow_value("a8098c1a-f86e-11da-bd1a-00112444be1").for(:uuid) }
|
70
|
+
it { should_not allow_value("6fa459eaee8a3ca4894edb77e160355e").for(:uuid) }
|
71
|
+
it { should_not allow_value("16fd27068baf433b82eb8c7fada847da").for(:uuid) }
|
72
|
+
it { should_not allow_value("886313e13b8a53729b900c9aee199e5d").for(:uuid) }
|
73
|
+
it { should_not allow_value("a8098c1af86e11dabd1a00112444be1e").for(:uuid) }
|
74
|
+
it { should_not allow_value("! \#$%\`|").for(:uuid) }
|
75
|
+
it { should_not allow_value("<>@[]\`|").for(:uuid) }
|
76
|
+
|
77
|
+
it { should ensure_valid_uuid_format_of(:uuid) }
|
78
|
+
it { should_not ensure_valid_uuid_format_of(:name) }
|
79
|
+
end
|
80
|
+
|
81
|
+
context "with version: 4 option has a valid value" do
|
82
|
+
let(:klass) do
|
83
|
+
Class.new do
|
84
|
+
include ActiveModel::Validations
|
85
|
+
attr_accessor :uuid, :name
|
86
|
+
validates :uuid, uuid: { version: 4 }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
subject { klass.new }
|
91
|
+
|
92
|
+
it { should allow_value("16fd2706-8baf-433b-82eb-8c7fada847da").for(:uuid) }
|
93
|
+
|
94
|
+
it { should_not allow_value('').for(:uuid) }
|
95
|
+
it { should_not allow_value(' ').for(:uuid) }
|
96
|
+
it { should_not allow_value(nil).for(:uuid) }
|
97
|
+
it { should_not allow_value("6fa459ea-ee8a-3ca4-894e-db77e160355e").for(:uuid) }
|
98
|
+
it { should_not allow_value("886313e1-3b8a-5372-9b90-0c9aee199e5d").for(:uuid) }
|
99
|
+
it { should_not allow_value("a8098c1a-f86e-11da-bd1a-00112444be1e").for(:uuid) }
|
100
|
+
it { should_not allow_value("6fa459ea-ee8a-3ca4-894e-db77e160355e1").for(:uuid) }
|
101
|
+
it { should_not allow_value("16fd2706-8baf-433b-82eb-8c7fada847da1").for(:uuid) }
|
102
|
+
it { should_not allow_value("886313e1-3b8a-5372-9b90-0c9aee199e5d1").for(:uuid) }
|
103
|
+
it { should_not allow_value("a8098c1a-f86e-11da-bd1a-00112444be1e1").for(:uuid) }
|
104
|
+
it { should_not allow_value("6fa459ea-ee8a-3ca4-894e-db77e160355").for(:uuid) }
|
105
|
+
it { should_not allow_value("16fd2706-8baf-433b-82eb-8c7fada847d").for(:uuid) }
|
106
|
+
it { should_not allow_value("886313e1-3b8a-5372-9b90-0c9aee199e5").for(:uuid) }
|
107
|
+
it { should_not allow_value("a8098c1a-f86e-11da-bd1a-00112444be1").for(:uuid) }
|
108
|
+
it { should_not allow_value("6fa459eaee8a3ca4894edb77e160355e").for(:uuid) }
|
109
|
+
it { should_not allow_value("16fd27068baf433b82eb8c7fada847da").for(:uuid) }
|
110
|
+
it { should_not allow_value("886313e13b8a53729b900c9aee199e5d").for(:uuid) }
|
111
|
+
it { should_not allow_value("a8098c1af86e11dabd1a00112444be1e").for(:uuid) }
|
112
|
+
it { should_not allow_value("! \#$%\`|").for(:uuid) }
|
113
|
+
it { should_not allow_value("<>@[]\`|").for(:uuid) }
|
114
|
+
|
115
|
+
it { should ensure_valid_uuid_format_of(:uuid) }
|
116
|
+
it { should_not ensure_valid_uuid_format_of(:name) }
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with version: 5 option has a valid value" do
|
120
|
+
let(:klass) do
|
121
|
+
Class.new do
|
122
|
+
include ActiveModel::Validations
|
123
|
+
attr_accessor :uuid, :name
|
124
|
+
validates :uuid, uuid: { version: 5 }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
subject { klass.new }
|
129
|
+
|
130
|
+
it { should allow_value("886313e1-3b8a-5372-9b90-0c9aee199e5d").for(:uuid) }
|
131
|
+
|
132
|
+
it { should_not allow_value('').for(:uuid) }
|
133
|
+
it { should_not allow_value(' ').for(:uuid) }
|
134
|
+
it { should_not allow_value(nil).for(:uuid) }
|
135
|
+
it { should_not allow_value("6fa459ea-ee8a-3ca4-894e-db77e160355e").for(:uuid) }
|
136
|
+
it { should_not allow_value("16fd2706-8baf-433b-82eb-8c7fada847da").for(:uuid) }
|
137
|
+
it { should_not allow_value("a8098c1a-f86e-11da-bd1a-00112444be1e").for(:uuid) }
|
138
|
+
it { should_not allow_value("6fa459ea-ee8a-3ca4-894e-db77e160355e1").for(:uuid) }
|
139
|
+
it { should_not allow_value("16fd2706-8baf-433b-82eb-8c7fada847da1").for(:uuid) }
|
140
|
+
it { should_not allow_value("886313e1-3b8a-5372-9b90-0c9aee199e5d1").for(:uuid) }
|
141
|
+
it { should_not allow_value("a8098c1a-f86e-11da-bd1a-00112444be1e1").for(:uuid) }
|
142
|
+
it { should_not allow_value("6fa459ea-ee8a-3ca4-894e-db77e160355").for(:uuid) }
|
143
|
+
it { should_not allow_value("16fd2706-8baf-433b-82eb-8c7fada847d").for(:uuid) }
|
144
|
+
it { should_not allow_value("886313e1-3b8a-5372-9b90-0c9aee199e5").for(:uuid) }
|
145
|
+
it { should_not allow_value("a8098c1a-f86e-11da-bd1a-00112444be1").for(:uuid) }
|
146
|
+
it { should_not allow_value("6fa459eaee8a3ca4894edb77e160355e").for(:uuid) }
|
147
|
+
it { should_not allow_value("16fd27068baf433b82eb8c7fada847da").for(:uuid) }
|
148
|
+
it { should_not allow_value("886313e13b8a53729b900c9aee199e5d").for(:uuid) }
|
149
|
+
it { should_not allow_value("a8098c1af86e11dabd1a00112444be1e").for(:uuid) }
|
150
|
+
it { should_not allow_value("! \#$%\`|").for(:uuid) }
|
151
|
+
it { should_not allow_value("<>@[]\`|").for(:uuid) }
|
152
|
+
|
153
|
+
it { should ensure_valid_uuid_format_of(:uuid) }
|
154
|
+
it { should_not ensure_valid_uuid_format_of(:name) }
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|