data_validator 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -2
- data/lib/data_validator/version.rb +1 -1
- data/lib/validations/base.rb +10 -2
- data/spec/validations/acceptance_spec.rb +1 -1
- data/spec/validations/base_spec.rb +2 -2
- data/spec/validations/confirmation_spec.rb +1 -1
- data/spec/validations/format_spec.rb +2 -2
- data/spec/validations/inclusion_spec.rb +1 -1
- data/spec/validations/length_validation_spec.rb +3 -3
- data/spec/validations/numericality_spec.rb +9 -9
- data/spec/validations/presence_validation_spec.rb +1 -1
- metadata +6 -6
data/README.md
CHANGED
@@ -28,7 +28,7 @@ If you use rails, you not worry about locale file.
|
|
28
28
|
Ex)
|
29
29
|
|
30
30
|
~~~
|
31
|
-
# encoding: UTF-8
|
31
|
+
# encoding: UTF-8
|
32
32
|
|
33
33
|
module DataValidator
|
34
34
|
class TestValidator < BaseValidator
|
@@ -47,7 +47,9 @@ BaseValidator set accessors below.
|
|
47
47
|
* value : validating paramter value
|
48
48
|
* options : validation rules
|
49
49
|
|
50
|
-
Please see test case.
|
50
|
+
Please see test case.
|
51
|
+
|
52
|
+
An error message subject uses "datavalidator.attribute.#{name}" in i18n locale file or name.
|
51
53
|
|
52
54
|
|
53
55
|
## Installation
|
data/lib/validations/base.rb
CHANGED
@@ -29,10 +29,18 @@ module DataValidator
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def error_add(error_message_key, message_args = {})
|
32
|
+
error_subject_key = "datavalidator.attribute.#{name}"
|
33
|
+
error_subject = ''
|
34
|
+
begin
|
35
|
+
error_subject = I18n.t! "datavalidator.attribute.#{name}"
|
36
|
+
rescue
|
37
|
+
error_subject = name.to_s
|
38
|
+
end
|
39
|
+
|
32
40
|
if errors.key? name
|
33
|
-
errors[name] << I18n.t("errors.messages.#{error_message_key.to_s}", message_args)
|
41
|
+
errors[name] << "#{error_subject} #{I18n.t("errors.messages.#{error_message_key.to_s}", message_args)}"
|
34
42
|
else
|
35
|
-
errors[name] = [I18n.t("errors.messages.#{error_message_key.to_s}", message_args)]
|
43
|
+
errors[name] = ["#{error_subject} #{I18n.t("errors.messages.#{error_message_key.to_s}", message_args)}"]
|
36
44
|
end
|
37
45
|
end
|
38
46
|
end
|
@@ -32,7 +32,7 @@ describe DataValidator::AcceptanceValidator do
|
|
32
32
|
it { @obj.valid?.should be_false }
|
33
33
|
it do
|
34
34
|
@obj.valid?
|
35
|
-
@obj.errors.should eql({terms_of_service: ["must be accepted"]})
|
35
|
+
@obj.errors.should eql({terms_of_service: ["terms_of_service must be accepted"]})
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -29,14 +29,14 @@ describe DataValidator::BaseValidator do
|
|
29
29
|
context 'add an error first' do
|
30
30
|
it do
|
31
31
|
@obj.error_add(:blank)
|
32
|
-
@obj.errors.should eql({name: ["can't be blank"]})
|
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
37
|
@obj.error_add(:blank)
|
38
38
|
@obj.error_add(:invalid)
|
39
|
-
@obj.errors.should eql({name: ["can't be blank", "is invalid"]})
|
39
|
+
@obj.errors.should eql({name: ["name can't be blank", "name is invalid"]})
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -31,7 +31,7 @@ describe DataValidator::AcceptanceValidator do
|
|
31
31
|
it { @obj.valid?.should be_false }
|
32
32
|
it do
|
33
33
|
@obj.valid?
|
34
|
-
@obj.errors.should eql({password: ["doesn't match confirmation"]})
|
34
|
+
@obj.errors.should eql({password: ["password doesn't match confirmation"]})
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -36,7 +36,7 @@ describe DataValidator::FormatValidator do
|
|
36
36
|
it { @obj.valid?.should be_false }
|
37
37
|
it do
|
38
38
|
@obj.valid?
|
39
|
-
@obj.errors.should eql({name: ["is invalid"]})
|
39
|
+
@obj.errors.should eql({name: ["name is invalid"]})
|
40
40
|
end
|
41
41
|
end
|
42
42
|
context 'without' do
|
@@ -49,7 +49,7 @@ describe DataValidator::FormatValidator do
|
|
49
49
|
it { @obj.valid?.should be_false }
|
50
50
|
it do
|
51
51
|
@obj.valid?
|
52
|
-
@obj.errors.should eql({name: ["is invalid"]})
|
52
|
+
@obj.errors.should eql({name: ["name is invalid"]})
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -26,7 +26,7 @@ describe DataValidator::InclusionValidator do
|
|
26
26
|
it {@obj.valid?.should be_false}
|
27
27
|
it do
|
28
28
|
@obj.valid?
|
29
|
-
@obj.errors.should eql({name: ["is not included in the list"]})
|
29
|
+
@obj.errors.should eql({name: ["name is not included in the list"]})
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -54,7 +54,7 @@ describe DataValidator::LengthValidator do
|
|
54
54
|
it { @obj.valid?.should be_false }
|
55
55
|
it do
|
56
56
|
@obj.valid?
|
57
|
-
@obj.errors.should eql({name: ["is the wrong length (should be 5 characters)"]})
|
57
|
+
@obj.errors.should eql({name: ["name is the wrong length (should be 5 characters)"]})
|
58
58
|
end
|
59
59
|
end
|
60
60
|
context 'maximum' do
|
@@ -67,7 +67,7 @@ describe DataValidator::LengthValidator do
|
|
67
67
|
it { @obj.valid?.should be_false }
|
68
68
|
it do
|
69
69
|
@obj.valid?
|
70
|
-
@obj.errors.should eql({name: ["is too long (maximum is 2 characters)"]})
|
70
|
+
@obj.errors.should eql({name: ["name is too long (maximum is 2 characters)"]})
|
71
71
|
end
|
72
72
|
end
|
73
73
|
context 'minimum' do
|
@@ -80,7 +80,7 @@ describe DataValidator::LengthValidator do
|
|
80
80
|
it { @obj.valid?.should be_false }
|
81
81
|
it do
|
82
82
|
@obj.valid?
|
83
|
-
@obj.errors.should eql({name: ["is too short (minimum is 5 characters)"]})
|
83
|
+
@obj.errors.should eql({name: ["name is too short (minimum is 5 characters)"]})
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -63,63 +63,63 @@ describe DataValidator::LengthValidator do
|
|
63
63
|
{num: "test"},
|
64
64
|
{num: {numericality: true}},
|
65
65
|
:num,
|
66
|
-
"is not a number"
|
66
|
+
"num is not a number"
|
67
67
|
end
|
68
68
|
context 'greater_than' do
|
69
69
|
it_behaves_like :validtion_false,
|
70
70
|
{num: "100"},
|
71
71
|
{num: {numericality: {greater_than: 100}}},
|
72
72
|
:num,
|
73
|
-
"must be greater than 100"
|
73
|
+
"num must be greater than 100"
|
74
74
|
end
|
75
75
|
context 'greater_than_or_equal_to' do
|
76
76
|
it_behaves_like :validtion_false,
|
77
77
|
{num: "99.9"},
|
78
78
|
{num: {numericality: {greater_than_or_equal_to: 100}}},
|
79
79
|
:num,
|
80
|
-
"must be greater than or equal to 100"
|
80
|
+
"num must be greater than or equal to 100"
|
81
81
|
end
|
82
82
|
context 'equal_to' do
|
83
83
|
it_behaves_like :validtion_false,
|
84
84
|
{num: "99"},
|
85
85
|
{num: {numericality: {equal_to: 100}}},
|
86
86
|
:num,
|
87
|
-
"must be equal to 100"
|
87
|
+
"num must be equal to 100"
|
88
88
|
end
|
89
89
|
context 'less_than' do
|
90
90
|
it_behaves_like :validtion_false,
|
91
91
|
{num: "100"},
|
92
92
|
{num: {numericality: {less_than: 100}}},
|
93
93
|
:num,
|
94
|
-
"must be less than 100"
|
94
|
+
"num must be less than 100"
|
95
95
|
end
|
96
96
|
context 'less_than_or_equal_to' do
|
97
97
|
it_behaves_like :validtion_false,
|
98
98
|
{num: "100.1"},
|
99
99
|
{num: {numericality: {less_than_or_equal_to: 100}}},
|
100
100
|
:num,
|
101
|
-
"must be less than or equal to 100"
|
101
|
+
"num must be less than or equal to 100"
|
102
102
|
end
|
103
103
|
context 'odd' do
|
104
104
|
it_behaves_like :validtion_false,
|
105
105
|
{num: "100"},
|
106
106
|
{num: {numericality: {odd: true}}},
|
107
107
|
:num,
|
108
|
-
"must be odd"
|
108
|
+
"num must be odd"
|
109
109
|
end
|
110
110
|
context 'even' do
|
111
111
|
it_behaves_like :validtion_false,
|
112
112
|
{num: "101"},
|
113
113
|
{num: {numericality: {even: true}}},
|
114
114
|
:num,
|
115
|
-
"must be even"
|
115
|
+
"num must be even"
|
116
116
|
end
|
117
117
|
context 'only_integer' do
|
118
118
|
it_behaves_like :validtion_false,
|
119
119
|
{num: "1.001"},
|
120
120
|
{num: {numericality: {only_integer: true}}},
|
121
121
|
:num,
|
122
|
-
"is not an integer"
|
122
|
+
"num is not an integer"
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &70095235205660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.2.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70095235205660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: i18n
|
27
|
-
requirement: &
|
27
|
+
requirement: &70095235204820 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0.6'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70095235204820
|
36
36
|
description: ! ' DataValidator has almost active_recorde validation methods.
|
37
37
|
|
38
38
|
'
|