client_side_validations-rails_2 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +7 -0
- data/lib/client_side_validations/rails_2/active_record/active_model/validations/base.rb +1 -0
- data/lib/client_side_validations/rails_2/active_record/active_model/validations/length.rb +4 -0
- data/lib/client_side_validations/rails_2/active_record/active_model/validations.rb +6 -1
- data/lib/client_side_validations/rails_2/active_record/middleware.rb +1 -0
- data/lib/client_side_validations/rails_2/middleware.rb +1 -0
- data/lib/client_side_validations/rails_2/version.rb +2 -1
- data/lib/client_side_validations/rails_2.rb +1 -0
- data/test/active_record/cases/test_validations.rb +122 -1
- metadata +3 -2
data/HISTORY
CHANGED
@@ -41,7 +41,12 @@ require 'client_side_validations/rails_2/active_record/active_model/validations/
|
|
41
41
|
MODULE
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
%w{
|
45
|
+
length
|
46
|
+
numericality
|
47
|
+
}.each do |validator|
|
48
|
+
require "client_side_validations/rails_2/active_record/active_model/validations/#{validator}"
|
49
|
+
end
|
45
50
|
|
46
51
|
module ActiveModel::Validations::ClassMethods
|
47
52
|
def validates_size_of(*attr_names)
|
@@ -11,7 +11,113 @@ class ValidationsTest < ClientSideValidations::ActiveRecordTestBase
|
|
11
11
|
user.new
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def test_acceptance_validation_to_client_side_hash
|
15
|
+
user = new_user do |p|
|
16
|
+
p.validates_acceptance_of :name
|
17
|
+
end
|
18
|
+
expected_hash = {
|
19
|
+
:name => {
|
20
|
+
:acceptance => {
|
21
|
+
:message => "must be accepted"
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
assert_equal expected_hash, user.client_side_validation_hash
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_confirmation_validation_to_client_side_hash
|
29
|
+
user = new_user do |p|
|
30
|
+
p.validates_confirmation_of :name
|
31
|
+
end
|
32
|
+
expected_hash = {
|
33
|
+
:name => {
|
34
|
+
:confirmation => {
|
35
|
+
:message => "doesn't match confirmation"
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
assert_equal expected_hash, user.client_side_validation_hash
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_exclusion_validation_to_client_side_hash
|
43
|
+
user = new_user do |p|
|
44
|
+
p.validates_exclusion_of :name, :in => %w{1}
|
45
|
+
end
|
46
|
+
expected_hash = {
|
47
|
+
:name => {
|
48
|
+
:exclusion => {
|
49
|
+
:message => "is reserved",
|
50
|
+
:in => ["1"]
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
assert_equal expected_hash, user.client_side_validation_hash
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_format_validation_to_client_side_hash
|
58
|
+
user = new_user do |p|
|
59
|
+
p.validates_format_of :name, :with => /\.+/
|
60
|
+
end
|
61
|
+
expected_hash = {
|
62
|
+
:name => {
|
63
|
+
:format => {
|
64
|
+
:message => "is invalid",
|
65
|
+
:with => /\.+/
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
assert_equal expected_hash, user.client_side_validation_hash
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_inclusion_validation_to_client_side_hash
|
73
|
+
user = new_user do |p|
|
74
|
+
p.validates_inclusion_of :name, :in => %w{1}
|
75
|
+
end
|
76
|
+
expected_hash = {
|
77
|
+
:name => {
|
78
|
+
:inclusion => {
|
79
|
+
:message => "is not included in the list",
|
80
|
+
:in => ["1"]
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
assert_equal expected_hash, user.client_side_validation_hash
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_length_validation_to_client_side_hash
|
88
|
+
user = new_user do |p|
|
89
|
+
p.validates_length_of :name, :is => 5
|
90
|
+
end
|
91
|
+
expected_hash = {
|
92
|
+
:name => {
|
93
|
+
:length => {
|
94
|
+
:messages => {
|
95
|
+
:is => "is the wrong length (should be 5 characters)"
|
96
|
+
},
|
97
|
+
:is => 5
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
assert_equal expected_hash, user.client_side_validation_hash
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_numericality_validation_to_client_side_hash
|
105
|
+
user = new_user do |p|
|
106
|
+
p.validates_numericality_of :name
|
107
|
+
end
|
108
|
+
expected_hash = {
|
109
|
+
:name => {
|
110
|
+
:numericality => {
|
111
|
+
:messages => {
|
112
|
+
:numericality => "is not a number"
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
assert_equal expected_hash, user.client_side_validation_hash
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_presence_validation_to_client_side_hash
|
15
121
|
user = new_user do |p|
|
16
122
|
p.validates_presence_of :name
|
17
123
|
end
|
@@ -24,4 +130,19 @@ class ValidationsTest < ClientSideValidations::ActiveRecordTestBase
|
|
24
130
|
}
|
25
131
|
assert_equal expected_hash, user.client_side_validation_hash
|
26
132
|
end
|
133
|
+
|
134
|
+
def test_uniqueness_validation_to_client_side_hash
|
135
|
+
user = new_user do |p|
|
136
|
+
p.validates_uniqueness_of :name
|
137
|
+
end
|
138
|
+
expected_hash = {
|
139
|
+
:name => {
|
140
|
+
:uniqueness => {
|
141
|
+
:message => "has already been taken",
|
142
|
+
:case_sensitive => nil
|
143
|
+
}
|
144
|
+
}
|
145
|
+
}
|
146
|
+
assert_equal expected_hash, user.client_side_validation_hash
|
147
|
+
end
|
27
148
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: client_side_validations-rails_2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Brian Cardarella
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-27 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/client_side_validations/rails_2/active_record/active_model.rb
|
127
127
|
- lib/client_side_validations/rails_2/active_record/active_model/validations.rb
|
128
128
|
- lib/client_side_validations/rails_2/active_record/active_model/validations/base.rb
|
129
|
+
- lib/client_side_validations/rails_2/active_record/active_model/validations/length.rb
|
129
130
|
- lib/client_side_validations/rails_2/active_record/active_model/validations/numericality.rb
|
130
131
|
- lib/client_side_validations/rails_2/active_record/middleware.rb
|
131
132
|
- lib/client_side_validations/rails_2/active_record/validations.rb
|