omg_validator 0.0.6.2 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.yardoc/checksums +15 -15
- data/.yardoc/objects/root.dat +0 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +25 -25
- data/doc/OmgValidator.html +6 -4
- data/doc/OmgValidator/Validators.html +6 -4
- data/doc/OmgValidator/Validators/AlphaDashValidator.html +14 -10
- data/doc/OmgValidator/Validators/AlphaNumericValidator.html +14 -10
- data/doc/OmgValidator/Validators/AlphaValidator.html +14 -10
- data/doc/OmgValidator/Validators/DateValidator.html +5 -5
- data/doc/OmgValidator/Validators/DecimalValidator.html +13 -10
- data/doc/OmgValidator/Validators/EmailValidator.html +15 -11
- data/doc/OmgValidator/Validators/IntegerValidator.html +14 -10
- data/doc/OmgValidator/Validators/IpAddressValidator.html +15 -11
- data/doc/OmgValidator/Validators/NumericValidator.html +13 -10
- data/doc/OmgValidator/Validators/PhoneNumberValidator.html +15 -11
- data/doc/OmgValidator/Validators/PostalCodeValidator.html +14 -10
- data/doc/OmgValidator/Validators/PostalOrZipCodeValidator.html +14 -10
- data/doc/OmgValidator/Validators/StrongPasswordValidator.html +18 -13
- data/doc/OmgValidator/Validators/UrlValidator.html +17 -11
- data/doc/OmgValidator/Validators/ZipCodeValidator.html +13 -10
- data/doc/_index.html +4 -4
- data/doc/file.README.html +11 -13
- data/doc/frames.html +1 -1
- data/doc/index.html +11 -13
- data/doc/js/full_list.js +6 -0
- data/doc/method_list.html +12 -12
- data/doc/top-level-namespace.html +5 -3
- data/lib/omg_validator.rb +3 -0
- data/lib/omg_validator/validators/alpha_dash_validator.rb +3 -0
- data/lib/omg_validator/validators/alpha_numeric_validator.rb +3 -0
- data/lib/omg_validator/validators/alpha_validator.rb +3 -0
- data/lib/omg_validator/validators/decimal_validator.rb +3 -0
- data/lib/omg_validator/validators/email_validator.rb +4 -1
- data/lib/omg_validator/validators/integer_validator.rb +3 -0
- data/lib/omg_validator/validators/ip_address_validator.rb +4 -1
- data/lib/omg_validator/validators/numeric_validator.rb +3 -0
- data/lib/omg_validator/validators/phone_number_validator.rb +4 -1
- data/lib/omg_validator/validators/postal_code_validator.rb +3 -0
- data/lib/omg_validator/validators/postal_or_zip_code_validator.rb +3 -0
- data/lib/omg_validator/validators/strong_password_validator.rb +6 -3
- data/lib/omg_validator/validators/url_validator.rb +5 -2
- data/lib/omg_validator/validators/zip_code_validator.rb +3 -0
- data/lib/omg_validator/version.rb +1 -1
- data/omg_validator-0.0.6.2.gem +0 -0
- data/test/dummy/app/models/thing.rb +32 -0
- data/test/dummy/config/environments/test.rb +1 -1
- data/test/omg_validator_test.rb +248 -0
- data/test/support/things.rb +252 -0
- metadata +7 -2
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Top Level Namespace
|
8
8
|
|
9
|
-
— Documentation by YARD 0.7.
|
9
|
+
— Documentation by YARD 0.7.5
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -91,12 +91,14 @@
|
|
91
91
|
|
92
92
|
|
93
93
|
|
94
|
+
|
95
|
+
|
94
96
|
</div>
|
95
97
|
|
96
98
|
<div id="footer">
|
97
|
-
Generated on
|
99
|
+
Generated on Thu Apr 5 00:05:42 2012 by
|
98
100
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
99
|
-
0.7.
|
101
|
+
0.7.5 (ruby-1.9.2).
|
100
102
|
</div>
|
101
103
|
|
102
104
|
</body>
|
data/lib/omg_validator.rb
CHANGED
@@ -14,9 +14,12 @@ require "omg_validator/validators/alpha_validator"
|
|
14
14
|
require "omg_validator/validators/date_validator"
|
15
15
|
require "omg_validator/validators/decimal_validator"
|
16
16
|
require "omg_validator/validators/email_validator"
|
17
|
+
require "omg_validator/validators/url_validator"
|
18
|
+
require "omg_validator/validators/ip_address_validator"
|
17
19
|
require "omg_validator/validators/integer_validator"
|
18
20
|
require "omg_validator/validators/numeric_validator"
|
19
21
|
require "omg_validator/validators/phone_number_validator"
|
20
22
|
require "omg_validator/validators/postal_code_validator"
|
21
23
|
require "omg_validator/validators/postal_or_zip_code_validator"
|
24
|
+
require "omg_validator/validators/strong_password_validator"
|
22
25
|
require "omg_validator/validators/zip_code_validator"
|
@@ -3,6 +3,9 @@ module OmgValidator
|
|
3
3
|
# Checks whether input only contains alpha-numberic characters and dashes
|
4
4
|
#
|
5
5
|
# validates :perma_link, alpha_dash: true
|
6
|
+
#
|
7
|
+
# matches: alpha-dash-23, ll2-ada, 343, Dfsdf, -,
|
8
|
+
# does not match: $10.00, sub.domain, id=343, (232)
|
6
9
|
class AlphaDashValidator < ActiveModel::EachValidator
|
7
10
|
def validate_each(record, attribute, value)
|
8
11
|
return nil if value.nil?
|
@@ -3,6 +3,9 @@ module OmgValidator
|
|
3
3
|
# Checks whether input only contains alpha-numberic characters
|
4
4
|
#
|
5
5
|
# validates :title, alpha_numberic: true
|
6
|
+
#
|
7
|
+
# matches: alpha23, Testing, 343, hello,
|
8
|
+
# does not match: 324-343, alpha-dash, id=343, (232)
|
6
9
|
class AlphaNumericValidator < ActiveModel::EachValidator
|
7
10
|
def validate_each(record, attribute, value)
|
8
11
|
return nil if value.nil?
|
@@ -3,6 +3,9 @@ module OmgValidator
|
|
3
3
|
# Checks whether input only contains alphabetic characters
|
4
4
|
#
|
5
5
|
# validates :name, alpha: true
|
6
|
+
#
|
7
|
+
# matches: alpha, testing, Hello,
|
8
|
+
# does not match: sub.domain, alpha-dash, id=343, (232)
|
6
9
|
class AlphaValidator < ActiveModel::EachValidator
|
7
10
|
def validate_each(record, attribute, value)
|
8
11
|
return nil if value.nil?
|
@@ -3,6 +3,9 @@ module OmgValidator
|
|
3
3
|
# Checks whether input is a valid floating point number
|
4
4
|
#
|
5
5
|
# validates :total_value, decimal: true
|
6
|
+
#
|
7
|
+
# matches: 10.00, -23.12, 9.99, 1.9002302
|
8
|
+
# does not match: 123, 99, -23, 1,000
|
6
9
|
class DecimalValidator < ActiveModel::EachValidator
|
7
10
|
def validate_each(record, attribute, value)
|
8
11
|
return nil if value.nil?
|
@@ -3,10 +3,13 @@ module OmgValidator
|
|
3
3
|
# Checks whether input is a valid email address
|
4
4
|
#
|
5
5
|
# validates :email, email: true
|
6
|
+
#
|
7
|
+
# matches: email@domain.com, my_user@domain.edu.org, sub.domain@ohyeah.com,
|
8
|
+
# does not match: mail@you@rock.com, domain.com
|
6
9
|
class EmailValidator < ActiveModel::EachValidator
|
7
10
|
def validate_each(record, attribute, value)
|
8
11
|
return nil if value.nil?
|
9
|
-
reg =
|
12
|
+
reg = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+$/
|
10
13
|
unless reg.match(value)
|
11
14
|
record.errors[attribute] = "must be a valid email address"
|
12
15
|
end
|
@@ -3,6 +3,9 @@ module OmgValidator
|
|
3
3
|
# Checks whether input is a valid integer
|
4
4
|
#
|
5
5
|
# validates :count, integer: true
|
6
|
+
#
|
7
|
+
# matches: 10, 20, 2323, -20, 10000000,
|
8
|
+
# does not match: 10.50, -22.21, 1,000, ten
|
6
9
|
class IntegerValidator < ActiveModel::EachValidator
|
7
10
|
def validate_each(record, attribute, value)
|
8
11
|
return nil if value.nil?
|
@@ -3,10 +3,13 @@ module OmgValidator
|
|
3
3
|
# Checks whether input is a valid IP Address
|
4
4
|
#
|
5
5
|
# validates :ip_address, ip_adress: true
|
6
|
+
#
|
7
|
+
# matches: 101.101.102.123, 9.199.22.212, 255.255.255.0, 127.0.0.1
|
8
|
+
# does not match: 101.101.102.565, 255.256.256.0, 90.0.0, 12.12.54.34.123
|
6
9
|
class IpAddressValidator < ActiveModel::EachValidator
|
7
10
|
def validate_each(record, attribute, value)
|
8
11
|
return nil if value.nil?
|
9
|
-
reg =
|
12
|
+
reg = /^\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$\b/
|
10
13
|
unless reg.match(value)
|
11
14
|
record.errors[attribute] = "must be a valid IP address"
|
12
15
|
end
|
@@ -3,6 +3,9 @@ module OmgValidator
|
|
3
3
|
# Checks whether input is a valid number
|
4
4
|
#
|
5
5
|
# validates :count, number: true
|
6
|
+
#
|
7
|
+
# matches: 123, 523.12, -23, -23.12
|
8
|
+
# does not match: six, 23.23.12, 1,000
|
6
9
|
class NumericValidator < ActiveModel::EachValidator
|
7
10
|
def validate_each(record, attribute, value)
|
8
11
|
return nil if value.nil?
|
@@ -4,10 +4,13 @@ module OmgValidator
|
|
4
4
|
# Currently only supports American and Canadian formats
|
5
5
|
#
|
6
6
|
# validates :phone, phone_number: true
|
7
|
+
#
|
8
|
+
# matches: 2342343423, 1-800-232-1232, 100-232-2322, 1905-232-2323,
|
9
|
+
# does not match: 3434343434343, 333333333, 905-232-23239, (111) 232-2322
|
7
10
|
class PhoneNumberValidator < ActiveModel::EachValidator
|
8
11
|
def validate_each(record, attribute, value)
|
9
12
|
return nil if value.nil?
|
10
|
-
reg = /^(
|
13
|
+
reg = /^(\d[ -\.]?)?(\d{3}[ -\.]?)?\d{3}[ -\.]?\d{4}(x\d+)?$/
|
11
14
|
unless reg.match(value)
|
12
15
|
record.errors[attribute] = "must be a valid phone number"
|
13
16
|
end
|
@@ -3,6 +3,9 @@ module OmgValidator
|
|
3
3
|
# Checks whether input is a valid postal code
|
4
4
|
#
|
5
5
|
# validates :postal_code, postal_code: true
|
6
|
+
#
|
7
|
+
# matches: L2J 4T5, l2a 9d1, h2o 4g1, h2o4g1
|
8
|
+
# does not match: z2n 1n3, aan 2j2, LL2J 4T5, 5j4 f1d
|
6
9
|
class PostalCodeValidator < ActiveModel::EachValidator
|
7
10
|
def validate_each(record, attribute, value)
|
8
11
|
return nil if value.nil?
|
@@ -3,6 +3,9 @@ module OmgValidator
|
|
3
3
|
# Checks whether input is a valid postal code or a valid zip code
|
4
4
|
#
|
5
5
|
# validates :zip_code, postal_or_zip_code: true
|
6
|
+
#
|
7
|
+
# matches: L2J 4T5, l2a 9d1, h2o 4g1, h2o4g1, 90210, 20037-8001, 12345
|
8
|
+
# does not match: z2n 1n3, aan 2j2, LL2J 4T5, 123456, 20037-001, 207-01
|
6
9
|
class PostalOrZipCodeValidator < ActiveModel::EachValidator
|
7
10
|
def validate_each(record, attribute, value)
|
8
11
|
return nil if value.nil?
|
@@ -1,15 +1,18 @@
|
|
1
1
|
module OmgValidator
|
2
2
|
module Validators
|
3
3
|
# Checks whether password input is a strong password
|
4
|
-
# Must contain a least one number, one lower case letter and one upper case letter
|
4
|
+
# Must contain a least one number, one lower case letter and one upper case letter and must be at least 8 characters
|
5
5
|
#
|
6
6
|
# validates :password, strong_password: true
|
7
|
+
#
|
8
|
+
# matches: ASdj3j3jsS, 8#adCje3, pwd#fdJa9, To34zNbsr30,
|
9
|
+
# does not match: password, sdfsdfs3, Jsdsdsdj, G3hn$h
|
7
10
|
class StrongPasswordValidator < ActiveModel::EachValidator
|
8
11
|
def validate_each(record, attribute, value)
|
9
12
|
return nil if value.nil?
|
10
|
-
reg =
|
13
|
+
reg = /(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/
|
11
14
|
unless reg.match(value)
|
12
|
-
record.errors[attribute] = "must contain at least a number, a lower case letter,
|
15
|
+
record.errors[attribute] = "must contain at least a number, a lower case letter, a upper case letter and must be at least 8 characters"
|
13
16
|
end
|
14
17
|
end
|
15
18
|
end
|
@@ -4,10 +4,13 @@ module OmgValidator
|
|
4
4
|
# Supports the protocols: http, https and ftp
|
5
5
|
#
|
6
6
|
# validates :url, url: true
|
7
|
-
|
7
|
+
#
|
8
|
+
# matches: http://www.example.com, www.example.com, example.com, sub.example.com
|
9
|
+
# does not match: @asd.com, domain.c, domain.asd., amasd@asd.com.a
|
10
|
+
class UrlValidator < ActiveModel::EachValidator
|
8
11
|
def validate_each(record, attribute, value)
|
9
12
|
return nil if value.nil?
|
10
|
-
reg =
|
13
|
+
reg = /^((https?):\/\/)?([a-z\d]+([\-\.][a-z\d]+)*\.[a-z]{2,6})((:(\d{1,5}))?(\/.*)?)?$/
|
11
14
|
unless reg.match(value)
|
12
15
|
record.errors[attribute] = "must be a valid url"
|
13
16
|
end
|
@@ -3,6 +3,9 @@ module OmgValidator
|
|
3
3
|
# Checks whether input is a valid zip code
|
4
4
|
#
|
5
5
|
# validates :zip_code, zip_code: true
|
6
|
+
#
|
7
|
+
# matches: 90210, 20037-8001, 12345
|
8
|
+
# does not match: 123456, 20037-001, 207-01
|
6
9
|
class ZipCodeValidator < ActiveModel::EachValidator
|
7
10
|
def validate_each(record, attribute, value)
|
8
11
|
return nil if value.nil?
|
Binary file
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
|
3
|
+
class Thing
|
4
|
+
include ActiveModel::Validations
|
5
|
+
|
6
|
+
attr_accessor :alpha, :alpha_numeric, :alpha_dash, :zip_code, :postal_or_zip_code, :postal_code,
|
7
|
+
:decimal, :integer, :numeric, :email, :ip_address, :url, :phone, :password, :date
|
8
|
+
|
9
|
+
validates :alpha, alpha: true
|
10
|
+
validates :alpha_numeric, alpha_numeric: true
|
11
|
+
validates :alpha_dash, alpha_dash: true
|
12
|
+
validates :zip_code, zip_code: true
|
13
|
+
validates :postal_or_zip_code, postal_or_zip_code: true
|
14
|
+
validates :postal_code, postal_code: true
|
15
|
+
validates :decimal, decimal: true
|
16
|
+
validates :integer, integer: true
|
17
|
+
validates :numeric, numeric: true
|
18
|
+
validates :email, email: true
|
19
|
+
validates :ip_address, ip_address: true
|
20
|
+
validates :url, url: true
|
21
|
+
validates :phone, phone_number: true
|
22
|
+
validates :password, strong_password: true
|
23
|
+
validates :date, date: true
|
24
|
+
|
25
|
+
def initialize(options = {})
|
26
|
+
@alpha = options[:alpha] unless options[:alpha].nil?
|
27
|
+
@alpha_numeric = options[:alpha_numeric] unless options[:alpha_numeric].nil?
|
28
|
+
@alpha_dash = options[:alpha_dash] unless options[:alpha_dash].nil?
|
29
|
+
@zip_code = options[:zip_code] unless options[:zip_code].nil?
|
30
|
+
@postal_or_zip_code = options[:postal_or_zip_code] unless options[:postal_or_zip_code].nil?
|
31
|
+
end
|
32
|
+
end
|
@@ -27,7 +27,7 @@ Dummy::Application.configure do
|
|
27
27
|
# Tell Action Mailer not to deliver emails to the real world.
|
28
28
|
# The :test delivery method accumulates sent emails in the
|
29
29
|
# ActionMailer::Base.deliveries array.
|
30
|
-
config.action_mailer.delivery_method = :test
|
30
|
+
#config.action_mailer.delivery_method = :test
|
31
31
|
|
32
32
|
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
33
33
|
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
data/test/omg_validator_test.rb
CHANGED
@@ -1,7 +1,255 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class OmgValidatorTest < ActiveSupport::TestCase
|
4
|
+
def setup
|
5
|
+
@thing = nil
|
6
|
+
@thing = Thing.new({
|
7
|
+
alpha: Things.alphas[:valid].sample,
|
8
|
+
alpha_numeric: Things.alpha_numerics[:valid].sample,
|
9
|
+
alpha_dash: Things.alpha_dashes[:valid].sample,
|
10
|
+
zip_code: Things.zip_codes[:valid].sample,
|
11
|
+
postal_or_zip_code: Things.postal_codes[:valid].sample
|
12
|
+
})
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
@thing = nil
|
17
|
+
end
|
18
|
+
|
4
19
|
test "truth" do
|
5
20
|
assert_kind_of Module, OmgValidator
|
6
21
|
end
|
22
|
+
|
23
|
+
# alpha
|
24
|
+
test "thing should be invalid if alpha contains non-alpha characters" do
|
25
|
+
Things.alphas[:invalid].each do |alpha|
|
26
|
+
@thing.alpha = alpha
|
27
|
+
assert !@thing.valid?, "#{alpha} - #{@thing.errors.full_messages.join("\n")}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
test "thing should be valid if alpha contains only alpha characters" do
|
32
|
+
Things.alphas[:valid].each do |alpha|
|
33
|
+
@thing.alpha = alpha
|
34
|
+
assert @thing.valid?, "#{alpha} - #{@thing.errors.full_messages.join("\n")}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# alpha numeric
|
39
|
+
test "thing should be invalid if alpha_numeric contains non-alpha-numeric characters" do
|
40
|
+
Things.alpha_numerics[:invalid].each do |alpha_numeric|
|
41
|
+
@thing.alpha_numeric = alpha_numeric
|
42
|
+
assert !@thing.valid?, "#{alpha_numeric} - #{@thing.errors.full_messages.join("\n")}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
test "thing should be valid if alpha_numeric contains only alpha-numeric characters" do
|
48
|
+
Things.alpha_numerics[:valid].each do |alpha_numeric|
|
49
|
+
@thing.alpha_numeric = alpha_numeric
|
50
|
+
assert @thing.valid?, "#{alpha_numeric} - #{@thing.errors.full_messages.join("\n")}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# alpha dash
|
55
|
+
test "thing should be invalid if alpha_dash contains non-alpha-numeric-dashes characters" do
|
56
|
+
Things.alpha_dashes[:invalid].each do |alpha_dash|
|
57
|
+
@thing.alpha_dash = alpha_dash
|
58
|
+
assert !@thing.valid?, "#{alpha_dash} - #{@thing.errors.full_messages.join("\n")}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
test "thing should be valid if alpha_dash contains only alpha-numeric-dashes characters" do
|
63
|
+
Things.alpha_dashes[:valid].each do |alpha_dash|
|
64
|
+
@thing.alpha_dash = alpha_dash
|
65
|
+
assert @thing.valid? "#{alpha_dash} - #{@thing.errors.full_messages.join("\n")}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
test "thing should be valid if alpha_dash contains only alpha or dash characters" do
|
70
|
+
Things.alpha_dashes[:valid].each do |alpha_dash|
|
71
|
+
@thing.alpha_dash = alpha_dash
|
72
|
+
assert @thing.valid?, "#{alpha_dash} - #{@thing.errors.full_messages.join("\n")}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# zip code
|
77
|
+
test "thing should be invalid if zip_code is not a valid zip_code" do
|
78
|
+
Things.zip_codes[:invalid].each do |zip|
|
79
|
+
@thing.zip_code = zip
|
80
|
+
assert !@thing.valid?, "#{zip} - #{@thing.errors.full_messages.join("\n")}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
test "thing should be valid if zip_code is a valid zip code" do
|
85
|
+
Things.zip_codes[:valid].each do |zip|
|
86
|
+
@thing.zip_code = zip
|
87
|
+
assert @thing.valid?, "#{zip} - #{@thing.errors.full_messages.join("\n")}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# postal or zip code
|
92
|
+
test "thing should be invalid if postal_or_zip_code is not a valid postal or zip code" do
|
93
|
+
Things.postal_codes[:invalid].concat(Things.zip_codes[:invalid]).each do |zip_or_postal|
|
94
|
+
@thing.postal_or_zip_code = zip_or_postal
|
95
|
+
assert !@thing.valid?, "#{zip_or_postal} - #{@thing.errors.full_messages.join("\n")}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
test "thing should be valid if postal_or_zip_code is a valid postal or zip code" do
|
100
|
+
Things.postal_codes[:valid].concat(Things.zip_codes[:valid]).each do |zip_or_postal|
|
101
|
+
@thing.postal_or_zip_code = zip_or_postal
|
102
|
+
assert @thing.valid?, "#{zip_or_postal} - #{@thing.errors.full_messages.join("\n")}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# postal code
|
107
|
+
test "thing should be valid if postal_code is a valid postal code" do
|
108
|
+
Things.postal_codes[:valid].each do |code|
|
109
|
+
@thing.postal_code = code
|
110
|
+
assert @thing.valid?, "#{code} - #{@thing.errors.full_messages.join("\n")}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
test "thing should be invalid if postal_code is not a valid postal code" do
|
115
|
+
Things.postal_codes[:invalid].each do |code|
|
116
|
+
@thing.postal_code = code
|
117
|
+
assert !@thing.valid?, "#{code} - #{@thing.errors.full_messages.join("\n")}"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# decimals
|
122
|
+
test "thing should be valid if decimal is a valid decimal" do
|
123
|
+
Things.decimals[:valid].each do |decimal|
|
124
|
+
@thing.decimal = decimal
|
125
|
+
assert @thing.valid?, "#{decimal} - #{@thing.errors.full_messages.join("\n")}"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
test "thing should be invalid if decimal is not a valid decimal" do
|
130
|
+
Things.decimals[:invalid].each do |decimal|
|
131
|
+
@thing.decimal = decimal
|
132
|
+
assert !@thing.valid?, "#{decimal} - #{@thing.errors.full_messages.join("\n")}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# integer
|
137
|
+
test "thing should be valid if integer is a valid integer" do
|
138
|
+
Things.integers[:valid].each do |integer|
|
139
|
+
@thing.integer = integer
|
140
|
+
assert @thing.valid?, "#{integer} - #{@thing.errors.full_messages.join("\n")}"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
test "thing should be invalid if integer is not a valid integer" do
|
145
|
+
Things.integers[:invalid].each do |integer|
|
146
|
+
@thing.integer = integer
|
147
|
+
assert !@thing.valid?, "#{integer} - #{@thing.errors.full_messages.join("\n")}"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# numeric
|
152
|
+
test "thing should be valid if numeric is a valid numeric" do
|
153
|
+
Things.numeric[:valid].each do |numeric|
|
154
|
+
@thing.numeric = numeric
|
155
|
+
assert @thing.valid?, "#{numeric} - #{@thing.errors.full_messages.join("\n")}"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
test "thing should be invalid if numeric is not a valid numeric" do
|
160
|
+
Things.numeric[:invalid].each do |numeric|
|
161
|
+
@thing.numeric = numeric
|
162
|
+
assert !@thing.valid?, "#{numeric} - #{@thing.errors.full_messages.join("\n")}"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# email
|
167
|
+
test "thing should be valid if email is a valid email" do
|
168
|
+
Things.emails[:valid].each do |email|
|
169
|
+
@thing.email = email
|
170
|
+
assert @thing.valid?, "#{email} - #{@thing.errors.full_messages.join("\n")}"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
test "thing should be invalid if email is not a valid email" do
|
175
|
+
Things.emails[:invalid].each do |email|
|
176
|
+
@thing.email = email
|
177
|
+
assert !@thing.valid?, "#{email} - #{@thing.errors.full_messages.join("\n")}"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# ip address
|
182
|
+
test "thing should be valid if ip_address is a valid ip address" do
|
183
|
+
Things.ip_addresses[:valid].each do |ip|
|
184
|
+
@thing.ip_address = ip
|
185
|
+
assert @thing.valid?, "#{ip} - #{@thing.errors.full_messages.join("\n")}"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
test "thing should be invalid if ip_address is not a valid ip address" do
|
190
|
+
Things.ip_addresses[:invalid].each do |ip|
|
191
|
+
@thing.ip_address = ip
|
192
|
+
assert !@thing.valid?, "#{ip} - #{@thing.errors.full_messages.join("\n")}"
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# url
|
197
|
+
test "thing should be valid if url is a valid url" do
|
198
|
+
Things.urls[:valid].each do |url|
|
199
|
+
@thing.url = url
|
200
|
+
assert @thing.valid?, "#{url} - #{@thing.errors.full_messages.join("\n")}"
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
test "thing should be invalid if url is not a valid url" do
|
205
|
+
Things.urls[:invalid].each do |url|
|
206
|
+
@thing.url = url
|
207
|
+
assert !@thing.valid?, "#{url} - #{@thing.errors.full_messages.join("\n")}"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# phone number
|
212
|
+
test "thing should be valid if phone is a valid phone number" do
|
213
|
+
Things.phone_numbers[:valid].each do |phone|
|
214
|
+
@thing.phone = phone
|
215
|
+
assert @thing.valid?, "#{phone} - #{@thing.errors.full_messages.join("\n")}"
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
test "thing should be invalid if phone is not a valid phone number" do
|
220
|
+
Things.phone_numbers[:invalid].each do |phone|
|
221
|
+
@thing.phone = phone
|
222
|
+
assert !@thing.valid?, "#{phone} - #{@thing.errors.full_messages.join("\n")}"
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
# strong password
|
227
|
+
test "thing should be valid if password is a valid strong password" do
|
228
|
+
Things.strong_passwords[:valid].each do |password|
|
229
|
+
@thing.password = password
|
230
|
+
assert @thing.valid?, "#{password} - #{@thing.errors.full_messages.join("\n")}"
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
test "thing should be invalid if password is not a valid strong password" do
|
235
|
+
Things.strong_passwords[:invalid].each do |password|
|
236
|
+
@thing.password = password
|
237
|
+
assert !@thing.valid?, "#{password} - #{@thing.errors.full_messages.join("\n")}"
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
# date
|
242
|
+
test "thing should be valid if date is a valid date" do
|
243
|
+
Things.dates[:valid].each do |date|
|
244
|
+
@thing.date = date
|
245
|
+
assert @thing.valid?, "#{date} - #{@thing.errors.full_messages.join("\n")}"
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
test "thing should be invalid if date is not a valid date" do
|
250
|
+
Things.dates[:invalid].each do |date|
|
251
|
+
@thing.date = date
|
252
|
+
assert !@thing.valid?, "#{date} - #{@thing.errors.full_messages.join("\n")}"
|
253
|
+
end
|
254
|
+
end
|
7
255
|
end
|