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.
Files changed (111) hide show
  1. data/client_side_validations.gemspec +4 -16
  2. data/lib/client_side_validations/action_view/form_builder.rb +31 -79
  3. data/lib/client_side_validations/action_view/form_helper.rb +59 -24
  4. data/lib/client_side_validations/active_model/exclusion.rb +14 -2
  5. data/lib/client_side_validations/active_model/format.rb +21 -0
  6. data/lib/client_side_validations/active_model/inclusion.rb +13 -2
  7. data/lib/client_side_validations/active_model/length.rb +4 -2
  8. data/lib/client_side_validations/active_model/numericality.rb +12 -1
  9. data/lib/client_side_validations/active_model.rb +100 -14
  10. data/lib/client_side_validations/active_record/middleware.rb +29 -3
  11. data/lib/client_side_validations/active_record/uniqueness.rb +4 -3
  12. data/lib/client_side_validations/active_record.rb +2 -1
  13. data/lib/client_side_validations/config.rb +9 -0
  14. data/lib/client_side_validations/core_ext/regexp.rb +1 -2
  15. data/lib/client_side_validations/generators/rails_validations.rb +15 -0
  16. data/lib/client_side_validations/generators.rb +12 -0
  17. data/lib/client_side_validations/middleware.rb +63 -24
  18. data/lib/client_side_validations/version.rb +1 -1
  19. data/lib/client_side_validations.rb +2 -2
  20. data/lib/generators/client_side_validations/copy_assets_generator.rb +58 -0
  21. data/lib/generators/client_side_validations/install_generator.rb +9 -21
  22. data/lib/generators/templates/client_side_validations/initializer.rb +2 -2
  23. data/vendor/assets/javascripts/rails.validations.js +474 -282
  24. metadata +156 -301
  25. data/lib/client_side_validations/formtastic.rb +0 -21
  26. data/lib/client_side_validations/mongo_mapper/middleware.rb +0 -20
  27. data/lib/client_side_validations/mongo_mapper/uniqueness.rb +0 -28
  28. data/lib/client_side_validations/mongo_mapper.rb +0 -9
  29. data/lib/client_side_validations/mongoid/middleware.rb +0 -20
  30. data/lib/client_side_validations/mongoid/uniqueness.rb +0 -28
  31. data/lib/client_side_validations/mongoid.rb +0 -9
  32. data/lib/client_side_validations/simple_form.rb +0 -24
  33. data/lib/generators/client_side_validations/copy_asset_generator.rb +0 -23
  34. data/lib/generators/templates/client_side_validations/README.rails.3.0 +0 -6
  35. data/lib/generators/templates/client_side_validations/README.rails.3.1 +0 -7
  36. data/test/action_view/cases/helper.rb +0 -176
  37. data/test/action_view/cases/test_helpers.rb +0 -600
  38. data/test/action_view/cases/test_legacy_helpers.rb +0 -217
  39. data/test/action_view/models/comment.rb +0 -35
  40. data/test/action_view/models/post.rb +0 -35
  41. data/test/action_view/models.rb +0 -3
  42. data/test/active_model/cases/helper.rb +0 -4
  43. data/test/active_model/cases/test_acceptance_validator.rb +0 -16
  44. data/test/active_model/cases/test_base.rb +0 -11
  45. data/test/active_model/cases/test_confirmation_validator.rb +0 -16
  46. data/test/active_model/cases/test_exclusion_validator.rb +0 -20
  47. data/test/active_model/cases/test_format_validator.rb +0 -21
  48. data/test/active_model/cases/test_inclusion_validator.rb +0 -21
  49. data/test/active_model/cases/test_length_validator.rb +0 -61
  50. data/test/active_model/cases/test_numericality_validator.rb +0 -46
  51. data/test/active_model/cases/test_presence_validator.rb +0 -16
  52. data/test/active_model/cases/test_validations.rb +0 -175
  53. data/test/active_model/models/person.rb +0 -17
  54. data/test/active_record/cases/helper.rb +0 -12
  55. data/test/active_record/cases/test_base.rb +0 -11
  56. data/test/active_record/cases/test_middleware.rb +0 -175
  57. data/test/active_record/cases/test_uniqueness_validator.rb +0 -50
  58. data/test/active_record/models/guid.rb +0 -7
  59. data/test/active_record/models/user.rb +0 -14
  60. data/test/base_helper.rb +0 -8
  61. data/test/core_ext/cases/test_core_ext.rb +0 -46
  62. data/test/formtastic/cases/helper.rb +0 -7
  63. data/test/formtastic/cases/test_form_builder.rb +0 -11
  64. data/test/formtastic/cases/test_form_helper.rb +0 -21
  65. data/test/generators/cases/test_generators.rb +0 -31
  66. data/test/javascript/config.ru +0 -3
  67. data/test/javascript/public/test/callbacks/elementAfter.js +0 -54
  68. data/test/javascript/public/test/callbacks/elementBefore.js +0 -54
  69. data/test/javascript/public/test/callbacks/elementFail.js +0 -70
  70. data/test/javascript/public/test/callbacks/elementPass.js +0 -70
  71. data/test/javascript/public/test/callbacks/formAfter.js +0 -45
  72. data/test/javascript/public/test/callbacks/formBefore.js +0 -45
  73. data/test/javascript/public/test/callbacks/formFail.js +0 -51
  74. data/test/javascript/public/test/callbacks/formPass.js +0 -50
  75. data/test/javascript/public/test/form_builders/validateForm.js +0 -66
  76. data/test/javascript/public/test/form_builders/validateFormtastic.js +0 -54
  77. data/test/javascript/public/test/form_builders/validateNestedForm.js +0 -66
  78. data/test/javascript/public/test/form_builders/validateSimpleForm.js +0 -57
  79. data/test/javascript/public/test/settings.js +0 -15
  80. data/test/javascript/public/test/validateElement.js +0 -179
  81. data/test/javascript/public/test/validators/acceptance.js +0 -42
  82. data/test/javascript/public/test/validators/confirmation.js +0 -25
  83. data/test/javascript/public/test/validators/exclusion.js +0 -41
  84. data/test/javascript/public/test/validators/format.js +0 -27
  85. data/test/javascript/public/test/validators/inclusion.js +0 -42
  86. data/test/javascript/public/test/validators/length.js +0 -76
  87. data/test/javascript/public/test/validators/numericality.js +0 -142
  88. data/test/javascript/public/test/validators/presence.js +0 -21
  89. data/test/javascript/public/test/validators/uniqueness.js +0 -96
  90. data/test/javascript/public/vendor/jquery.metadata.js +0 -122
  91. data/test/javascript/public/vendor/qunit.css +0 -196
  92. data/test/javascript/public/vendor/qunit.js +0 -1374
  93. data/test/javascript/server.rb +0 -84
  94. data/test/javascript/views/index.erb +0 -20
  95. data/test/javascript/views/layout.erb +0 -21
  96. data/test/middleware/cases/helper.rb +0 -18
  97. data/test/middleware/cases/test_middleware.rb +0 -8
  98. data/test/mongo_mapper/cases/helper.rb +0 -9
  99. data/test/mongo_mapper/cases/test_base.rb +0 -15
  100. data/test/mongo_mapper/cases/test_middleware.rb +0 -77
  101. data/test/mongo_mapper/cases/test_uniqueness_validator.rb +0 -50
  102. data/test/mongo_mapper/models/magazine.rb +0 -11
  103. data/test/mongoid/cases/helper.rb +0 -16
  104. data/test/mongoid/cases/test_base.rb +0 -15
  105. data/test/mongoid/cases/test_middleware.rb +0 -77
  106. data/test/mongoid/cases/test_uniqueness_validator.rb +0 -49
  107. data/test/mongoid/models/book.rb +0 -12
  108. data/test/simple_form/cases/helper.rb +0 -5
  109. data/test/simple_form/cases/test_form_builder.rb +0 -14
  110. data/test/simple_form/cases/test_form_helper.rb +0 -24
  111. data/test/test_loader.rb +0 -6
@@ -1,96 +0,0 @@
1
- module('Uniqueness options', {
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 class="message"></label></div>',
6
- label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
7
- validators: {'user[email]':{"uniqueness":{"message": "must be unique", "scope":{name:"pass"}},"presence":{"message": "must be present"}}}
8
- }
9
-
10
- $('#qunit-fixture')
11
- .append($('<form />', {
12
- action: '/users',
13
- 'data-validate': true,
14
- method: 'post',
15
- id: 'new_user'
16
- }))
17
- .find('form')
18
- .append($('<input />', {
19
- name: 'user[name]',
20
- id: 'user_name',
21
- type: 'text'
22
- }))
23
- .append($('<input />', {
24
- name: 'user[email]',
25
- id: 'user_email',
26
- 'data-validate': 'true',
27
- type: 'text'
28
- }))
29
-
30
- $('form#new_user').validate();
31
- }
32
- });
33
-
34
- test('when matching uniqueness on a non-nested resource', function() {
35
- var element = $('<input type="text" name="user[email]"/>');
36
- var options = { 'message': "failed validation" };
37
- element.val('nottaken@test.com');
38
- equal(clientSideValidations.validators.remote.uniqueness(element, options), undefined);
39
- });
40
-
41
- test('when matching uniqueness on a non-nested resource', function() {
42
- var element = $('<input type="text" name="user[email]"/>');
43
- var options = { 'message': "failed validation" };
44
- element.val('taken@test.com');
45
- equal(clientSideValidations.validators.remote.uniqueness(element, options), "failed validation");
46
- });
47
-
48
- test('when matching uniqueness on a nested singular resource', function() {
49
- var element = $('<input type="text" name="profile[user_attributes][email]"/>');
50
- var options = { 'message': "failed validation" };
51
- element.val('nottaken@test.com');
52
- equal(clientSideValidations.validators.remote.uniqueness(element, options), undefined);
53
- });
54
-
55
- test('when matching uniqueness on a nested singular resource', function() {
56
- var element = $('<input type="text" name="profile[user_attributes][email]"/>');
57
- var options = { 'message': "failed validation" };
58
- element.val('taken@test.com');
59
- equal(clientSideValidations.validators.remote.uniqueness(element, options), "failed validation");
60
- });
61
-
62
- test('when using scopes with no replacement', function() {
63
- var element = $('<input type="text" name="person[age]" />');
64
- var options = { 'message': "failed validation", 'with': /\d+/, 'scope': { 'name': 'test name' } };
65
- element.val('test');
66
- equal(clientSideValidations.validators.remote.uniqueness(element, options), "failed validation");
67
- });
68
-
69
- test('when using scopes with replacement', function() {
70
- var element = $('<input type="text" name="person[age]" />');
71
- var options = { 'message': "failed validation", 'with': /\d+/, 'scope': { 'name': 'test name' } };
72
- element.val('test')
73
- $('#qunit-fixture').append('<input type="text" name="person[name]" />').find('input[name="person[name]"]').val('other name');
74
- equal(clientSideValidations.validators.remote.uniqueness(element, options), undefined);
75
- });
76
-
77
- test('when validating by scope and mixed focus order', function() {
78
- var unique_element = $('#user_email'), scope_element = $('#user_name');
79
- unique_element.val('free@test.com');
80
- unique_element.trigger('change');
81
- unique_element.trigger('focusout');
82
- equal($('.message[for="user_email"]').text(), '');
83
-
84
- scope_element.val('test name');
85
- scope_element.trigger('change');
86
- scope_element.trigger('focusout');
87
- equal($('.message[for="user_email"]').text(), 'must be unique');
88
- });
89
-
90
- test('when matching uniqueness on a resource with a defined class name', function() {
91
- var element = $('<input type="text" name="user2[email]"/>');
92
- var options = { 'message': "failed validation", 'class': "active_record_test_module/user2" };
93
- element.val('nottaken@test.com');
94
- equal(clientSideValidations.validators.remote.uniqueness(element, options), 'failed validation');
95
- });
96
-
@@ -1,122 +0,0 @@
1
- /*
2
- * Metadata - jQuery plugin for parsing metadata from elements
3
- *
4
- * Copyright (c) 2006 John Resig, Yehuda Katz, J�örn Zaefferer, Paul McLanahan
5
- *
6
- * Dual licensed under the MIT and GPL licenses:
7
- * http://www.opensource.org/licenses/mit-license.php
8
- * http://www.gnu.org/licenses/gpl.html
9
- *
10
- * Revision: $Id: jquery.metadata.js 4187 2007-12-16 17:15:27Z joern.zaefferer $
11
- *
12
- */
13
-
14
- /**
15
- * Sets the type of metadata to use. Metadata is encoded in JSON, and each property
16
- * in the JSON will become a property of the element itself.
17
- *
18
- * There are three supported types of metadata storage:
19
- *
20
- * attr: Inside an attribute. The name parameter indicates *which* attribute.
21
- *
22
- * class: Inside the class attribute, wrapped in curly braces: { }
23
- *
24
- * elem: Inside a child element (e.g. a script tag). The
25
- * name parameter indicates *which* element.
26
- *
27
- * The metadata for an element is loaded the first time the element is accessed via jQuery.
28
- *
29
- * As a result, you can define the metadata type, use $(expr) to load the metadata into the elements
30
- * matched by expr, then redefine the metadata type and run another $(expr) for other elements.
31
- *
32
- * @name $.metadata.setType
33
- *
34
- * @example <p id="one" class="some_class {item_id: 1, item_label: 'Label'}">This is a p</p>
35
- * @before $.metadata.setType("class")
36
- * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
37
- * @desc Reads metadata from the class attribute
38
- *
39
- * @example <p id="one" class="some_class" data="{item_id: 1, item_label: 'Label'}">This is a p</p>
40
- * @before $.metadata.setType("attr", "data")
41
- * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
42
- * @desc Reads metadata from a "data" attribute
43
- *
44
- * @example <p id="one" class="some_class"><script>{item_id: 1, item_label: 'Label'}</script>This is a p</p>
45
- * @before $.metadata.setType("elem", "script")
46
- * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
47
- * @desc Reads metadata from a nested script element
48
- *
49
- * @param String type The encoding type
50
- * @param String name The name of the attribute to be used to get metadata (optional)
51
- * @cat Plugins/Metadata
52
- * @descr Sets the type of encoding to be used when loading metadata for the first time
53
- * @type undefined
54
- * @see metadata()
55
- */
56
-
57
- (function($) {
58
-
59
- $.extend({
60
- metadata : {
61
- defaults : {
62
- type: 'class',
63
- name: 'metadata',
64
- cre: /({.*})/,
65
- single: 'metadata'
66
- },
67
- setType: function( type, name ){
68
- this.defaults.type = type;
69
- this.defaults.name = name;
70
- },
71
- get: function( elem, opts ){
72
- var settings = $.extend({},this.defaults,opts);
73
- // check for empty string in single property
74
- if ( !settings.single.length ) settings.single = 'metadata';
75
-
76
- var data = $.data(elem, settings.single);
77
- // returned cached data if it already exists
78
- if ( data ) return data;
79
-
80
- data = "{}";
81
-
82
- if ( settings.type == "class" ) {
83
- var m = settings.cre.exec( elem.className );
84
- if ( m )
85
- data = m[1];
86
- } else if ( settings.type == "elem" ) {
87
- if( !elem.getElementsByTagName )
88
- return undefined;
89
- var e = elem.getElementsByTagName(settings.name);
90
- if ( e.length )
91
- data = $.trim(e[0].innerHTML);
92
- } else if ( elem.getAttribute != undefined ) {
93
- var attr = elem.getAttribute( settings.name );
94
- if ( attr )
95
- data = attr;
96
- }
97
-
98
- if ( data.indexOf( '{' ) <0 )
99
- data = "{" + data + "}";
100
-
101
- data = eval("(" + data + ")");
102
-
103
- $.data( elem, settings.single, data );
104
- return data;
105
- }
106
- }
107
- });
108
-
109
- /**
110
- * Returns the metadata object for the first member of the jQuery object.
111
- *
112
- * @name metadata
113
- * @descr Returns element's metadata object
114
- * @param Object opts An object contianing settings to override the defaults
115
- * @type jQuery
116
- * @cat Plugins/Metadata
117
- */
118
- $.fn.metadata = function( opts ){
119
- return $.metadata.get( this[0], opts );
120
- };
121
-
122
- })(jQuery);
@@ -1,196 +0,0 @@
1
- /** Font Family and Sizes */
2
-
3
- #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
4
- font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
5
- }
6
-
7
- #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
8
- #qunit-tests { font-size: smaller; }
9
-
10
-
11
- /** Resets */
12
-
13
- #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult {
14
- margin: 0;
15
- padding: 0;
16
- }
17
-
18
-
19
- /** Header */
20
-
21
- #qunit-header {
22
- padding: 0.5em 0 0.5em 1em;
23
-
24
- color: #8699a4;
25
- background-color: #0d3349;
26
-
27
- font-size: 1.5em;
28
- line-height: 1em;
29
- font-weight: normal;
30
-
31
- border-radius: 15px 15px 0 0;
32
- -moz-border-radius: 15px 15px 0 0;
33
- -webkit-border-top-right-radius: 15px;
34
- -webkit-border-top-left-radius: 15px;
35
- }
36
-
37
- #qunit-header a {
38
- text-decoration: none;
39
- color: #c2ccd1;
40
- }
41
-
42
- #qunit-header a:hover,
43
- #qunit-header a:focus {
44
- color: #fff;
45
- }
46
-
47
- #qunit-banner {
48
- height: 5px;
49
- }
50
-
51
- #qunit-testrunner-toolbar {
52
- padding: 0em 0 0.5em 2em;
53
- }
54
-
55
- #qunit-userAgent {
56
- padding: 0.5em 0 0.5em 2.5em;
57
- background-color: #2b81af;
58
- color: #fff;
59
- text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
60
- }
61
-
62
-
63
- /** Tests: Pass/Fail */
64
-
65
- #qunit-tests {
66
- list-style-position: inside;
67
- }
68
-
69
- #qunit-tests li {
70
- padding: 0.4em 0.5em 0.4em 2.5em;
71
- border-bottom: 1px solid #fff;
72
- list-style-position: inside;
73
- }
74
-
75
- #qunit-tests li strong {
76
- cursor: pointer;
77
- }
78
-
79
- #qunit-tests ol {
80
- margin-top: 0.5em;
81
- padding: 0.5em;
82
-
83
- background-color: #fff;
84
-
85
- border-radius: 15px;
86
- -moz-border-radius: 15px;
87
- -webkit-border-radius: 15px;
88
-
89
- box-shadow: inset 0px 2px 13px #999;
90
- -moz-box-shadow: inset 0px 2px 13px #999;
91
- -webkit-box-shadow: inset 0px 2px 13px #999;
92
- }
93
-
94
- #qunit-tests table {
95
- border-collapse: collapse;
96
- margin-top: .2em;
97
- }
98
-
99
- #qunit-tests th {
100
- text-align: right;
101
- vertical-align: top;
102
- padding: 0 .5em 0 0;
103
- }
104
-
105
- #qunit-tests td {
106
- vertical-align: top;
107
- }
108
-
109
- #qunit-tests pre {
110
- margin: 0;
111
- white-space: pre-wrap;
112
- word-wrap: break-word;
113
- }
114
-
115
- #qunit-tests del {
116
- background-color: #e0f2be;
117
- color: #374e0c;
118
- text-decoration: none;
119
- }
120
-
121
- #qunit-tests ins {
122
- background-color: #ffcaca;
123
- color: #500;
124
- text-decoration: none;
125
- }
126
-
127
- /*** Test Counts */
128
-
129
- #qunit-tests b.counts { color: black; }
130
- #qunit-tests b.passed { color: #5E740B; }
131
- #qunit-tests b.failed { color: #710909; }
132
-
133
- #qunit-tests li li {
134
- margin: 0.5em;
135
- padding: 0.4em 0.5em 0.4em 0.5em;
136
- background-color: #fff;
137
- border-bottom: none;
138
- list-style-position: inside;
139
- }
140
-
141
- /*** Passing Styles */
142
-
143
- #qunit-tests li li.pass {
144
- color: #5E740B;
145
- background-color: #fff;
146
- border-left: 26px solid #C6E746;
147
- }
148
-
149
- #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
150
- #qunit-tests .pass .test-name { color: #366097; }
151
-
152
- #qunit-tests .pass .test-actual,
153
- #qunit-tests .pass .test-expected { color: #999999; }
154
-
155
- #qunit-banner.qunit-pass { background-color: #C6E746; }
156
-
157
- /*** Failing Styles */
158
-
159
- #qunit-tests li li.fail {
160
- color: #710909;
161
- background-color: #fff;
162
- border-left: 26px solid #EE5757;
163
- }
164
-
165
- #qunit-tests .fail { color: #000000; background-color: #EE5757; }
166
- #qunit-tests .fail .test-name,
167
- #qunit-tests .fail .module-name { color: #000000; }
168
-
169
- #qunit-tests .fail .test-actual { color: #EE5757; }
170
- #qunit-tests .fail .test-expected { color: green; }
171
-
172
- #qunit-banner.qunit-fail,
173
- #qunit-testrunner-toolbar { background-color: #EE5757; }
174
-
175
-
176
- /** Footer */
177
-
178
- #qunit-testresult {
179
- padding: 0.5em 0.5em 0.5em 2.5em;
180
-
181
- color: #2b81af;
182
- background-color: #D2E0E6;
183
-
184
- border-radius: 0 0 15px 15px;
185
- -moz-border-radius: 0 0 15px 15px;
186
- -webkit-border-bottom-right-radius: 15px;
187
- -webkit-border-bottom-left-radius: 15px;
188
- }
189
-
190
- /** Fixture */
191
-
192
- #qunit-fixture {
193
- position: absolute;
194
- top: -10000px;
195
- left: -10000px;
196
- }