client_side_validations 3.1.0 → 3.2.0
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/client_side_validations.gemspec +4 -16
- data/lib/client_side_validations/action_view/form_builder.rb +31 -79
- data/lib/client_side_validations/action_view/form_helper.rb +59 -24
- data/lib/client_side_validations/active_model/exclusion.rb +14 -2
- data/lib/client_side_validations/active_model/format.rb +21 -0
- data/lib/client_side_validations/active_model/inclusion.rb +13 -2
- data/lib/client_side_validations/active_model/length.rb +4 -2
- data/lib/client_side_validations/active_model/numericality.rb +12 -1
- data/lib/client_side_validations/active_model.rb +100 -14
- data/lib/client_side_validations/active_record/middleware.rb +29 -3
- data/lib/client_side_validations/active_record/uniqueness.rb +4 -3
- data/lib/client_side_validations/active_record.rb +2 -1
- data/lib/client_side_validations/config.rb +9 -0
- data/lib/client_side_validations/core_ext/regexp.rb +1 -2
- data/lib/client_side_validations/generators/rails_validations.rb +15 -0
- data/lib/client_side_validations/generators.rb +12 -0
- data/lib/client_side_validations/middleware.rb +63 -24
- data/lib/client_side_validations/version.rb +1 -1
- data/lib/client_side_validations.rb +2 -2
- data/lib/generators/client_side_validations/copy_assets_generator.rb +58 -0
- data/lib/generators/client_side_validations/install_generator.rb +9 -21
- data/lib/generators/templates/client_side_validations/initializer.rb +2 -2
- data/vendor/assets/javascripts/rails.validations.js +474 -282
- metadata +156 -301
- data/lib/client_side_validations/formtastic.rb +0 -21
- data/lib/client_side_validations/mongo_mapper/middleware.rb +0 -20
- data/lib/client_side_validations/mongo_mapper/uniqueness.rb +0 -28
- data/lib/client_side_validations/mongo_mapper.rb +0 -9
- data/lib/client_side_validations/mongoid/middleware.rb +0 -20
- data/lib/client_side_validations/mongoid/uniqueness.rb +0 -28
- data/lib/client_side_validations/mongoid.rb +0 -9
- data/lib/client_side_validations/simple_form.rb +0 -24
- data/lib/generators/client_side_validations/copy_asset_generator.rb +0 -23
- data/lib/generators/templates/client_side_validations/README.rails.3.0 +0 -6
- data/lib/generators/templates/client_side_validations/README.rails.3.1 +0 -7
- data/test/action_view/cases/helper.rb +0 -176
- data/test/action_view/cases/test_helpers.rb +0 -600
- data/test/action_view/cases/test_legacy_helpers.rb +0 -217
- data/test/action_view/models/comment.rb +0 -35
- data/test/action_view/models/post.rb +0 -35
- data/test/action_view/models.rb +0 -3
- data/test/active_model/cases/helper.rb +0 -4
- data/test/active_model/cases/test_acceptance_validator.rb +0 -16
- data/test/active_model/cases/test_base.rb +0 -11
- data/test/active_model/cases/test_confirmation_validator.rb +0 -16
- data/test/active_model/cases/test_exclusion_validator.rb +0 -20
- data/test/active_model/cases/test_format_validator.rb +0 -21
- data/test/active_model/cases/test_inclusion_validator.rb +0 -21
- data/test/active_model/cases/test_length_validator.rb +0 -61
- data/test/active_model/cases/test_numericality_validator.rb +0 -46
- data/test/active_model/cases/test_presence_validator.rb +0 -16
- data/test/active_model/cases/test_validations.rb +0 -175
- data/test/active_model/models/person.rb +0 -17
- data/test/active_record/cases/helper.rb +0 -12
- data/test/active_record/cases/test_base.rb +0 -11
- data/test/active_record/cases/test_middleware.rb +0 -175
- data/test/active_record/cases/test_uniqueness_validator.rb +0 -50
- data/test/active_record/models/guid.rb +0 -7
- data/test/active_record/models/user.rb +0 -14
- data/test/base_helper.rb +0 -8
- data/test/core_ext/cases/test_core_ext.rb +0 -46
- data/test/formtastic/cases/helper.rb +0 -7
- data/test/formtastic/cases/test_form_builder.rb +0 -11
- data/test/formtastic/cases/test_form_helper.rb +0 -21
- data/test/generators/cases/test_generators.rb +0 -31
- data/test/javascript/config.ru +0 -3
- data/test/javascript/public/test/callbacks/elementAfter.js +0 -54
- data/test/javascript/public/test/callbacks/elementBefore.js +0 -54
- data/test/javascript/public/test/callbacks/elementFail.js +0 -70
- data/test/javascript/public/test/callbacks/elementPass.js +0 -70
- data/test/javascript/public/test/callbacks/formAfter.js +0 -45
- data/test/javascript/public/test/callbacks/formBefore.js +0 -45
- data/test/javascript/public/test/callbacks/formFail.js +0 -51
- data/test/javascript/public/test/callbacks/formPass.js +0 -50
- data/test/javascript/public/test/form_builders/validateForm.js +0 -66
- data/test/javascript/public/test/form_builders/validateFormtastic.js +0 -54
- data/test/javascript/public/test/form_builders/validateNestedForm.js +0 -66
- data/test/javascript/public/test/form_builders/validateSimpleForm.js +0 -57
- data/test/javascript/public/test/settings.js +0 -15
- data/test/javascript/public/test/validateElement.js +0 -179
- data/test/javascript/public/test/validators/acceptance.js +0 -42
- data/test/javascript/public/test/validators/confirmation.js +0 -25
- data/test/javascript/public/test/validators/exclusion.js +0 -41
- data/test/javascript/public/test/validators/format.js +0 -27
- data/test/javascript/public/test/validators/inclusion.js +0 -42
- data/test/javascript/public/test/validators/length.js +0 -76
- data/test/javascript/public/test/validators/numericality.js +0 -142
- data/test/javascript/public/test/validators/presence.js +0 -21
- data/test/javascript/public/test/validators/uniqueness.js +0 -96
- data/test/javascript/public/vendor/jquery.metadata.js +0 -122
- data/test/javascript/public/vendor/qunit.css +0 -196
- data/test/javascript/public/vendor/qunit.js +0 -1374
- data/test/javascript/server.rb +0 -84
- data/test/javascript/views/index.erb +0 -20
- data/test/javascript/views/layout.erb +0 -21
- data/test/middleware/cases/helper.rb +0 -18
- data/test/middleware/cases/test_middleware.rb +0 -8
- data/test/mongo_mapper/cases/helper.rb +0 -9
- data/test/mongo_mapper/cases/test_base.rb +0 -15
- data/test/mongo_mapper/cases/test_middleware.rb +0 -77
- data/test/mongo_mapper/cases/test_uniqueness_validator.rb +0 -50
- data/test/mongo_mapper/models/magazine.rb +0 -11
- data/test/mongoid/cases/helper.rb +0 -16
- data/test/mongoid/cases/test_base.rb +0 -15
- data/test/mongoid/cases/test_middleware.rb +0 -77
- data/test/mongoid/cases/test_uniqueness_validator.rb +0 -49
- data/test/mongoid/models/book.rb +0 -12
- data/test/simple_form/cases/helper.rb +0 -5
- data/test/simple_form/cases/test_form_builder.rb +0 -14
- data/test/simple_form/cases/test_form_helper.rb +0 -24
- data/test/test_loader.rb +0 -6
|
@@ -1,600 +0,0 @@
|
|
|
1
|
-
require 'action_view/cases/helper'
|
|
2
|
-
|
|
3
|
-
class ClientSideValidations::ActionViewHelpersTest < ActionView::TestCase
|
|
4
|
-
include ActionViewTestSetup
|
|
5
|
-
|
|
6
|
-
cattr_accessor :field_error_proc
|
|
7
|
-
@@field_error_proc = Proc.new { |html_tag, instance| html_tag }
|
|
8
|
-
|
|
9
|
-
def client_side_form_settings_helper
|
|
10
|
-
{
|
|
11
|
-
:type => "ActionView::Helpers::FormBuilder",
|
|
12
|
-
:input_tag => %{<span id="input_tag" />},
|
|
13
|
-
:label_tag => %{<label id="label_tag" />}
|
|
14
|
-
}
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def test_text_field
|
|
18
|
-
form_for(@post, :validate => true) do |f|
|
|
19
|
-
concat f.text_field(:cost)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
23
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
24
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" size="30" type="text" />}
|
|
25
|
-
end
|
|
26
|
-
assert_equal expected, output_buffer
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_password_field
|
|
30
|
-
form_for(@post, :validate => true) do |f|
|
|
31
|
-
concat f.password_field(:cost)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
35
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
36
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" size="30" type="password" />}
|
|
37
|
-
end
|
|
38
|
-
assert_equal expected, output_buffer
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def test_file_field
|
|
42
|
-
form_for(@post, :validate => true) do |f|
|
|
43
|
-
concat f.file_field(:cost)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
47
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators, :file => true) do
|
|
48
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" type="file" />}
|
|
49
|
-
end
|
|
50
|
-
assert_equal expected, output_buffer
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def test_text_area
|
|
54
|
-
form_for(@post, :validate => true) do |f|
|
|
55
|
-
concat f.text_area(:cost)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
59
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
60
|
-
%{<textarea cols="40" data-validate="true" id="post_cost" name="post[cost]" rows="20"></textarea>}
|
|
61
|
-
end
|
|
62
|
-
assert_equal expected, output_buffer
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def test_search_field
|
|
66
|
-
form_for(@post, :validate => true) do |f|
|
|
67
|
-
concat f.search_field(:cost)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
71
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
72
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" size="30" type="search" />}
|
|
73
|
-
end
|
|
74
|
-
assert_equal expected, output_buffer
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def test_telephone_field
|
|
78
|
-
form_for(@post, :validate => true) do |f|
|
|
79
|
-
concat f.telephone_field(:cost)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
83
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
84
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" size="30" type="tel" />}
|
|
85
|
-
end
|
|
86
|
-
assert_equal expected, output_buffer
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def test_phone_field
|
|
90
|
-
form_for(@post, :validate => true) do |f|
|
|
91
|
-
concat f.phone_field(:cost)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
95
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
96
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" size="30" type="tel" />}
|
|
97
|
-
end
|
|
98
|
-
assert_equal expected, output_buffer
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def test_url_field
|
|
102
|
-
form_for(@post, :validate => true) do |f|
|
|
103
|
-
concat f.url_field(:cost)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
107
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
108
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" size="30" type="url" />}
|
|
109
|
-
end
|
|
110
|
-
assert_equal expected, output_buffer
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def test_email_field
|
|
114
|
-
form_for(@post, :validate => true) do |f|
|
|
115
|
-
concat f.email_field(:cost)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
119
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
120
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" size="30" type="email" />}
|
|
121
|
-
end
|
|
122
|
-
assert_equal expected, output_buffer
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def test_number_field
|
|
126
|
-
form_for(@post, :validate => true) do |f|
|
|
127
|
-
concat f.number_field(:cost)
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
131
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
132
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" size="30" type="number" />}
|
|
133
|
-
end
|
|
134
|
-
assert_equal expected, output_buffer
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def test_range_field
|
|
138
|
-
form_for(@post, :validate => true) do |f|
|
|
139
|
-
concat f.range_field(:cost)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
143
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
144
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" size="30" type="range" />}
|
|
145
|
-
end
|
|
146
|
-
assert_equal expected, output_buffer
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def test_check_box
|
|
150
|
-
form_for(@post, :validate => true) do |f|
|
|
151
|
-
concat f.check_box(:cost)
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
155
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
156
|
-
%{<input name="post[cost]" type="hidden" value="0" />} +
|
|
157
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" type="checkbox" value="1" />}
|
|
158
|
-
end
|
|
159
|
-
assert_equal expected, output_buffer
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
def test_radio_button
|
|
163
|
-
form_for(@post, :validate => true) do |f|
|
|
164
|
-
concat f.radio_button(:cost, "10")
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
168
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
169
|
-
%{<input data-validate="true" id="post_cost_10" name="post[cost]" type="radio" value="10" />}
|
|
170
|
-
end
|
|
171
|
-
assert_equal expected, output_buffer
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
def test_field_without_validations
|
|
175
|
-
form_for(@post, :validate => true) do |f|
|
|
176
|
-
concat f.text_field(:title)
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => {}) do
|
|
180
|
-
%{<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />}
|
|
181
|
-
end
|
|
182
|
-
assert_equal expected, output_buffer
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
def test_text_field_with_validations_turned_off
|
|
186
|
-
form_for(@post, :validate => true) do |f|
|
|
187
|
-
concat f.text_field(:cost, :validate => false)
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => {}) do
|
|
191
|
-
%{<input id="post_cost" name="post[cost]" size="30" type="text" />}
|
|
192
|
-
end
|
|
193
|
-
assert_equal expected, output_buffer
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def test_nested_fields_for_inherit_validation_settings
|
|
197
|
-
form_for(@post, :validate => true) do |f|
|
|
198
|
-
concat f.fields_for(:comment, @comment) { |c|
|
|
199
|
-
concat c.text_field(:title)
|
|
200
|
-
}
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
validators = {'post[comment][title]' => {:presence => {:message => "can't be blank"}}}
|
|
204
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
205
|
-
%{<input data-validate="true" id="post_comment_title" name="post[comment][title]" size="30" type="text" />}
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
assert_equal expected, output_buffer
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def test_nested_fields_for_dont_overwrite_validation_with_inheritance
|
|
212
|
-
form_for(@post, :validate => true) do |f|
|
|
213
|
-
concat f.fields_for(:comment, @comment, :validate => false) { |c|
|
|
214
|
-
concat c.text_field(:title)
|
|
215
|
-
}
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => {}) do
|
|
219
|
-
%{<input id="post_comment_title" name="post[comment][title]" size="30" type="text" />}
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
assert_equal expected, output_buffer
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
def test_with_custom_id_for_form
|
|
226
|
-
form_for(@post, :validate => true, :html => { :id => 'some_form' }) do |f|
|
|
227
|
-
concat f.text_field(:cost)
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
231
|
-
expected = whole_form("/posts/123", "some_form", "edit_post", :method => "put", :validators => validators) do
|
|
232
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" size="30" type="text" />}
|
|
233
|
-
end
|
|
234
|
-
assert_equal expected, output_buffer
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
def test_ignore_an_individual_validator
|
|
238
|
-
hash = {
|
|
239
|
-
:cost => {
|
|
240
|
-
:presence => {
|
|
241
|
-
:message => "can't be blank"
|
|
242
|
-
},
|
|
243
|
-
:format => {
|
|
244
|
-
:with => /.+/,
|
|
245
|
-
:message => "is invalid"
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
@post.stubs(:client_side_validation_hash).returns(hash)
|
|
250
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
251
|
-
form_for(@post, :validate => true) do |f|
|
|
252
|
-
concat f.text_field(:cost, :validate => { :format => false })
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
256
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
257
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" size="30" type="text" />}
|
|
258
|
-
end
|
|
259
|
-
assert_equal expected, output_buffer
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
def test_ignore_many_validators
|
|
263
|
-
hash = {
|
|
264
|
-
:cost => {
|
|
265
|
-
:presence => {
|
|
266
|
-
:message => "can't be blank"
|
|
267
|
-
},
|
|
268
|
-
:format => {
|
|
269
|
-
:with => /.+/,
|
|
270
|
-
:message => "is invalid"
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
@post.stubs(:client_side_validation_hash).returns(hash)
|
|
275
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
276
|
-
form_for(@post, :validate => true) do |f|
|
|
277
|
-
concat f.text_field(:cost, :validate => { :presence => false, :format => false })
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
validators = {}
|
|
281
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
282
|
-
%{<input id="post_cost" name="post[cost]" size="30" type="text" />}
|
|
283
|
-
end
|
|
284
|
-
assert_equal expected, output_buffer
|
|
285
|
-
end
|
|
286
|
-
|
|
287
|
-
def test_select
|
|
288
|
-
form_for(@post, :validate => true) do |f|
|
|
289
|
-
concat f.select(:cost, [])
|
|
290
|
-
end
|
|
291
|
-
|
|
292
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
293
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
294
|
-
%{<select data-validate="true" id="post_cost" name="post[cost]"></select>}
|
|
295
|
-
end
|
|
296
|
-
assert_equal expected, output_buffer
|
|
297
|
-
end
|
|
298
|
-
|
|
299
|
-
def test_select_multiple
|
|
300
|
-
form_for(@post, :validate => true) do |f|
|
|
301
|
-
concat f.select(:cost, [], {}, :multiple => true)
|
|
302
|
-
end
|
|
303
|
-
|
|
304
|
-
validators = {'post[cost][]' => {:presence => {:message => "can't be blank"}}}
|
|
305
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
306
|
-
%{<select data-validate="true" id="post_cost" multiple="multiple" name="post[cost][]"></select>}
|
|
307
|
-
end
|
|
308
|
-
assert_equal expected, output_buffer
|
|
309
|
-
end
|
|
310
|
-
|
|
311
|
-
def test_collection_select
|
|
312
|
-
form_for(@post, :validate => true) do |f|
|
|
313
|
-
concat f.collection_select(:cost, [], :id, :name)
|
|
314
|
-
end
|
|
315
|
-
|
|
316
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
317
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
318
|
-
%{<select data-validate="true" id="post_cost" name="post[cost]"></select>}
|
|
319
|
-
end
|
|
320
|
-
assert_equal expected, output_buffer
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
def test_grouped_collection_select
|
|
324
|
-
form_for(@post, :validate => true) do |f|
|
|
325
|
-
concat f.grouped_collection_select(:cost, [], :group_method, :group_label_method, :id, :name)
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
329
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
330
|
-
%{<select data-validate="true" id="post_cost" name="post[cost]"></select>}
|
|
331
|
-
end
|
|
332
|
-
assert_equal expected, output_buffer
|
|
333
|
-
end
|
|
334
|
-
|
|
335
|
-
def test_time_zone_select
|
|
336
|
-
zones = mock('TimeZones')
|
|
337
|
-
zones.stubs(:all).returns([])
|
|
338
|
-
form_for(@post, :validate => true) do |f|
|
|
339
|
-
concat f.time_zone_select(:cost, nil, :model => zones)
|
|
340
|
-
end
|
|
341
|
-
|
|
342
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
343
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
344
|
-
%{<select data-validate="true" id="post_cost" name="post[cost]"></select>}
|
|
345
|
-
end
|
|
346
|
-
assert_equal expected, output_buffer
|
|
347
|
-
end
|
|
348
|
-
|
|
349
|
-
def test_conditional_validator_filters
|
|
350
|
-
hash = {
|
|
351
|
-
:cost => {
|
|
352
|
-
:presence => {
|
|
353
|
-
:message => "can't be blank",
|
|
354
|
-
:unless => :cannot_validate?
|
|
355
|
-
}
|
|
356
|
-
},
|
|
357
|
-
:title => {
|
|
358
|
-
:presence => {
|
|
359
|
-
:message => "can't be blank",
|
|
360
|
-
:if => :can_validate?
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
@post.title = nil
|
|
366
|
-
@post.stubs(:cannot_validate?).returns(false)
|
|
367
|
-
@post.stubs(:can_validate?).returns(true)
|
|
368
|
-
@post.stubs(:client_side_validation_hash).returns(hash)
|
|
369
|
-
form_for(@post, :validate => true) do |f|
|
|
370
|
-
concat f.text_field(:cost)
|
|
371
|
-
concat f.text_field(:title)
|
|
372
|
-
end
|
|
373
|
-
|
|
374
|
-
validators = {}
|
|
375
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
376
|
-
%{<input id="post_cost" name="post[cost]" size="30" type="text" />} +
|
|
377
|
-
%{<input id="post_title" name="post[title]" size="30" type="text" />}
|
|
378
|
-
end
|
|
379
|
-
assert_equal expected, output_buffer
|
|
380
|
-
end
|
|
381
|
-
|
|
382
|
-
def test_conditional_validators_should_be_filtered
|
|
383
|
-
hash = {
|
|
384
|
-
:cost => {
|
|
385
|
-
:presence => {
|
|
386
|
-
:message => "can't be blank",
|
|
387
|
-
:unless => :cannot_validate?
|
|
388
|
-
}
|
|
389
|
-
},
|
|
390
|
-
:title => {
|
|
391
|
-
:presence => {
|
|
392
|
-
:message => "can't be blank",
|
|
393
|
-
:if => :can_validate?
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
@post.title = nil
|
|
399
|
-
@post.stubs(:cannot_validate?).returns(false)
|
|
400
|
-
@post.stubs(:can_validate?).returns(true)
|
|
401
|
-
@post.stubs(:client_side_validation_hash).returns(hash)
|
|
402
|
-
form_for(@post, :validate => true) do |f|
|
|
403
|
-
concat f.text_field(:cost)
|
|
404
|
-
concat f.text_field(:title)
|
|
405
|
-
end
|
|
406
|
-
|
|
407
|
-
validators = {}
|
|
408
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
409
|
-
%{<input id="post_cost" name="post[cost]" size="30" type="text" />} +
|
|
410
|
-
%{<input id="post_title" name="post[title]" size="30" type="text" />}
|
|
411
|
-
end
|
|
412
|
-
assert_equal expected, output_buffer
|
|
413
|
-
end
|
|
414
|
-
|
|
415
|
-
def test_conditional_validator_filters_being_forced
|
|
416
|
-
hash = {
|
|
417
|
-
:cost => {
|
|
418
|
-
:presence => {
|
|
419
|
-
:message => "can't be blank",
|
|
420
|
-
:unless => :cannot_validate?
|
|
421
|
-
}
|
|
422
|
-
},
|
|
423
|
-
:title => {
|
|
424
|
-
:presence => {
|
|
425
|
-
:message => "can't be blank",
|
|
426
|
-
:if => :can_validate?
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
@post.title = nil
|
|
432
|
-
@post.stubs(:cannot_validate?).returns(false)
|
|
433
|
-
@post.stubs(:can_validate?).returns(true)
|
|
434
|
-
@post.stubs(:client_side_validation_hash).returns(hash)
|
|
435
|
-
form_for(@post, :validate => true) do |f|
|
|
436
|
-
concat f.text_field(:cost, :validate => true)
|
|
437
|
-
concat f.text_field(:title, :validate => true)
|
|
438
|
-
end
|
|
439
|
-
|
|
440
|
-
validators = {
|
|
441
|
-
'post[cost]' => {:presence => {:message => "can't be blank"}},
|
|
442
|
-
'post[title]' => {:presence => {:message => "can't be blank"}}
|
|
443
|
-
}
|
|
444
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
445
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" size="30" type="text" />} +
|
|
446
|
-
%{<input data-validate="true" id="post_title" name="post[title]" size="30" type="text" />}
|
|
447
|
-
end
|
|
448
|
-
assert_equal expected, output_buffer
|
|
449
|
-
end
|
|
450
|
-
|
|
451
|
-
def test_conditional_validator_filters_being_forced_and_not_meeting_condition
|
|
452
|
-
hash = {
|
|
453
|
-
:cost => {
|
|
454
|
-
:presence => {
|
|
455
|
-
:message => "can't be blank",
|
|
456
|
-
:unless => :cannot_validate?
|
|
457
|
-
}
|
|
458
|
-
},
|
|
459
|
-
:title => {
|
|
460
|
-
:presence => {
|
|
461
|
-
:message => "can't be blank",
|
|
462
|
-
:if => :can_validate?
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
@post.title = nil
|
|
468
|
-
@post.stubs(:cannot_validate?).returns(true)
|
|
469
|
-
@post.stubs(:can_validate?).returns(false)
|
|
470
|
-
@post.stubs(:client_side_validation_hash).returns(hash)
|
|
471
|
-
form_for(@post, :validate => true) do |f|
|
|
472
|
-
concat f.text_field(:cost, :validate => true)
|
|
473
|
-
concat f.text_field(:title, :validate => true)
|
|
474
|
-
end
|
|
475
|
-
|
|
476
|
-
validators = {}
|
|
477
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
478
|
-
%{<input id="post_cost" name="post[cost]" size="30" type="text" />} +
|
|
479
|
-
%{<input id="post_title" name="post[title]" size="30" type="text" />}
|
|
480
|
-
end
|
|
481
|
-
assert_equal expected, output_buffer
|
|
482
|
-
end
|
|
483
|
-
|
|
484
|
-
def test_conditional_validator_filters_being_forced_individually
|
|
485
|
-
hash = {
|
|
486
|
-
:cost => {
|
|
487
|
-
:presence => {
|
|
488
|
-
:message => "can't be blank",
|
|
489
|
-
:unless => :cannot_validate?
|
|
490
|
-
}
|
|
491
|
-
},
|
|
492
|
-
:title => {
|
|
493
|
-
:presence => {
|
|
494
|
-
:message => "can't be blank",
|
|
495
|
-
:if => :can_validate?
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
@post.title = nil
|
|
501
|
-
@post.stubs(:cannot_validate?).returns(false)
|
|
502
|
-
@post.stubs(:can_validate?).returns(true)
|
|
503
|
-
@post.stubs(:client_side_validation_hash).returns(hash)
|
|
504
|
-
form_for(@post, :validate => true) do |f|
|
|
505
|
-
concat f.text_field(:cost, :validate => { :presence => true })
|
|
506
|
-
concat f.text_field(:title, :validate => { :presence => true })
|
|
507
|
-
end
|
|
508
|
-
|
|
509
|
-
validators = {
|
|
510
|
-
'post[cost]' => {:presence => {:message => "can't be blank"}},
|
|
511
|
-
'post[title]' => {:presence => {:message => "can't be blank"}}
|
|
512
|
-
}
|
|
513
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
514
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" size="30" type="text" />} +
|
|
515
|
-
%{<input data-validate="true" id="post_title" name="post[title]" size="30" type="text" />}
|
|
516
|
-
end
|
|
517
|
-
assert_equal expected, output_buffer
|
|
518
|
-
end
|
|
519
|
-
|
|
520
|
-
def test_conditional_validator_filters_being_forced_and_not_meeting_condition_individually
|
|
521
|
-
hash = {
|
|
522
|
-
:cost => {
|
|
523
|
-
:presence => {
|
|
524
|
-
:message => "can't be blank",
|
|
525
|
-
:unless => :cannot_validate?
|
|
526
|
-
}
|
|
527
|
-
},
|
|
528
|
-
:title => {
|
|
529
|
-
:presence => {
|
|
530
|
-
:message => "can't be blank",
|
|
531
|
-
:if => :can_validate?
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
@post.title = nil
|
|
537
|
-
@post.stubs(:cannot_validate?).returns(true)
|
|
538
|
-
@post.stubs(:can_validate?).returns(false)
|
|
539
|
-
@post.stubs(:client_side_validation_hash).returns(hash)
|
|
540
|
-
form_for(@post, :validate => true) do |f|
|
|
541
|
-
concat f.text_field(:cost, :validate => { :presence => true })
|
|
542
|
-
concat f.text_field(:title, :validate => { :presence => true })
|
|
543
|
-
end
|
|
544
|
-
|
|
545
|
-
validators = {}
|
|
546
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
547
|
-
%{<input id="post_cost" name="post[cost]" size="30" type="text" />} +
|
|
548
|
-
%{<input id="post_title" name="post[title]" size="30" type="text" />}
|
|
549
|
-
end
|
|
550
|
-
assert_equal expected, output_buffer
|
|
551
|
-
end
|
|
552
|
-
|
|
553
|
-
def test_conditional_validator_filters_being_forced_with_procs
|
|
554
|
-
hash = {
|
|
555
|
-
:cost => {
|
|
556
|
-
:presence => {
|
|
557
|
-
:message => "can't be blank",
|
|
558
|
-
:unless => Proc.new { |post| post.cannot_validate? }
|
|
559
|
-
}
|
|
560
|
-
},
|
|
561
|
-
:title => {
|
|
562
|
-
:presence => {
|
|
563
|
-
:message => "can't be blank",
|
|
564
|
-
:if => Proc.new { |post| post.can_validate? }
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
@post.title = nil
|
|
570
|
-
@post.stubs(:cannot_validate?).returns(false)
|
|
571
|
-
@post.stubs(:can_validate?).returns(true)
|
|
572
|
-
@post.stubs(:client_side_validation_hash).returns(hash)
|
|
573
|
-
form_for(@post, :validate => true) do |f|
|
|
574
|
-
concat f.text_field(:cost, :validate => true)
|
|
575
|
-
concat f.text_field(:title, :validate => true)
|
|
576
|
-
end
|
|
577
|
-
|
|
578
|
-
validators = {
|
|
579
|
-
'post[cost]' => {:presence => {:message => "can't be blank"}},
|
|
580
|
-
'post[title]' => {:presence => {:message => "can't be blank"}}
|
|
581
|
-
}
|
|
582
|
-
expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => "put", :validators => validators) do
|
|
583
|
-
%{<input data-validate="true" id="post_cost" name="post[cost]" size="30" type="text" />} +
|
|
584
|
-
%{<input data-validate="true" id="post_title" name="post[title]" size="30" type="text" />}
|
|
585
|
-
end
|
|
586
|
-
assert_equal expected, output_buffer
|
|
587
|
-
end
|
|
588
|
-
|
|
589
|
-
def test_pushing_script_to_content_for
|
|
590
|
-
form_for(@post, :validate => :post) do |f|
|
|
591
|
-
concat f.text_field(:cost)
|
|
592
|
-
end
|
|
593
|
-
|
|
594
|
-
validators = {'post[cost]' => {:presence => {:message => "can't be blank"}}}
|
|
595
|
-
expected = %{<form accept-charset="UTF-8" action="/posts/123" class="edit_post" data-validate="true" id="edit_post_123" method="post" novalidate="novalidate"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="put" /></div><input data-validate="true" id="post_cost" name="post[cost]" size="30" type="text" /></form>}
|
|
596
|
-
assert_equal expected, output_buffer
|
|
597
|
-
assert_equal build_script_tag(nil, "edit_post_123", validators), content_for(:post)
|
|
598
|
-
end
|
|
599
|
-
end
|
|
600
|
-
|