af-client_side_validations 3.1.4.af1
Sign up to get free protection for your applications and to get access to all the features.
- data/client_side_validations.gemspec +34 -0
- data/lib/client_side_validations/action_view/form_builder.rb +160 -0
- data/lib/client_side_validations/action_view/form_helper.rb +92 -0
- data/lib/client_side_validations/action_view/form_tag_helper.rb +12 -0
- data/lib/client_side_validations/action_view.rb +14 -0
- data/lib/client_side_validations/active_model/acceptance.rb +10 -0
- data/lib/client_side_validations/active_model/exclusion.rb +15 -0
- data/lib/client_side_validations/active_model/format.rb +10 -0
- data/lib/client_side_validations/active_model/inclusion.rb +15 -0
- data/lib/client_side_validations/active_model/length.rb +24 -0
- data/lib/client_side_validations/active_model/numericality.rb +31 -0
- data/lib/client_side_validations/active_model/presence.rb +10 -0
- data/lib/client_side_validations/active_model.rb +60 -0
- data/lib/client_side_validations/active_record/middleware.rb +33 -0
- data/lib/client_side_validations/active_record/uniqueness.rb +28 -0
- data/lib/client_side_validations/active_record.rb +11 -0
- data/lib/client_side_validations/core_ext/range.rb +10 -0
- data/lib/client_side_validations/core_ext/regexp.rb +14 -0
- data/lib/client_side_validations/core_ext.rb +3 -0
- data/lib/client_side_validations/engine.rb +6 -0
- data/lib/client_side_validations/files.rb +8 -0
- data/lib/client_side_validations/formtastic.rb +21 -0
- data/lib/client_side_validations/middleware.rb +81 -0
- data/lib/client_side_validations/mongo_mapper/middleware.rb +20 -0
- data/lib/client_side_validations/mongo_mapper/uniqueness.rb +28 -0
- data/lib/client_side_validations/mongo_mapper.rb +9 -0
- data/lib/client_side_validations/mongoid/middleware.rb +20 -0
- data/lib/client_side_validations/mongoid/uniqueness.rb +28 -0
- data/lib/client_side_validations/mongoid.rb +9 -0
- data/lib/client_side_validations/simple_form.rb +24 -0
- data/lib/client_side_validations/version.rb +3 -0
- data/lib/client_side_validations.rb +13 -0
- data/lib/generators/client_side_validations/copy_asset_generator.rb +36 -0
- data/lib/generators/client_side_validations/install_generator.rb +45 -0
- data/lib/generators/templates/client_side_validations/README.rails.3.0 +6 -0
- data/lib/generators/templates/client_side_validations/README.rails.3.1 +7 -0
- data/lib/generators/templates/client_side_validations/initializer.rb +14 -0
- data/test/action_view/cases/helper.rb +176 -0
- data/test/action_view/cases/test_helpers.rb +666 -0
- data/test/action_view/cases/test_legacy_helpers.rb +217 -0
- data/test/action_view/models/comment.rb +35 -0
- data/test/action_view/models/post.rb +35 -0
- data/test/action_view/models.rb +3 -0
- data/test/active_model/cases/helper.rb +4 -0
- data/test/active_model/cases/test_acceptance_validator.rb +16 -0
- data/test/active_model/cases/test_base.rb +11 -0
- data/test/active_model/cases/test_confirmation_validator.rb +16 -0
- data/test/active_model/cases/test_exclusion_validator.rb +20 -0
- data/test/active_model/cases/test_format_validator.rb +21 -0
- data/test/active_model/cases/test_inclusion_validator.rb +21 -0
- data/test/active_model/cases/test_length_validator.rb +61 -0
- data/test/active_model/cases/test_numericality_validator.rb +46 -0
- data/test/active_model/cases/test_presence_validator.rb +16 -0
- data/test/active_model/cases/test_validations.rb +175 -0
- data/test/active_model/models/person.rb +17 -0
- data/test/active_record/cases/helper.rb +12 -0
- data/test/active_record/cases/test_base.rb +11 -0
- data/test/active_record/cases/test_middleware.rb +175 -0
- data/test/active_record/cases/test_uniqueness_validator.rb +50 -0
- data/test/active_record/models/guid.rb +7 -0
- data/test/active_record/models/user.rb +14 -0
- data/test/base_helper.rb +7 -0
- data/test/core_ext/cases/test_core_ext.rb +46 -0
- data/test/formtastic/cases/helper.rb +7 -0
- data/test/formtastic/cases/test_form_builder.rb +11 -0
- data/test/formtastic/cases/test_form_helper.rb +21 -0
- data/test/generators/cases/test_generators.rb +70 -0
- data/test/javascript/config.ru +3 -0
- data/test/javascript/public/test/callbacks/elementAfter.js +54 -0
- data/test/javascript/public/test/callbacks/elementBefore.js +54 -0
- data/test/javascript/public/test/callbacks/elementFail.js +70 -0
- data/test/javascript/public/test/callbacks/elementPass.js +70 -0
- data/test/javascript/public/test/callbacks/formAfter.js +45 -0
- data/test/javascript/public/test/callbacks/formBefore.js +45 -0
- data/test/javascript/public/test/callbacks/formFail.js +51 -0
- data/test/javascript/public/test/callbacks/formPass.js +50 -0
- data/test/javascript/public/test/form_builders/validateForm.js +66 -0
- data/test/javascript/public/test/form_builders/validateFormtastic.js +54 -0
- data/test/javascript/public/test/form_builders/validateNestedForm.js +66 -0
- data/test/javascript/public/test/form_builders/validateSimpleForm.js +57 -0
- data/test/javascript/public/test/settings.js +15 -0
- data/test/javascript/public/test/validateElement.js +209 -0
- data/test/javascript/public/test/validators/acceptance.js +42 -0
- data/test/javascript/public/test/validators/confirmation.js +25 -0
- data/test/javascript/public/test/validators/exclusion.js +41 -0
- data/test/javascript/public/test/validators/format.js +27 -0
- data/test/javascript/public/test/validators/inclusion.js +42 -0
- data/test/javascript/public/test/validators/length.js +76 -0
- data/test/javascript/public/test/validators/numericality.js +158 -0
- data/test/javascript/public/test/validators/presence.js +21 -0
- data/test/javascript/public/test/validators/uniqueness.js +107 -0
- data/test/javascript/public/vendor/jquery.metadata.js +122 -0
- data/test/javascript/public/vendor/qunit.css +196 -0
- data/test/javascript/public/vendor/qunit.js +1374 -0
- data/test/javascript/server.rb +84 -0
- data/test/javascript/views/index.erb +20 -0
- data/test/javascript/views/layout.erb +21 -0
- data/test/middleware/cases/helper.rb +18 -0
- data/test/middleware/cases/test_middleware.rb +8 -0
- data/test/mongo_mapper/cases/helper.rb +9 -0
- data/test/mongo_mapper/cases/test_base.rb +15 -0
- data/test/mongo_mapper/cases/test_middleware.rb +77 -0
- data/test/mongo_mapper/cases/test_uniqueness_validator.rb +50 -0
- data/test/mongo_mapper/models/magazine.rb +11 -0
- data/test/mongoid/cases/helper.rb +16 -0
- data/test/mongoid/cases/test_base.rb +15 -0
- data/test/mongoid/cases/test_middleware.rb +77 -0
- data/test/mongoid/cases/test_uniqueness_validator.rb +49 -0
- data/test/mongoid/models/book.rb +12 -0
- data/test/simple_form/cases/helper.rb +5 -0
- data/test/simple_form/cases/test_form_builder.rb +14 -0
- data/test/simple_form/cases/test_form_helper.rb +24 -0
- data/test/test_loader.rb +6 -0
- data/vendor/assets/javascripts/rails.validations.js +418 -0
- metadata +436 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
module('Validate SimpleForm', {
|
2
|
+
setup: function() {
|
3
|
+
window['new_user'] = {
|
4
|
+
type: 'SimpleForm::FormBuilder',
|
5
|
+
error_class: 'error',
|
6
|
+
error_tag: 'span',
|
7
|
+
wrapper_error_class: 'field_with_errors',
|
8
|
+
wrapper_tag: 'div',
|
9
|
+
validators: {
|
10
|
+
"user[name]":{"presence":{"message": "must be present"}, "format":{"message":"is invalid","with":/\d+/}}
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
$('#qunit-fixture')
|
15
|
+
.append($('<form />', {
|
16
|
+
action: '/users',
|
17
|
+
'data-validate': true,
|
18
|
+
method: 'post',
|
19
|
+
id: 'new_user'
|
20
|
+
}))
|
21
|
+
.find('form')
|
22
|
+
.append('<div />').find('div')
|
23
|
+
.append($('<input />', {
|
24
|
+
name: 'user[name]',
|
25
|
+
id: 'user_name',
|
26
|
+
'data-validate': 'true',
|
27
|
+
type: 'text'
|
28
|
+
}))
|
29
|
+
.append($('<label for="user_name">Name</label>'));
|
30
|
+
$('form#new_user').validate();
|
31
|
+
}
|
32
|
+
});
|
33
|
+
|
34
|
+
test('Validate error attaching and detaching', function() {
|
35
|
+
var form = $('form#new_user'), input = form.find('input#user_name');
|
36
|
+
var label = $('label[for="user_name"]');
|
37
|
+
|
38
|
+
input.trigger('focusout');
|
39
|
+
ok(input.parent().hasClass('field_with_errors'));
|
40
|
+
ok(label.parent().hasClass('field_with_errors'));
|
41
|
+
ok(input.parent().find('span.error:contains("must be present")')[0]);
|
42
|
+
|
43
|
+
input.val('abc')
|
44
|
+
input.trigger('change')
|
45
|
+
input.trigger('focusout')
|
46
|
+
ok(input.parent().hasClass('field_with_errors'));
|
47
|
+
ok(label.parent().hasClass('field_with_errors'));
|
48
|
+
ok(input.parent().find('span.error:contains("is invalid")')[0]);
|
49
|
+
|
50
|
+
input.val('123')
|
51
|
+
input.trigger('change')
|
52
|
+
input.trigger('focusout')
|
53
|
+
ok(!input.parent().hasClass('field_with_errors'));
|
54
|
+
ok(!label.parent().hasClass('field_with_errors'));
|
55
|
+
ok(!input.parent().find('span.error')[0]);
|
56
|
+
});
|
57
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// hijacks normal form submit; lets it submit to an iframe to prevent
|
2
|
+
// navigating away from the test suite
|
3
|
+
$(document).bind('submit', function(e) {
|
4
|
+
if (!e.isDefaultPrevented()) {
|
5
|
+
var form = $(e.target), action = form.attr('action'),
|
6
|
+
name = 'form-frame' + jQuery.guid++,
|
7
|
+
iframe = $('<iframe name="' + name + '" />');
|
8
|
+
|
9
|
+
if (action.indexOf('iframe') < 0) form.attr('action', action + '?iframe=true')
|
10
|
+
form.attr('target', name);
|
11
|
+
$('#qunit-fixture').append(iframe);
|
12
|
+
form.trigger('iframe:loading');
|
13
|
+
}
|
14
|
+
});
|
15
|
+
|
@@ -0,0 +1,209 @@
|
|
1
|
+
module('Validate Element', {
|
2
|
+
setup: function() {
|
3
|
+
window['new_user'] = {
|
4
|
+
type: 'ActionView::Helpers::FormBuilder',
|
5
|
+
input_tag: '<div class="field_with_errors"><span id="input_tag" /><label for="user_name" class="message"></label></div>',
|
6
|
+
label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
|
7
|
+
validators: {
|
8
|
+
'user[name]':{"presence":{"message": "must be present"}, "format":{"message":"is invalid","with":/\d+/}},
|
9
|
+
'user[password]':{"confirmation":{"message": "must match confirmation"}},
|
10
|
+
'user[agree]':{"acceptance": {"message": "must be accepted"}},
|
11
|
+
'user[email]':{"uniqueness":{"message": "must be unique"},"presence":{"message": "must be present"}},
|
12
|
+
'user[phone_numbers_attributes][][number]':{"presence":{"message": "must be present"}}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
$('#qunit-fixture')
|
17
|
+
.append($('<form />', {
|
18
|
+
action: '/users',
|
19
|
+
'data-validate': true,
|
20
|
+
method: 'post',
|
21
|
+
id: 'new_user'
|
22
|
+
}))
|
23
|
+
.find('form')
|
24
|
+
.append($('<label for="user_name">Name</label>'))
|
25
|
+
.append($('<input />', {
|
26
|
+
name: 'user[name]',
|
27
|
+
id: 'user_name',
|
28
|
+
'data-validate': 'true',
|
29
|
+
type: 'text'
|
30
|
+
}))
|
31
|
+
.append($('<label for="user_password">Password</label>'))
|
32
|
+
.append($('<input />', {
|
33
|
+
name: 'user[password]',
|
34
|
+
id: 'user_password',
|
35
|
+
'data-validate': 'true',
|
36
|
+
type: 'password'
|
37
|
+
}))
|
38
|
+
.append($('<label for="user_password_confirmation">Password Confirmation</label>'))
|
39
|
+
.append($('<input />', {
|
40
|
+
name: 'user[password_confirmation]',
|
41
|
+
id: 'user_password_confirmation',
|
42
|
+
type: 'password'
|
43
|
+
}))
|
44
|
+
.append($('<label for="user_agree">Agree</label>'))
|
45
|
+
.append($('<input />', {
|
46
|
+
name: 'user[agree]',
|
47
|
+
id: 'user_agree',
|
48
|
+
'data-validate': 'true',
|
49
|
+
type: 'checkbox',
|
50
|
+
value: 1
|
51
|
+
}))
|
52
|
+
.append($('<input />', {
|
53
|
+
name: 'user[email]',
|
54
|
+
id: 'user_email',
|
55
|
+
'data-validate': 'true',
|
56
|
+
type: 'text'
|
57
|
+
}))
|
58
|
+
.append($('<label for="user_phone_numbers_attributes_0_number">Phone Number</label>'))
|
59
|
+
.append($('<input />', {
|
60
|
+
name: 'user[phone_numbers_attributes][0][number]',
|
61
|
+
id: 'user_phone_numbers_attributes_0_number',
|
62
|
+
'data-validate': 'true',
|
63
|
+
type: 'text'
|
64
|
+
}))
|
65
|
+
.append($('<label for="user_phone_numbers_attributes_1_number">Phone Number</label>'))
|
66
|
+
.append($('<input />', {
|
67
|
+
name: 'user[phone_numbers_attributes][1][number]',
|
68
|
+
id: 'user_phone_numbers_attributes_1_number',
|
69
|
+
'data-validate': 'true',
|
70
|
+
type: 'text'
|
71
|
+
}))
|
72
|
+
$('form#new_user').validate();
|
73
|
+
}
|
74
|
+
});
|
75
|
+
|
76
|
+
test('Validate when focusouting', function() {
|
77
|
+
var form = $('form#new_user'), input = form.find('input#user_name');
|
78
|
+
var label = $('label[for="user_name"]');
|
79
|
+
|
80
|
+
input.trigger('focusout');
|
81
|
+
ok(input.parent().hasClass('field_with_errors'));
|
82
|
+
ok(label.parent().hasClass('field_with_errors'));
|
83
|
+
});
|
84
|
+
|
85
|
+
test('Validate when checkbox is clicked', function() {
|
86
|
+
var form = $('form#new_user'), input = form.find('input#user_agree');
|
87
|
+
var label = $('label[for="user_agree"]');
|
88
|
+
|
89
|
+
input.attr('checked', false)
|
90
|
+
input.trigger('click');
|
91
|
+
ok(input.parent().hasClass('field_with_errors'));
|
92
|
+
ok(label.parent().hasClass('field_with_errors'));
|
93
|
+
});
|
94
|
+
|
95
|
+
test('Validate when focusout on confirmation', function() {
|
96
|
+
var form = $('form#new_user'), password = form.find('input#user_password'), confirmation = form.find('input#user_password_confirmation');
|
97
|
+
var label = $('label[for="user_password"]');
|
98
|
+
|
99
|
+
password.val('password');
|
100
|
+
confirmation.trigger('focusout');
|
101
|
+
ok(password.parent().hasClass('field_with_errors'));
|
102
|
+
ok(label.parent().hasClass('field_with_errors'));
|
103
|
+
});
|
104
|
+
|
105
|
+
test('Validate nested attributes', function() {
|
106
|
+
var form = $('form#new_user'), input, label;
|
107
|
+
|
108
|
+
input = form.find('input#user_phone_numbers_attributes_1_number');
|
109
|
+
label = $('label[for="user_phone_numbers_attributes_1_number"]');
|
110
|
+
input.trigger('focusout');
|
111
|
+
ok(input.parent().hasClass('field_with_errors'));
|
112
|
+
ok(label.parent().hasClass('field_with_errors'));
|
113
|
+
|
114
|
+
input = form.find('input#user_phone_numbers_attributes_0_number');
|
115
|
+
label = $('label[for="user_phone_numbers_attributes_0_number"]');
|
116
|
+
input.trigger('focusout');
|
117
|
+
ok(input.parent().hasClass('field_with_errors'));
|
118
|
+
ok(label.parent().hasClass('field_with_errors'));
|
119
|
+
});
|
120
|
+
|
121
|
+
test('Validate when keyup on confirmation', function() {
|
122
|
+
var form = $('form#new_user'), password = form.find('input#user_password'), confirmation = form.find('input#user_password_confirmation');
|
123
|
+
var label = $('label[for="user_password"]');
|
124
|
+
|
125
|
+
password.val('password');
|
126
|
+
|
127
|
+
confirmation.trigger('keyup');
|
128
|
+
ok(password.parent().hasClass('field_with_errors'));
|
129
|
+
ok(label.parent().hasClass('field_with_errors'));
|
130
|
+
|
131
|
+
confirmation.val('password')
|
132
|
+
confirmation.trigger('keyup');
|
133
|
+
ok(!password.parent().hasClass('field_with_errors'));
|
134
|
+
ok(!label.parent().hasClass('field_with_errors'));
|
135
|
+
});
|
136
|
+
|
137
|
+
test('Forcing remote validators to run last', function() {
|
138
|
+
var form = $('form#new_user'), input = form.find('input#user_email');
|
139
|
+
|
140
|
+
input.trigger('focusout');
|
141
|
+
equal(input.parent().find('label').text(), "must be present")
|
142
|
+
});
|
143
|
+
|
144
|
+
test("Don't validate when value hasn't changed", function() {
|
145
|
+
var form = $('form#new_user'), input = form.find('input#user_name');
|
146
|
+
var label = $('label[for="user_name"]');
|
147
|
+
|
148
|
+
input.trigger('focusout');
|
149
|
+
ok(input.parent().hasClass('field_with_errors'));
|
150
|
+
ok(label.parent().hasClass('field_with_errors'));
|
151
|
+
|
152
|
+
input.val('123');
|
153
|
+
input.trigger('focusout');
|
154
|
+
ok(input.parent().hasClass('field_with_errors'));
|
155
|
+
ok(label.parent().hasClass('field_with_errors'));
|
156
|
+
|
157
|
+
input.trigger('change');
|
158
|
+
input.trigger('focusout');
|
159
|
+
ok(!input.parent().hasClass('field_with_errors'));
|
160
|
+
ok(!label.parent().hasClass('field_with_errors'));
|
161
|
+
});
|
162
|
+
|
163
|
+
test('Validate when error message needs to change', function() {
|
164
|
+
var form = $('form#new_user'), input = form.find('input#user_name');
|
165
|
+
var label = $('label[for="user_name"]');
|
166
|
+
|
167
|
+
input.trigger('focusout');
|
168
|
+
equal(input.parent().find('label.message').text(), "must be present");
|
169
|
+
input.val('abc');
|
170
|
+
input.trigger('change')
|
171
|
+
input.trigger('focusout');
|
172
|
+
equal(input.parent().find('label.message').text(), "is invalid");
|
173
|
+
})
|
174
|
+
|
175
|
+
test("Don't validate confirmation when not a validatable input", function() {
|
176
|
+
$('#qunit-fixture')
|
177
|
+
.append($('<form />', {
|
178
|
+
action: '/users',
|
179
|
+
'data-validate': true,
|
180
|
+
method: 'post',
|
181
|
+
id: 'new_user_2'
|
182
|
+
}))
|
183
|
+
.find('form')
|
184
|
+
.append($('<label for="user_2_password">Password</label>'))
|
185
|
+
.append($('<input />', {
|
186
|
+
name: 'user_2[password]',
|
187
|
+
id: 'user_2_password',
|
188
|
+
type: 'password'
|
189
|
+
}))
|
190
|
+
.append($('<label for="user_2_password_confirmation">Password Confirmation</label>'))
|
191
|
+
.append($('<input />', {
|
192
|
+
name: 'user_2[password_confirmation]',
|
193
|
+
id: 'user_2_password_confirmation',
|
194
|
+
type: 'password'
|
195
|
+
}))
|
196
|
+
new_user_2 = {
|
197
|
+
type: 'ActionView::Helpers::FormBuilder',
|
198
|
+
input_tag: '<div class="field_with_errors"><span id="input_tag" /><label for="user_name" class="message"></label></div>',
|
199
|
+
label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
|
200
|
+
validators: {
|
201
|
+
}
|
202
|
+
}
|
203
|
+
$('form#new_user_2').validate();
|
204
|
+
var form = $('form#new_user_2'), input = form.find('input#user_2_password_confirmation');
|
205
|
+
input.val('123');
|
206
|
+
input.trigger('focusout');
|
207
|
+
ok(!input.parent().hasClass('field_with_errors'));
|
208
|
+
});
|
209
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module('Acceptance options');
|
2
|
+
|
3
|
+
test('when checkbox and checked', function() {
|
4
|
+
var element = $('<input type="checkbox" />');
|
5
|
+
var options = { message: "failed validation" };
|
6
|
+
element.attr('checked', true)
|
7
|
+
equal(clientSideValidations.validators.local.acceptance(element, options), undefined);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('when checkbox and not checked', function() {
|
11
|
+
var element = $('<input type="checkbox" />');
|
12
|
+
var options = { message: "failed validation" };
|
13
|
+
equal(clientSideValidations.validators.local.acceptance(element, options), "failed validation");
|
14
|
+
});
|
15
|
+
|
16
|
+
test('when text and value default of 1', function() {
|
17
|
+
var element = $('<input type="text" />');
|
18
|
+
var options = { message: "failed validation" };
|
19
|
+
element.val("1");
|
20
|
+
equal(clientSideValidations.validators.local.acceptance(element, options), undefined);
|
21
|
+
});
|
22
|
+
|
23
|
+
test('when text and value 2 and accept value is 2', function() {
|
24
|
+
var element = $('<input type="text" />');
|
25
|
+
var options = { message: "failed validation", accept: 1 };
|
26
|
+
element.val("1");
|
27
|
+
equal(clientSideValidations.validators.local.acceptance(element, options), undefined);
|
28
|
+
});
|
29
|
+
|
30
|
+
test('when text and value empty', function() {
|
31
|
+
var element = $('<input type="text" />');
|
32
|
+
var options = { message: "failed validation" };
|
33
|
+
equal(clientSideValidations.validators.local.acceptance(element, options), "failed validation");
|
34
|
+
});
|
35
|
+
|
36
|
+
test('when text and value 1 and accept value is 2', function() {
|
37
|
+
var element = $('<input type="text" />');
|
38
|
+
var options = { message: "failed validation", accept: 2 };
|
39
|
+
element.val("1");
|
40
|
+
equal(clientSideValidations.validators.local.acceptance(element, options), "failed validation");
|
41
|
+
});
|
42
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module('Confirmation options', {
|
2
|
+
setup: function() {
|
3
|
+
$('#qunit-fixture')
|
4
|
+
.append('<input id="password" type="password" />')
|
5
|
+
.append('<input id="password_confirmation" type="password" />')
|
6
|
+
}
|
7
|
+
});
|
8
|
+
|
9
|
+
test('when values match', function() {
|
10
|
+
var password_element = $('#password');
|
11
|
+
var password_confirmation_element = $('#password_confirmation');
|
12
|
+
var options = { message: "failed validation" };
|
13
|
+
password_element.val('test');
|
14
|
+
password_confirmation_element.val('test');
|
15
|
+
equal(clientSideValidations.validators.local.confirmation(password_element, options), undefined);
|
16
|
+
});
|
17
|
+
|
18
|
+
test('when values match', function() {
|
19
|
+
var password_element = $('#password');
|
20
|
+
var password_confirmation_element = $('#password_confirmation');
|
21
|
+
var options = { message: "failed validation" };
|
22
|
+
password_element.val('test');
|
23
|
+
password_confirmation_element.val('bad test');
|
24
|
+
equal(clientSideValidations.validators.local.confirmation(password_element, options), "failed validation");
|
25
|
+
});
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module('Exclusion options');
|
2
|
+
|
3
|
+
test('when value is not in the list', function() {
|
4
|
+
var element = $('<input type="text" />');
|
5
|
+
var options = { 'message': "failed validation", 'in': [1, 2, 3] };
|
6
|
+
element.val('4');
|
7
|
+
equal(clientSideValidations.validators.local.exclusion(element, options), undefined);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('when value is not in the range', function() {
|
11
|
+
var element = $('<input type="text" />');
|
12
|
+
var options = { 'message': "failed validation", 'range': [1, 3] };
|
13
|
+
element.val('4');
|
14
|
+
equal(clientSideValidations.validators.local.exclusion(element, options), undefined);
|
15
|
+
});
|
16
|
+
|
17
|
+
test('when value is in the list', function() {
|
18
|
+
var element = $('<input type="text" />');
|
19
|
+
var options = { 'message': "failed validation", 'in': [1, 2, 3] };
|
20
|
+
element.val('1');
|
21
|
+
equal(clientSideValidations.validators.local.exclusion(element, options), "failed validation");
|
22
|
+
});
|
23
|
+
|
24
|
+
test('when value is in the range', function() {
|
25
|
+
var element = $('<input type="text" />');
|
26
|
+
var options = { 'message': "failed validation", 'range': [1, 3] };
|
27
|
+
element.val('1');
|
28
|
+
equal(clientSideValidations.validators.local.exclusion(element, options), "failed validation");
|
29
|
+
});
|
30
|
+
|
31
|
+
test('when allowing blank', function() {
|
32
|
+
var element = $('<input type="text" />');
|
33
|
+
var options = { 'message': "failed validation", 'in': [1, 2, 3], allow_blank: true };
|
34
|
+
equal(clientSideValidations.validators.local.exclusion(element, options), undefined);
|
35
|
+
});
|
36
|
+
|
37
|
+
test('when not allowing blank', function() {
|
38
|
+
var element = $('<input type="text" />');
|
39
|
+
var options = { 'message': "failed validation", 'in': [1, 2, 3] };
|
40
|
+
equal(clientSideValidations.validators.local.exclusion(element, options), "failed validation");
|
41
|
+
});
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module('Format options');
|
2
|
+
|
3
|
+
test('when matching format', function() {
|
4
|
+
var element = $('<input type="text" />');
|
5
|
+
var options = { 'message': "failed validation", 'with': /\d+/ };
|
6
|
+
element.val('123');
|
7
|
+
equal(clientSideValidations.validators.local.format(element, options), undefined);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('when not matching format', function() {
|
11
|
+
var element = $('<input type="text" />');
|
12
|
+
var options = { 'message': "failed validation", 'with': /\d+/ };
|
13
|
+
element.val('abc');
|
14
|
+
equal(clientSideValidations.validators.local.format(element, options), "failed validation");
|
15
|
+
});
|
16
|
+
|
17
|
+
test('when allowing blank', function() {
|
18
|
+
var element = $('<input type="text" />');
|
19
|
+
var options = { 'message': "failed validation", 'with': /\d+/, 'allow_blank': true };
|
20
|
+
equal(clientSideValidations.validators.local.format(element, options), undefined);
|
21
|
+
});
|
22
|
+
|
23
|
+
test('when not allowing blank', function() {
|
24
|
+
var element = $('<input type="text" />');
|
25
|
+
var options = { 'message': "failed validation", 'with': /\d+/ };
|
26
|
+
equal(clientSideValidations.validators.local.format(element, options), "failed validation");
|
27
|
+
});
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module('Inclusion options');
|
2
|
+
|
3
|
+
test('when value is in the list', function() {
|
4
|
+
var element = $('<input type="text" />');
|
5
|
+
var options = { 'message': "failed validation", 'in': [1, 2, 3] };
|
6
|
+
element.val('1');
|
7
|
+
equal(clientSideValidations.validators.local.inclusion(element, options), undefined);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('when value is in the range', function() {
|
11
|
+
var element = $('<input type="text" />');
|
12
|
+
var options = { 'message': "failed validation", 'range': [1, 3] };
|
13
|
+
element.val('1');
|
14
|
+
equal(clientSideValidations.validators.local.inclusion(element, options), undefined);
|
15
|
+
});
|
16
|
+
|
17
|
+
test('when value is not in the list', function() {
|
18
|
+
var element = $('<input type="text" />');
|
19
|
+
var options = { 'message': "failed validation", 'in': [1, 2, 3] };
|
20
|
+
element.val('4');
|
21
|
+
equal(clientSideValidations.validators.local.inclusion(element, options), "failed validation");
|
22
|
+
});
|
23
|
+
|
24
|
+
test('when value is not in the range', function() {
|
25
|
+
var element = $('<input type="text" />');
|
26
|
+
var options = { 'message': "failed validation", 'range': [1, 3] };
|
27
|
+
element.val('4');
|
28
|
+
equal(clientSideValidations.validators.local.inclusion(element, options), "failed validation");
|
29
|
+
});
|
30
|
+
|
31
|
+
test('when allowing blank', function() {
|
32
|
+
var element = $('<input type="text" />');
|
33
|
+
var options = { 'message': "failed validation", 'in': [1, 2, 3], allow_blank: true };
|
34
|
+
equal(clientSideValidations.validators.local.inclusion(element, options), undefined);
|
35
|
+
});
|
36
|
+
|
37
|
+
test('when not allowing blank', function() {
|
38
|
+
var element = $('<input type="text" />');
|
39
|
+
var options = { 'message': "failed validation", 'in': [1, 2, 3] };
|
40
|
+
equal(clientSideValidations.validators.local.inclusion(element, options), "failed validation");
|
41
|
+
});
|
42
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module('Length options');
|
2
|
+
|
3
|
+
test('when allowed length is 3 and value length is 3', function() {
|
4
|
+
var element = $('<input type="text" />');
|
5
|
+
var options = { messages: { is: "failed validation" }, is: 3 };
|
6
|
+
element.val('123');
|
7
|
+
equal(clientSideValidations.validators.local.length(element, options), undefined);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('when allowed length is 3 and value length is 4', function() {
|
11
|
+
var element = $('<input type="text" />');
|
12
|
+
var options = { messages: { is: "failed validation" }, is: 3 };
|
13
|
+
element.val('1234');
|
14
|
+
equal(clientSideValidations.validators.local.length(element, options), "failed validation");
|
15
|
+
});
|
16
|
+
|
17
|
+
test('when allowed length is 3 and value length is 2', function() {
|
18
|
+
var element = $('<input type="text" />');
|
19
|
+
var options = { messages: { is: "failed validation" }, is: 3 };
|
20
|
+
element.val('12');
|
21
|
+
equal(clientSideValidations.validators.local.length(element, options), "failed validation");
|
22
|
+
});
|
23
|
+
|
24
|
+
test('when allowing blank and allowed length is 3', function() {
|
25
|
+
var element = $('<input type="text" />');
|
26
|
+
var options = { messages: { is: "failed validation" }, is: 3, allow_blank: true };
|
27
|
+
equal(clientSideValidations.validators.local.length(element, options), undefined);
|
28
|
+
});
|
29
|
+
|
30
|
+
test('when allowing blank and minimum length is 3 and maximum length is 100', function() {
|
31
|
+
var element = $('<input type="text" />');
|
32
|
+
var options = { messages: { minimum: "failed minimum validation", maximum: "failed maximum validation" }, minimum: 3, maximum: 100, allow_blank: true };
|
33
|
+
equal(clientSideValidations.validators.local.length(element, options), undefined);
|
34
|
+
});
|
35
|
+
|
36
|
+
test('when not allowing blank and allowed length is 3', function() {
|
37
|
+
var element = $('<input type="text" />');
|
38
|
+
var options = { messages: { is: "failed validation" }, is: 3 };
|
39
|
+
equal(clientSideValidations.validators.local.length(element, options), "failed validation");
|
40
|
+
});
|
41
|
+
|
42
|
+
test('when allowed length is 3 and a differnet tokenizer', function() {
|
43
|
+
var element = $('<input type="text" />');
|
44
|
+
element.val("one two three");
|
45
|
+
var options = { messages: { is: "failed validation" }, is: 3, js_tokenizer: "match(/\\w+/g)" };
|
46
|
+
equal(clientSideValidations.validators.local.length(element, options), undefined);
|
47
|
+
});
|
48
|
+
|
49
|
+
test('when allowed length minimum is 3 and value length is 3', function() {
|
50
|
+
var element = $('<input type="text" />');
|
51
|
+
var options = { messages: { is: "failed validation" }, is: 3 };
|
52
|
+
element.val('123');
|
53
|
+
equal(clientSideValidations.validators.local.length(element, options), undefined);
|
54
|
+
});
|
55
|
+
|
56
|
+
test('when allowed length minimum is 3 and value length is 2', function() {
|
57
|
+
var element = $('<input type="text" />');
|
58
|
+
var options = { messages: { minimum: "failed validation" }, minimum: 3 };
|
59
|
+
element.val('12');
|
60
|
+
equal(clientSideValidations.validators.local.length(element, options), "failed validation");
|
61
|
+
});
|
62
|
+
|
63
|
+
test('when allowed length maximum is 3 and value length is 3', function() {
|
64
|
+
var element = $('<input type="text" />');
|
65
|
+
var options = { messages: { is: "failed validation" }, is: 3 };
|
66
|
+
element.val('123');
|
67
|
+
equal(clientSideValidations.validators.local.length(element, options), undefined);
|
68
|
+
});
|
69
|
+
|
70
|
+
test('when allowed length maximum is 3 and value length is 4', function() {
|
71
|
+
var element = $('<input type="text" />');
|
72
|
+
var options = { messages: { maximum: "failed validation" }, maximum: 3 };
|
73
|
+
element.val('1234');
|
74
|
+
equal(clientSideValidations.validators.local.length(element, options), "failed validation");
|
75
|
+
});
|
76
|
+
|