client_side_validations 3.1.5 → 3.2.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/client_side_validations.gemspec +1 -9
  2. data/lib/client_side_validations.rb +6 -2
  3. data/lib/client_side_validations/action_view/form_builder.rb +4 -2
  4. data/lib/client_side_validations/action_view/form_helper.rb +15 -7
  5. data/lib/client_side_validations/active_model.rb +5 -2
  6. data/lib/client_side_validations/active_record.rb +2 -1
  7. data/lib/client_side_validations/active_record/middleware.rb +15 -2
  8. data/lib/client_side_validations/active_record/uniqueness.rb +0 -1
  9. data/lib/client_side_validations/core_ext/regexp.rb +1 -1
  10. data/lib/client_side_validations/middleware.rb +40 -16
  11. data/lib/client_side_validations/version.rb +1 -1
  12. data/lib/generators/templates/client_side_validations/initializer.rb +0 -3
  13. data/vendor/assets/javascripts/rails.validations.js +135 -170
  14. metadata +22 -329
  15. data/lib/client_side_validations/formtastic.rb +0 -21
  16. data/lib/client_side_validations/mongo_mapper.rb +0 -9
  17. data/lib/client_side_validations/mongo_mapper/middleware.rb +0 -20
  18. data/lib/client_side_validations/mongo_mapper/uniqueness.rb +0 -29
  19. data/lib/client_side_validations/mongoid.rb +0 -9
  20. data/lib/client_side_validations/mongoid/format.rb +0 -10
  21. data/lib/client_side_validations/mongoid/length.rb +0 -24
  22. data/lib/client_side_validations/mongoid/middleware.rb +0 -20
  23. data/lib/client_side_validations/mongoid/presence.rb +0 -10
  24. data/lib/client_side_validations/mongoid/uniqueness.rb +0 -29
  25. data/lib/client_side_validations/simple_form.rb +0 -24
  26. data/lib/generators/templates/client_side_validations/README.rails.3.0 +0 -6
  27. data/test/action_view/cases/helper.rb +0 -176
  28. data/test/action_view/cases/test_helpers.rb +0 -635
  29. data/test/action_view/cases/test_legacy_helpers.rb +0 -217
  30. data/test/action_view/models.rb +0 -3
  31. data/test/action_view/models/comment.rb +0 -35
  32. data/test/action_view/models/post.rb +0 -35
  33. data/test/active_model/cases/helper.rb +0 -4
  34. data/test/active_model/cases/test_acceptance_validator.rb +0 -16
  35. data/test/active_model/cases/test_base.rb +0 -11
  36. data/test/active_model/cases/test_confirmation_validator.rb +0 -16
  37. data/test/active_model/cases/test_exclusion_validator.rb +0 -20
  38. data/test/active_model/cases/test_format_validator.rb +0 -21
  39. data/test/active_model/cases/test_inclusion_validator.rb +0 -21
  40. data/test/active_model/cases/test_length_validator.rb +0 -61
  41. data/test/active_model/cases/test_numericality_validator.rb +0 -46
  42. data/test/active_model/cases/test_presence_validator.rb +0 -16
  43. data/test/active_model/cases/test_validations.rb +0 -175
  44. data/test/active_model/models/person.rb +0 -17
  45. data/test/active_record/cases/helper.rb +0 -12
  46. data/test/active_record/cases/test_base.rb +0 -11
  47. data/test/active_record/cases/test_middleware.rb +0 -175
  48. data/test/active_record/cases/test_uniqueness_validator.rb +0 -56
  49. data/test/active_record/models/guid.rb +0 -7
  50. data/test/active_record/models/user.rb +0 -14
  51. data/test/base_helper.rb +0 -21
  52. data/test/core_ext/cases/test_core_ext.rb +0 -46
  53. data/test/formtastic/cases/helper.rb +0 -7
  54. data/test/formtastic/cases/test_form_builder.rb +0 -11
  55. data/test/formtastic/cases/test_form_helper.rb +0 -21
  56. data/test/generators/cases/test_generators.rb +0 -70
  57. data/test/javascript/config.ru +0 -3
  58. data/test/javascript/public/test/callbacks/elementAfter.js +0 -54
  59. data/test/javascript/public/test/callbacks/elementBefore.js +0 -54
  60. data/test/javascript/public/test/callbacks/elementFail.js +0 -70
  61. data/test/javascript/public/test/callbacks/elementPass.js +0 -70
  62. data/test/javascript/public/test/callbacks/formAfter.js +0 -45
  63. data/test/javascript/public/test/callbacks/formBefore.js +0 -45
  64. data/test/javascript/public/test/callbacks/formFail.js +0 -51
  65. data/test/javascript/public/test/callbacks/formPass.js +0 -50
  66. data/test/javascript/public/test/form_builders/validateForm.js +0 -66
  67. data/test/javascript/public/test/form_builders/validateFormtastic.js +0 -54
  68. data/test/javascript/public/test/form_builders/validateNestedForm.js +0 -66
  69. data/test/javascript/public/test/form_builders/validateSimpleForm.js +0 -57
  70. data/test/javascript/public/test/settings.js +0 -15
  71. data/test/javascript/public/test/validateElement.js +0 -179
  72. data/test/javascript/public/test/validators/acceptance.js +0 -42
  73. data/test/javascript/public/test/validators/confirmation.js +0 -25
  74. data/test/javascript/public/test/validators/exclusion.js +0 -41
  75. data/test/javascript/public/test/validators/format.js +0 -27
  76. data/test/javascript/public/test/validators/inclusion.js +0 -42
  77. data/test/javascript/public/test/validators/length.js +0 -76
  78. data/test/javascript/public/test/validators/numericality.js +0 -158
  79. data/test/javascript/public/test/validators/presence.js +0 -21
  80. data/test/javascript/public/test/validators/uniqueness.js +0 -107
  81. data/test/javascript/public/vendor/jquery.metadata.js +0 -122
  82. data/test/javascript/public/vendor/qunit.css +0 -196
  83. data/test/javascript/public/vendor/qunit.js +0 -1374
  84. data/test/javascript/server.rb +0 -84
  85. data/test/javascript/views/index.erb +0 -20
  86. data/test/javascript/views/layout.erb +0 -21
  87. data/test/middleware/cases/helper.rb +0 -7
  88. data/test/middleware/cases/test_middleware.rb +0 -8
  89. data/test/mongo_mapper/cases/helper.rb +0 -9
  90. data/test/mongo_mapper/cases/test_base.rb +0 -15
  91. data/test/mongo_mapper/cases/test_middleware.rb +0 -77
  92. data/test/mongo_mapper/cases/test_uniqueness_validator.rb +0 -55
  93. data/test/mongo_mapper/models/magazine.rb +0 -11
  94. data/test/mongoid/cases/helper.rb +0 -12
  95. data/test/mongoid/cases/test_base.rb +0 -15
  96. data/test/mongoid/cases/test_format_validator.rb +0 -21
  97. data/test/mongoid/cases/test_length_validator.rb +0 -60
  98. data/test/mongoid/cases/test_middleware.rb +0 -77
  99. data/test/mongoid/cases/test_presence_validator.rb +0 -16
  100. data/test/mongoid/cases/test_uniqueness_validator.rb +0 -54
  101. data/test/mongoid/models/book.rb +0 -12
  102. data/test/simple_form/cases/helper.rb +0 -5
  103. data/test/simple_form/cases/test_form_builder.rb +0 -14
  104. data/test/simple_form/cases/test_form_helper.rb +0 -24
  105. data/test/test_loader.rb +0 -6
@@ -1,57 +0,0 @@
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
-
@@ -1,15 +0,0 @@
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
-
@@ -1,179 +0,0 @@
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
- }
13
- }
14
-
15
- $('#qunit-fixture')
16
- .append($('<form />', {
17
- action: '/users',
18
- 'data-validate': true,
19
- method: 'post',
20
- id: 'new_user'
21
- }))
22
- .find('form')
23
- .append($('<label for="user_name">Name</label>'))
24
- .append($('<input />', {
25
- name: 'user[name]',
26
- id: 'user_name',
27
- 'data-validate': 'true',
28
- type: 'text'
29
- }))
30
- .append($('<label for="user_password">Password</label>'))
31
- .append($('<input />', {
32
- name: 'user[password]',
33
- id: 'user_password',
34
- 'data-validate': 'true',
35
- type: 'password'
36
- }))
37
- .append($('<label for="user_password_confirmation">Password Confirmation</label>'))
38
- .append($('<input />', {
39
- name: 'user[password_confirmation]',
40
- id: 'user_password_confirmation',
41
- type: 'password'
42
- }))
43
- .append($('<label for="user_agree">Agree</label>'))
44
- .append($('<input />', {
45
- name: 'user[agree]',
46
- id: 'user_agree',
47
- 'data-validate': 'true',
48
- type: 'checkbox',
49
- value: 1
50
- }))
51
- .append($('<input />', {
52
- name: 'user[email]',
53
- id: 'user_email',
54
- 'data-validate': 'true',
55
- type: 'text'
56
- }))
57
-
58
- $('form#new_user').validate();
59
- }
60
- });
61
-
62
- test('Validate when focusouting', function() {
63
- var form = $('form#new_user'), input = form.find('input#user_name');
64
- var label = $('label[for="user_name"]');
65
-
66
- input.trigger('focusout');
67
- ok(input.parent().hasClass('field_with_errors'));
68
- ok(label.parent().hasClass('field_with_errors'));
69
- });
70
-
71
- test('Validate when checkbox is clicked', function() {
72
- var form = $('form#new_user'), input = form.find('input#user_agree');
73
- var label = $('label[for="user_agree"]');
74
-
75
- input.attr('checked', false)
76
- input.trigger('click');
77
- ok(input.parent().hasClass('field_with_errors'));
78
- ok(label.parent().hasClass('field_with_errors'));
79
- });
80
-
81
- test('Validate when focusout on confirmation', function() {
82
- var form = $('form#new_user'), password = form.find('input#user_password'), confirmation = form.find('input#user_password_confirmation');
83
- var label = $('label[for="user_password"]');
84
-
85
- password.val('password');
86
- confirmation.trigger('focusout');
87
- ok(password.parent().hasClass('field_with_errors'));
88
- ok(label.parent().hasClass('field_with_errors'));
89
- });
90
-
91
- test('Validate when keyup on confirmation', function() {
92
- var form = $('form#new_user'), password = form.find('input#user_password'), confirmation = form.find('input#user_password_confirmation');
93
- var label = $('label[for="user_password"]');
94
-
95
- password.val('password');
96
-
97
- confirmation.trigger('keyup');
98
- ok(password.parent().hasClass('field_with_errors'));
99
- ok(label.parent().hasClass('field_with_errors'));
100
-
101
- confirmation.val('password')
102
- confirmation.trigger('keyup');
103
- ok(!password.parent().hasClass('field_with_errors'));
104
- ok(!label.parent().hasClass('field_with_errors'));
105
- });
106
-
107
- test('Forcing remote validators to run last', function() {
108
- var form = $('form#new_user'), input = form.find('input#user_email');
109
-
110
- input.trigger('focusout');
111
- equal(input.parent().find('label').text(), "must be present")
112
- });
113
-
114
- test("Don't validate when value hasn't changed", function() {
115
- var form = $('form#new_user'), input = form.find('input#user_name');
116
- var label = $('label[for="user_name"]');
117
-
118
- input.trigger('focusout');
119
- ok(input.parent().hasClass('field_with_errors'));
120
- ok(label.parent().hasClass('field_with_errors'));
121
-
122
- input.val('123');
123
- input.trigger('focusout');
124
- ok(input.parent().hasClass('field_with_errors'));
125
- ok(label.parent().hasClass('field_with_errors'));
126
-
127
- input.trigger('change');
128
- input.trigger('focusout');
129
- ok(!input.parent().hasClass('field_with_errors'));
130
- ok(!label.parent().hasClass('field_with_errors'));
131
- });
132
-
133
- test('Validate when error message needs to change', function() {
134
- var form = $('form#new_user'), input = form.find('input#user_name');
135
- var label = $('label[for="user_name"]');
136
-
137
- input.trigger('focusout');
138
- equal(input.parent().find('label.message').text(), "must be present");
139
- input.val('abc');
140
- input.trigger('change')
141
- input.trigger('focusout');
142
- equal(input.parent().find('label.message').text(), "is invalid");
143
- })
144
-
145
- test("Don't validate confirmation when not a validatable input", function() {
146
- $('#qunit-fixture')
147
- .append($('<form />', {
148
- action: '/users',
149
- 'data-validate': true,
150
- method: 'post',
151
- id: 'new_user_2'
152
- }))
153
- .find('form')
154
- .append($('<label for="user_2_password">Password</label>'))
155
- .append($('<input />', {
156
- name: 'user_2[password]',
157
- id: 'user_2_password',
158
- type: 'password'
159
- }))
160
- .append($('<label for="user_2_password_confirmation">Password Confirmation</label>'))
161
- .append($('<input />', {
162
- name: 'user_2[password_confirmation]',
163
- id: 'user_2_password_confirmation',
164
- type: 'password'
165
- }))
166
- new_user_2 = {
167
- type: 'ActionView::Helpers::FormBuilder',
168
- input_tag: '<div class="field_with_errors"><span id="input_tag" /><label for="user_name" class="message"></label></div>',
169
- label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
170
- validators: {
171
- }
172
- }
173
- $('form#new_user_2').validate();
174
- var form = $('form#new_user_2'), input = form.find('input#user_2_password_confirmation');
175
- input.val('123');
176
- input.trigger('focusout');
177
- ok(!input.parent().hasClass('field_with_errors'));
178
- });
179
-
@@ -1,42 +0,0 @@
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
-
@@ -1,25 +0,0 @@
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
- });
@@ -1,41 +0,0 @@
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
- });
@@ -1,27 +0,0 @@
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
- });
@@ -1,42 +0,0 @@
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
-
@@ -1,76 +0,0 @@
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
-