validatious-on-rails 0.4.5 → 0.4.6
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/generators/validatious/templates/v2.rails.js +35 -0
- data/lib/validatious-on-rails/model_validations.rb +45 -32
- data/lib/validatious-on-rails/validatious/client_side_validator.rb +1 -1
- data/lib/validatious-on-rails/validatious/remote_validator.rb +4 -6
- data/lib/validatious-on-rails/validatious/validator.rb +48 -55
- data/lib/validatious-on-rails/validatious/validators/acceptance_accept_validator.rb +24 -0
- data/lib/validatious-on-rails/validatious/validators/confirmation_of_validator.rb +22 -0
- data/lib/validatious-on-rails/validatious/validators/exclusion_in_validator.rb +30 -0
- data/lib/validatious-on-rails/validatious/validators/format_with_validator.rb +27 -0
- data/lib/validatious-on-rails/validatious/validators/inclusion_in_validator.rb +30 -0
- data/lib/validatious-on-rails/validatious/validators/length/is_validator.rb +7 -10
- data/lib/validatious-on-rails/validatious/validators/length/maximum_validator.rb +6 -9
- data/lib/validatious-on-rails/validatious/validators/length/minimum_validator.rb +6 -9
- data/lib/validatious-on-rails/validatious/validators/numericality/equal_to_validator.rb +5 -7
- data/lib/validatious-on-rails/validatious/validators/numericality/even_validator.rb +5 -6
- data/lib/validatious-on-rails/validatious/validators/numericality/greater_than_or_equal_to_validator.rb +5 -7
- data/lib/validatious-on-rails/validatious/validators/numericality/greater_than_validator.rb +5 -7
- data/lib/validatious-on-rails/validatious/validators/numericality/less_than_or_equal_to_validator.rb +5 -7
- data/lib/validatious-on-rails/validatious/validators/numericality/less_than_validator.rb +5 -7
- data/lib/validatious-on-rails/validatious/validators/numericality/odd_validator.rb +5 -6
- data/lib/validatious-on-rails/validatious/validators/numericality/only_integer_validator.rb +6 -7
- data/lib/validatious-on-rails/validatious/validators/presence_validator.rb +4 -7
- data/lib/validatious-on-rails/validatious/validators/uniqueness_validator.rb +3 -10
- data/test/validatious_on_rails/controller_test.rb +1 -1
- data/test/validatious_on_rails/model_validations_test.rb +19 -19
- data/test/validatious_on_rails/rails/action_view_helpers_test.rb +11 -9
- data/test/validatious_on_rails/validatious/validator_test.rb +11 -11
- metadata +12 -12
- data/lib/validatious-on-rails/validatious/validators/acceptance_validator.rb +0 -28
- data/lib/validatious-on-rails/validatious/validators/confirmation_validator.rb +0 -23
- data/lib/validatious-on-rails/validatious/validators/exclusion_validator.rb +0 -28
- data/lib/validatious-on-rails/validatious/validators/format_validator.rb +0 -33
- data/lib/validatious-on-rails/validatious/validators/inclusion_validator.rb +0 -28
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), *%w[.. validator]))
|
3
|
+
|
4
|
+
# TODO/QUESTION: Should message be thrown on the confirmation field or the confirmed field (Rails).
|
5
|
+
# First makes most sense, but not the Rails way.
|
6
|
+
#
|
7
|
+
module ValidatiousOnRails
|
8
|
+
module Validatious
|
9
|
+
class ConfirmationOfValidator < ClientSideValidator
|
10
|
+
|
11
|
+
def initialize(*args)
|
12
|
+
super
|
13
|
+
self.message = self.class.generate_message(:confirmation)
|
14
|
+
self.params = %w[field-id]
|
15
|
+
self.fn = %{
|
16
|
+
return value === v2.$f(params[0]).getValue();
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), *%w[.. validator]))
|
3
|
+
|
4
|
+
module ValidatiousOnRails
|
5
|
+
module Validatious
|
6
|
+
class ExclusionInValidator < ClientSideValidator
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
data = args.first.dup
|
10
|
+
args.unshift self.class.generate_id(args.shift.inspect)
|
11
|
+
super *args
|
12
|
+
self.message = self.class.generate_message(:exclusion)
|
13
|
+
self.params = %w[exclude allow_nil allow_blank]
|
14
|
+
self.data = %{
|
15
|
+
v2.Rails.params['#{args.first}'] = #{data.to_json};
|
16
|
+
}
|
17
|
+
self.fn = %{
|
18
|
+
#{self.class.handle_nil(1)}
|
19
|
+
#{self.class.handle_blank(2)}
|
20
|
+
var exclusion_values = v2.Rails.params[params[0]];
|
21
|
+
for (var i = 0; i < exclusion_values.length; i++) {
|
22
|
+
if (exclusion_values[i] == value) { return false; }
|
23
|
+
};
|
24
|
+
return true;
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), *%w[.. validator]))
|
3
|
+
|
4
|
+
module ValidatiousOnRails
|
5
|
+
module Validatious
|
6
|
+
class FormatWithValidator < ClientSideValidator
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
data = args.first.dup
|
10
|
+
args.unshift self.class.generate_id(args.shift.inspect)
|
11
|
+
super *args
|
12
|
+
self.message = self.class.generate_message(:invalid)
|
13
|
+
self.params = %w[format allow_nil allow_blank]
|
14
|
+
self.data = %{
|
15
|
+
v2.Rails.params['#{args.first}'] = #{data.inspect.gsub(/\\A/, '^').gsub(/\\z/, '$')};
|
16
|
+
}
|
17
|
+
# v2.Rails.messages['#{args.first}'] = #{self.message.to_json};
|
18
|
+
self.fn = %{
|
19
|
+
#{self.class.handle_nil(1)}
|
20
|
+
#{self.class.handle_blank(2)}
|
21
|
+
return v2.Rails.params[params[0]].test(value);
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), *%w[.. validator]))
|
3
|
+
|
4
|
+
module ValidatiousOnRails
|
5
|
+
module Validatious
|
6
|
+
class InclusionInValidator < ClientSideValidator
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
data = args.first.dup
|
10
|
+
args.unshift self.class.generate_id(args.shift.inspect)
|
11
|
+
super *args
|
12
|
+
self.message = self.class.generate_message(:inclusion)
|
13
|
+
self.params = %w[include allow_nil allow_blank]
|
14
|
+
self.data = %{
|
15
|
+
v2.Rails.params['#{args.first}'] = #{data.to_json};
|
16
|
+
}
|
17
|
+
self.fn = %{
|
18
|
+
#{self.class.handle_nil(1)}
|
19
|
+
#{self.class.handle_blank(2)}
|
20
|
+
var inclusion_values = v2.Rails.params[params[0]];
|
21
|
+
for (var i = 0; i < inclusion_values.length; i++) {
|
22
|
+
if (inclusion_values[i] == value) { return true; }
|
23
|
+
};
|
24
|
+
return false;
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -6,19 +6,16 @@ module ValidatiousOnRails
|
|
6
6
|
module Length
|
7
7
|
class IsValidator < ClientSideValidator
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
self.params = ['count']
|
14
|
-
self.message = self.class.generate_message(validation, :key => :wrong_length, :count => '{{count}}')
|
15
|
-
self.accept_empty = validation.options[:allow_nil]
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
self.message = self.class.generate_message(:wrong_length, :count => '{{count}}')
|
12
|
+
self.params = %w[count allow_nil allow_blank]
|
16
13
|
self.fn = %{
|
17
|
-
#{self.class.validate_blank(validation.options[:allow_blank])}
|
18
14
|
value += '';
|
19
|
-
|
15
|
+
#{self.class.handle_nil}
|
16
|
+
#{self.class.handle_blank}
|
17
|
+
return value.length == params[0];
|
20
18
|
}
|
21
|
-
self.fn.freeze
|
22
19
|
end
|
23
20
|
|
24
21
|
end
|
@@ -6,19 +6,16 @@ module ValidatiousOnRails
|
|
6
6
|
module Length
|
7
7
|
class MaximumValidator < ClientSideValidator
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
self.params = ['count']
|
14
|
-
self.message = self.class.generate_message(validation, :key => :too_long, :count => '{{count}}')
|
15
|
-
self.accept_empty = validation.options[:allow_nil]
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
self.message = self.class.generate_message(:too_long, :count => '{{count}}')
|
12
|
+
self.params = %w[count allow_nil allow_blank]
|
16
13
|
self.fn = %{
|
17
|
-
#{self.class.validate_blank(validation.options[:allow_blank])}
|
18
14
|
value += '';
|
15
|
+
#{self.class.handle_nil}
|
16
|
+
#{self.class.handle_blank}
|
19
17
|
return value.length <= params[0];
|
20
18
|
}
|
21
|
-
self.fn.freeze
|
22
19
|
end
|
23
20
|
|
24
21
|
end
|
@@ -6,19 +6,16 @@ module ValidatiousOnRails
|
|
6
6
|
module Length
|
7
7
|
class MinimumValidator < ClientSideValidator
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
self.params = ['count']
|
14
|
-
self.message = self.class.generate_message(validation, :key => :too_short, :count => '{{count}}')
|
15
|
-
self.accept_empty = validation.options[:allow_nil]
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
self.message = self.class.generate_message(:too_short, :count => '{{count}}')
|
12
|
+
self.params = %w[count allow_nil allow_blank]
|
16
13
|
self.fn = %{
|
17
|
-
#{self.class.validate_blank(validation.options[:allow_blank])}
|
18
14
|
value += '';
|
15
|
+
#{self.class.handle_nil}
|
16
|
+
#{self.class.handle_blank}
|
19
17
|
return value.length >= params[0];
|
20
18
|
}
|
21
|
-
self.fn.freeze
|
22
19
|
end
|
23
20
|
|
24
21
|
end
|
@@ -6,17 +6,15 @@ module ValidatiousOnRails
|
|
6
6
|
module Numericality
|
7
7
|
class EqualToValidator < ClientSideValidator
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
12
|
-
self.params = [
|
13
|
-
self.message = self.class.generate_message(validation, :key => :equal_to, :count => '{{count}}')
|
14
|
-
self.accept_empty = validation.options[:allow_nil]
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
self.message = self.class.generate_message(:equal_to, :count => '{{count}}')
|
12
|
+
self.params = %w[count allow_nil]
|
15
13
|
self.fn = %{
|
14
|
+
#{self.class.handle_nil}
|
16
15
|
value = +value;
|
17
16
|
return value == params[0];
|
18
17
|
}
|
19
|
-
self.fn.freeze
|
20
18
|
end
|
21
19
|
|
22
20
|
end
|
@@ -6,16 +6,15 @@ module ValidatiousOnRails
|
|
6
6
|
module Numericality
|
7
7
|
class EvenValidator < ClientSideValidator
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
12
|
-
self.
|
13
|
-
self.accept_empty = validation.options[:allow_nil]
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
self.message = self.class.generate_message(:even)
|
12
|
+
self.params = %w[allow_nil]
|
14
13
|
self.fn = %{
|
14
|
+
#{self.class.handle_nil(0)}
|
15
15
|
value = +value;
|
16
16
|
return (value % 2) == 0;
|
17
17
|
}
|
18
|
-
self.fn.freeze
|
19
18
|
end
|
20
19
|
|
21
20
|
end
|
@@ -6,17 +6,15 @@ module ValidatiousOnRails
|
|
6
6
|
module Numericality
|
7
7
|
class GreaterThanOrEqualToValidator < ClientSideValidator
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
12
|
-
self.params = [
|
13
|
-
self.message = self.class.generate_message(validation, :key => :greater_than_or_equal_to, :count => '{{count}}')
|
14
|
-
self.accept_empty = validation.options[:allow_nil]
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
self.message = self.class.generate_message(:greater_than_or_equal_to, :count => '{{count}}')
|
12
|
+
self.params = %w[count allow_nil]
|
15
13
|
self.fn = %{
|
14
|
+
#{self.class.handle_nil}
|
16
15
|
value = +value;
|
17
16
|
return value >= params[0];
|
18
17
|
}
|
19
|
-
self.fn.freeze
|
20
18
|
end
|
21
19
|
|
22
20
|
end
|
@@ -6,17 +6,15 @@ module ValidatiousOnRails
|
|
6
6
|
module Numericality
|
7
7
|
class GreaterThanValidator < ClientSideValidator
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
12
|
-
self.params = [
|
13
|
-
self.message = self.class.generate_message(validation, :key => :greater_than, :count => '{{count}}')
|
14
|
-
self.accept_empty = validation.options[:allow_nil]
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
self.message = self.class.generate_message(:greater_than, :count => '{{count}}')
|
12
|
+
self.params = %w[count allow_nil]
|
15
13
|
self.fn = %{
|
14
|
+
#{self.class.handle_nil}
|
16
15
|
value = +value;
|
17
16
|
return value > params[0];
|
18
17
|
}
|
19
|
-
self.fn.freeze
|
20
18
|
end
|
21
19
|
|
22
20
|
end
|
data/lib/validatious-on-rails/validatious/validators/numericality/less_than_or_equal_to_validator.rb
CHANGED
@@ -6,17 +6,15 @@ module ValidatiousOnRails
|
|
6
6
|
module Numericality
|
7
7
|
class LessThanOrEqualToValidator < ClientSideValidator
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
12
|
-
self.params = [
|
13
|
-
self.message = self.class.generate_message(validation, :key => :less_than_or_equal_to, :count => '{{count}}')
|
14
|
-
self.accept_empty = validation.options[:allow_nil]
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
self.message = self.class.generate_message(:less_than_or_equal_to, :count => '{{count}}')
|
12
|
+
self.params = %w[count allow_nil]
|
15
13
|
self.fn = %{
|
14
|
+
#{self.class.handle_nil}
|
16
15
|
value = +value;
|
17
16
|
return value <= params[0];
|
18
17
|
}
|
19
|
-
self.fn.freeze
|
20
18
|
end
|
21
19
|
|
22
20
|
end
|
@@ -6,17 +6,15 @@ module ValidatiousOnRails
|
|
6
6
|
module Numericality
|
7
7
|
class LessThanValidator < ClientSideValidator
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
12
|
-
self.params = [
|
13
|
-
self.message = self.class.generate_message(validation, :key => :less_than, :count => '{{count}}')
|
14
|
-
self.accept_empty = validation.options[:allow_nil]
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
self.message = self.class.generate_message(:less_than, :count => '{{count}}')
|
12
|
+
self.params = %w[count allow_nil]
|
15
13
|
self.fn = %{
|
14
|
+
#{self.class.handle_nil}
|
16
15
|
value = +value;
|
17
16
|
return value < params[0];
|
18
17
|
}
|
19
|
-
self.fn.freeze
|
20
18
|
end
|
21
19
|
|
22
20
|
end
|
@@ -6,16 +6,15 @@ module ValidatiousOnRails
|
|
6
6
|
module Numericality
|
7
7
|
class OddValidator < ClientSideValidator
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
12
|
-
self.
|
13
|
-
self.accept_empty = validation.options[:allow_nil]
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
self.message = self.class.generate_message(:odd)
|
12
|
+
self.params = %w[allow_nil]
|
14
13
|
self.fn = %{
|
14
|
+
#{self.class.handle_nil(0)}
|
15
15
|
value = +value;
|
16
16
|
return (value % 2) == 1;
|
17
17
|
}
|
18
|
-
self.fn.freeze
|
19
18
|
end
|
20
19
|
|
21
20
|
end
|
@@ -6,16 +6,15 @@ module ValidatiousOnRails
|
|
6
6
|
module Numericality
|
7
7
|
class OnlyIntegerValidator < ClientSideValidator
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
12
|
-
self.
|
13
|
-
self.accept_empty = validation.options[:allow_nil]
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
self.message = self.class.generate_message(:not_a_number, :count => '{{count}}')
|
12
|
+
self.params = %w[allow_nil]
|
14
13
|
self.fn = %{
|
14
|
+
#{self.class.handle_nil(0)}
|
15
15
|
value = +value;
|
16
|
-
return
|
16
|
+
return /^[+-]?\d+$/.test(value);
|
17
17
|
}
|
18
|
-
self.fn.freeze
|
19
18
|
end
|
20
19
|
|
21
20
|
end
|
@@ -5,16 +5,13 @@ module ValidatiousOnRails
|
|
5
5
|
module Validatious
|
6
6
|
class PresenceValidator < ClientSideValidator
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
|
10
|
-
|
11
|
-
self.
|
12
|
-
self.accept_empty = false
|
13
|
-
# Identical to Validatious "required" validator, but we want Rails I18n message support, so...
|
8
|
+
def initialize(*args)
|
9
|
+
super
|
10
|
+
self.message = self.class.generate_message(:blank)
|
11
|
+
self.params = %w[]
|
14
12
|
self.fn = %{
|
15
13
|
return !v2.empty(value) && !(typeof value.length !== 'undefined' && value.length === 0) && !/^[#{'\s\t\n'}]*$/.test(value);
|
16
14
|
}
|
17
|
-
self.fn.freeze
|
18
15
|
end
|
19
16
|
|
20
17
|
end
|
@@ -5,17 +5,10 @@ module ValidatiousOnRails
|
|
5
5
|
module Validatious
|
6
6
|
class UniquenessValidator < RemoteValidator
|
7
7
|
|
8
|
-
def initialize(
|
8
|
+
def initialize(*args)
|
9
9
|
super
|
10
|
-
self.
|
11
|
-
|
12
|
-
|
13
|
-
class << self
|
14
|
-
|
15
|
-
def generate_message(validation)
|
16
|
-
super(validation, :key => :taken)
|
17
|
-
end
|
18
|
-
|
10
|
+
self.params = %w[]
|
11
|
+
self.message = self.class.generate_message(:blank)
|
19
12
|
end
|
20
13
|
|
21
14
|
end
|
@@ -80,7 +80,7 @@ class ControllerTest < ::ActionController::TestCase
|
|
80
80
|
|
81
81
|
get :uniqueness_of, :model => 'bogus_item', :attribute => 'name', :value => 'carrot'
|
82
82
|
assert_response 200
|
83
|
-
assert_equal '
|
83
|
+
assert_equal 'true', @response.body
|
84
84
|
end
|
85
85
|
|
86
86
|
test "valid :value - should succeed" do
|
@@ -40,14 +40,14 @@ class ModelValidationsTest < ::ActiveSupport::TestCase
|
|
40
40
|
validators = ::ValidatiousOnRails::ModelValidations.acceptance_of(
|
41
41
|
validation(:validates_acceptance_of)
|
42
42
|
)
|
43
|
-
assert_validator_class 'acceptance-
|
43
|
+
assert_validator_class 'acceptance-accept_1_false', validators
|
44
44
|
end
|
45
45
|
|
46
46
|
test "with :accept" do
|
47
47
|
validators = ::ValidatiousOnRails::ModelValidations.acceptance_of(
|
48
48
|
validation(:validates_acceptance_of, :accept => true)
|
49
49
|
)
|
50
|
-
assert_validator_class 'acceptance-
|
50
|
+
assert_validator_class 'acceptance-accept_true_false', validators
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -67,7 +67,7 @@ class ModelValidationsTest < ::ActiveSupport::TestCase
|
|
67
67
|
validators = ::ValidatiousOnRails::ModelValidations.exclusion_of(
|
68
68
|
validation(:validates_exclusion_of, :in => values)
|
69
69
|
)
|
70
|
-
assert_validator_class /^exclusion-
|
70
|
+
assert_validator_class /^exclusion-in_(\d+)/, validators
|
71
71
|
assert_match /#{values.to_json}/, validators.first.fn
|
72
72
|
end
|
73
73
|
|
@@ -76,7 +76,7 @@ class ModelValidationsTest < ::ActiveSupport::TestCase
|
|
76
76
|
validators = ::ValidatiousOnRails::ModelValidations.format_of(
|
77
77
|
validation(:validates_format_of, :with => pattern)
|
78
78
|
)
|
79
|
-
assert_validator_class /^format-
|
79
|
+
assert_validator_class /^format-with_(\d+)_false_false/, validators
|
80
80
|
assert_match /#{pattern.inspect[1,-1]}/, validators.first.fn
|
81
81
|
end
|
82
82
|
|
@@ -85,7 +85,7 @@ class ModelValidationsTest < ::ActiveSupport::TestCase
|
|
85
85
|
validators = ::ValidatiousOnRails::ModelValidations.inclusion_of(
|
86
86
|
validation(:validates_inclusion_of, :in => values)
|
87
87
|
)
|
88
|
-
assert_validator_class /^inclusion-
|
88
|
+
assert_validator_class /^inclusion-in_(\d+)_false_false/, validators
|
89
89
|
assert_match /#{values.to_json}/, validators.first.fn
|
90
90
|
end
|
91
91
|
|
@@ -95,42 +95,42 @@ class ModelValidationsTest < ::ActiveSupport::TestCase
|
|
95
95
|
validators = ::ValidatiousOnRails::ModelValidations.length_of(
|
96
96
|
validation(:validates_length_of, :is => 2)
|
97
97
|
)
|
98
|
-
assert_validator_class 'length-
|
98
|
+
assert_validator_class 'length-is_2_false_false', validators
|
99
99
|
end
|
100
100
|
|
101
101
|
test "with :in" do
|
102
102
|
validators = ::ValidatiousOnRails::ModelValidations.length_of(
|
103
103
|
validation(:validates_length_of, :in => 2..10)
|
104
104
|
)
|
105
|
-
assert_validator_class 'length-
|
105
|
+
assert_validator_class 'length-minimum_2_false_false length-maximum_10_false_false', validators
|
106
106
|
end
|
107
107
|
|
108
108
|
test "with :within" do
|
109
109
|
validators = ::ValidatiousOnRails::ModelValidations.length_of(
|
110
110
|
validation(:validates_length_of, :within => 2..10)
|
111
111
|
)
|
112
|
-
assert_validator_class 'length-
|
112
|
+
assert_validator_class 'length-minimum_2_false_false length-maximum_10_false_false', validators
|
113
113
|
end
|
114
114
|
|
115
115
|
test "with :minimum" do
|
116
116
|
validators = ::ValidatiousOnRails::ModelValidations.length_of(
|
117
117
|
validation(:validates_length_of, :minimum => 2)
|
118
118
|
)
|
119
|
-
assert_validator_class 'length-
|
119
|
+
assert_validator_class 'length-minimum_2_false_false', validators
|
120
120
|
end
|
121
121
|
|
122
122
|
test "with :maximum" do
|
123
123
|
validators = ::ValidatiousOnRails::ModelValidations.length_of(
|
124
124
|
validation(:validates_length_of, :maximum => 10)
|
125
125
|
)
|
126
|
-
assert_validator_class 'length-
|
126
|
+
assert_validator_class 'length-maximum_10_false_false', validators
|
127
127
|
end
|
128
128
|
|
129
129
|
test "with :minimum + :maximum" do
|
130
130
|
validators = ::ValidatiousOnRails::ModelValidations.length_of(
|
131
131
|
validation(:validates_length_of, :minimum => 2, :maximum => 10)
|
132
132
|
)
|
133
|
-
assert_validator_class 'length-
|
133
|
+
assert_validator_class 'length-minimum_2_false_false length-maximum_10_false_false', validators
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
@@ -141,14 +141,14 @@ class ModelValidationsTest < ::ActiveSupport::TestCase
|
|
141
141
|
validators = ::ValidatiousOnRails::ModelValidations.numericality_of(
|
142
142
|
validation(:validates_numericality_of, :even => false, :odd => true)
|
143
143
|
)
|
144
|
-
assert_validator_class 'numericality-
|
144
|
+
assert_validator_class 'numericality-odd_false', validators
|
145
145
|
end
|
146
146
|
|
147
147
|
test "with :even only" do
|
148
148
|
validators = ::ValidatiousOnRails::ModelValidations.numericality_of(
|
149
149
|
validation(:validates_numericality_of, :even => true, :odd => false)
|
150
150
|
)
|
151
|
-
assert_validator_class 'numericality-
|
151
|
+
assert_validator_class 'numericality-even_false', validators
|
152
152
|
end
|
153
153
|
|
154
154
|
test "with :odd and :even" do
|
@@ -171,42 +171,42 @@ class ModelValidationsTest < ::ActiveSupport::TestCase
|
|
171
171
|
validation(:validates_numericality_of, :only_integer => true)
|
172
172
|
)
|
173
173
|
# Alt. more generic idea: assert_equal 'numericality-precision_0', validator.to_class
|
174
|
-
assert_validator_class 'numericality-
|
174
|
+
assert_validator_class 'numericality-only-integer_false', validators
|
175
175
|
end
|
176
176
|
|
177
177
|
test "with :greater_than" do
|
178
178
|
validators = ::ValidatiousOnRails::ModelValidations.numericality_of(
|
179
179
|
validation(:validates_numericality_of, :greater_than => 2)
|
180
180
|
)
|
181
|
-
assert_validator_class 'numericality-greater-
|
181
|
+
assert_validator_class 'numericality-greater-than_2_false', validators
|
182
182
|
end
|
183
183
|
|
184
184
|
test "with :greater_than_or_equal_to" do
|
185
185
|
validators = ::ValidatiousOnRails::ModelValidations.numericality_of(
|
186
186
|
validation(:validates_numericality_of, :greater_than_or_equal_to => 2)
|
187
187
|
)
|
188
|
-
assert_validator_class 'numericality-greater-than-or-equal-
|
188
|
+
assert_validator_class 'numericality-greater-than-or-equal-to_2_false', validators
|
189
189
|
end
|
190
190
|
|
191
191
|
test "with :equal_to" do
|
192
192
|
validators = ::ValidatiousOnRails::ModelValidations.numericality_of(
|
193
193
|
validation(:validates_numericality_of, :equal_to => 2)
|
194
194
|
)
|
195
|
-
assert_validator_class 'numericality-equal-
|
195
|
+
assert_validator_class 'numericality-equal-to_2_false', validators
|
196
196
|
end
|
197
197
|
|
198
198
|
test "with :less_than" do
|
199
199
|
validators = ::ValidatiousOnRails::ModelValidations.numericality_of(
|
200
200
|
validation(:validates_numericality_of, :less_than => 10)
|
201
201
|
)
|
202
|
-
assert_validator_class 'numericality-less-
|
202
|
+
assert_validator_class 'numericality-less-than_10_false', validators
|
203
203
|
end
|
204
204
|
|
205
205
|
test "with :less_than_or_equal_to" do
|
206
206
|
validators = ::ValidatiousOnRails::ModelValidations.numericality_of(
|
207
207
|
validation(:validates_numericality_of, :less_than_or_equal_to => 10)
|
208
208
|
)
|
209
|
-
assert_validator_class 'numericality-less-than-or-equal-
|
209
|
+
assert_validator_class 'numericality-less-than-or-equal-to_10_false', validators
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|