data_validator 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/data_validator/version.rb +1 -1
- data/lib/validations/acceptance.rb +1 -1
- data/lib/validations/base.rb +1 -1
- data/lib/validations/confirmation.rb +1 -1
- data/lib/validations/format.rb +2 -2
- data/lib/validations/inclusion.rb +1 -1
- data/lib/validations/length.rb +1 -1
- data/lib/validations/numericality.rb +4 -4
- data/lib/validations/presence.rb +1 -1
- data/spec/validations/base_spec.rb +4 -4
- metadata +1 -1
data/lib/validations/base.rb
CHANGED
@@ -28,7 +28,7 @@ module DataValidator
|
|
28
28
|
raise ArgumentError, "Validate method is necessary"
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
31
|
+
def add_error(error_message_key, message_args = {})
|
32
32
|
error_subject_key = "datavalidator.attribute.#{name}"
|
33
33
|
error_subject = ''
|
34
34
|
begin
|
data/lib/validations/format.rb
CHANGED
@@ -12,9 +12,9 @@ module DataValidator
|
|
12
12
|
|
13
13
|
def validate
|
14
14
|
if regexp = options[:with]
|
15
|
-
|
15
|
+
add_error :invalid if value.to_s !~ regexp
|
16
16
|
elsif regexp = options[:without]
|
17
|
-
|
17
|
+
add_error :invalid if value.to_s =~ regexp
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
data/lib/validations/length.rb
CHANGED
@@ -32,7 +32,7 @@ module DataValidator
|
|
32
32
|
CHECKS.each do |key, validity_check|
|
33
33
|
next unless check_value = options[key]
|
34
34
|
next if value_length.send(validity_check, check_value)
|
35
|
-
|
35
|
+
add_error MESSAGES[key], count: check_value
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -16,13 +16,13 @@ module DataValidator
|
|
16
16
|
|
17
17
|
def validate
|
18
18
|
unless checked_value = parse_raw_value_as_a_number(value)
|
19
|
-
|
19
|
+
add_error :not_a_number
|
20
20
|
return
|
21
21
|
end
|
22
22
|
|
23
23
|
if options[:only_integer]
|
24
24
|
unless checked_value = parse_raw_value_as_an_integer(value)
|
25
|
-
|
25
|
+
add_error :not_an_integer
|
26
26
|
return
|
27
27
|
end
|
28
28
|
end
|
@@ -31,12 +31,12 @@ module DataValidator
|
|
31
31
|
case option
|
32
32
|
when :odd, :even
|
33
33
|
unless checked_value.to_i.send(CHECKS[option])
|
34
|
-
|
34
|
+
add_error option
|
35
35
|
end
|
36
36
|
else
|
37
37
|
option_value = option_value.call(record) if option_value.is_a?(Proc)
|
38
38
|
unless checked_value.send(CHECKS[option], option_value)
|
39
|
-
|
39
|
+
add_error option, count: option_value
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
data/lib/validations/presence.rb
CHANGED
@@ -24,18 +24,18 @@ describe DataValidator::BaseValidator do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
describe :
|
27
|
+
describe :add_error do
|
28
28
|
before { @obj = DataValidator::BaseValidator.new(:name, 'value', true, {}) }
|
29
29
|
context 'add an error first' do
|
30
30
|
it do
|
31
|
-
@obj.
|
31
|
+
@obj.add_error(:blank)
|
32
32
|
@obj.errors.should eql({name: ["name can't be blank"]})
|
33
33
|
end
|
34
34
|
end
|
35
35
|
context 'add an errors secondly' do
|
36
36
|
it do
|
37
|
-
@obj.
|
38
|
-
@obj.
|
37
|
+
@obj.add_error(:blank)
|
38
|
+
@obj.add_error(:invalid)
|
39
39
|
@obj.errors.should eql({name: ["name can't be blank", "name is invalid"]})
|
40
40
|
end
|
41
41
|
end
|