client_side_validations 3.1.1 → 3.1.3

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.
@@ -17,14 +17,14 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_development_dependency 'rails', '3.1.0.rc4'
20
+ s.add_development_dependency 'rails', '~> 3.1.0'
21
21
  s.add_development_dependency 'sqlite3'
22
22
  s.add_development_dependency 'bson_ext'
23
23
  s.add_development_dependency 'mongoid', '~> 2.0.0'
24
- s.add_development_dependency 'mongo_mapper','~>0.9.0'
24
+ s.add_development_dependency 'mongo_mapper','~> 0.9.0'
25
25
  s.add_development_dependency 'mocha'
26
- s.add_development_dependency 'simple_form'
27
- s.add_development_dependency 'formtastic', '~> 2.0.0.rc3'
26
+ s.add_development_dependency 'simple_form', '~> 1.5.0'
27
+ s.add_development_dependency 'formtastic', '~> 2.0.0'
28
28
 
29
29
  # For QUnit testing
30
30
  s.add_development_dependency 'sinatra', '~> 1.0'
@@ -1,3 +1,3 @@
1
1
  module ClientSideValidations
2
- VERSION = '3.1.1'
2
+ VERSION = '3.1.3'
3
3
  end
@@ -2,14 +2,27 @@ module ClientSideValidations
2
2
  module Generators
3
3
  class CopyAssetGenerator < Rails::Generators::Base
4
4
  source_root File.expand_path('../../../../vendor/assets/javascripts', __FILE__)
5
- if Rails.version >= '3.1'
5
+
6
+ private
7
+
8
+ def self.asset_pipeline_enabled?
9
+ (Rails.configuration.respond_to?(:assets) ? (Rails.configuration.assets || {}) : {})[:enabled]
10
+ end
11
+
12
+ def asset_pipeline_enabled?
13
+ self.class.asset_pipeline_enabled?
14
+ end
15
+
16
+ public
17
+
18
+ if asset_pipeline_enabled?
6
19
  desc 'Creates a ClientSideValidations initializer and copies rails.validations.js to app/assets/javascripts.'
7
20
  else
8
21
  desc 'Creates a ClientSideValidations initializer and copies rails.validations.js to public/javascripts.'
9
22
  end
10
23
 
11
24
  def copy_javascript_asset
12
- if Rails.version >= '3.1'
25
+ if asset_pipeline_enabled?
13
26
  destination = 'app/assets/javascripts'
14
27
  else
15
28
  destination = 'public/javascripts'
@@ -3,7 +3,19 @@ module ClientSideValidations
3
3
  class InstallGenerator < Rails::Generators::Base
4
4
  source_root File.expand_path('../../templates/client_side_validations', __FILE__)
5
5
 
6
- if Rails.version >= '3.1'
6
+ private
7
+
8
+ def self.asset_pipeline_enabled?
9
+ (Rails.configuration.respond_to?(:assets) ? (Rails.configuration.assets || {}) : {})[:enabled]
10
+ end
11
+
12
+ def asset_pipeline_enabled?
13
+ self.class.asset_pipeline_enabled?
14
+ end
15
+
16
+ public
17
+
18
+ if asset_pipeline_enabled?
7
19
  desc 'Creates a ClientSideValidations initializer.'
8
20
  else
9
21
  desc 'Creates a ClientSideValidations initializer and copies rails.validations.js to public/javascripts.'
@@ -14,10 +26,8 @@ module ClientSideValidations
14
26
  end
15
27
 
16
28
  def copy_javascript_asset
17
- if Rails.version >= '3.0'
18
- if Rails.version < '3.1'
19
- copy_file '../../../../vendor/assets/javascripts/rails.validations.js', 'public/javascripts/rails.validations.js'
20
- end
29
+ unless asset_pipeline_enabled?
30
+ copy_file '../../../../vendor/assets/javascripts/rails.validations.js', 'public/javascripts/rails.validations.js'
21
31
  end
22
32
  end
23
33
 
@@ -28,6 +38,7 @@ module ClientSideValidations
28
38
  readme 'README.rails.3.0' if behavior == :invoke
29
39
  end
30
40
  end
41
+
31
42
  end
32
43
  end
33
44
  end
data/test/base_helper.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
3
  Bundler.setup
4
- require 'ruby-debug'
5
4
  require 'test/unit'
6
5
  require 'mocha'
7
6
 
@@ -14,8 +14,8 @@ class ClientSideValidations::Formtastic::FormHelperTest < ActionView::TestCase
14
14
  concat f.input(:cost)
15
15
  end
16
16
 
17
- expected = %{<form accept-charset="UTF-8" action="/posts/123" class="formtastic 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="&#x2713;" /><input name="_method" type="hidden" value="put" /></div><li class="string input required stringish" id="post_cost_input"><label class=\" label\" for="post_cost">Cost<abbr title="required">*</abbr></label><input data-validate="true" id="post_cost" name="post[cost]" required=\"required\" type="text" />\n\n</li></form><script>window['edit_post_123'] = {"type":"Formtastic::FormBuilder","inline_error_class":"inline-errors","validators":{"post[cost]":{"presence":{"message":"can't be blank"}}}};</script>}
17
+ expected = %{<form accept-charset="UTF-8" action="/posts/123" class="formtastic 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="&#x2713;" /><input name="_method" type="hidden" value="put" /></div><li class="string input required stringish" id="post_cost_input"><label class=\" label\" for="post_cost">Cost<abbr title="required">*</abbr></label><input data-validate="true" id="post_cost" name="post[cost]" type="text" />\n\n</li></form><script>window['edit_post_123'] = {"type":"Formtastic::FormBuilder","inline_error_class":"inline-errors","validators":{"post[cost]":{"presence":{"message":"can't be blank"}}}};</script>}
18
18
  assert_equal expected, output_buffer, "\n\n *** If you're running Ruby 1.8 and this test fails is is most likely due to 1.8's lack of insertion order persistence with Hashes ***\n"
19
19
  end
20
20
 
21
- end
21
+ end
@@ -7,10 +7,32 @@ class InstallGeneratorTest < Rails::Generators::TestCase
7
7
  destination File.expand_path('../../tmp', __FILE__)
8
8
  setup :prepare_destination
9
9
 
10
- test 'Assert all files are properly created' do
10
+ test 'Assert all files are properly created when no asset pipeline present' do
11
+ stub_configuration
11
12
  run_generator
12
13
  assert_file 'config/initializers/client_side_validations.rb'
13
- assert_file 'public/javascripts/rails.validations.js' if Rails.version > '3.0' && Rails.version < '3.1'
14
+ assert_file 'public/javascripts/rails.validations.js'
15
+ end
16
+
17
+ test 'Assert all files are properly created when asset pipeline present and disabled' do
18
+ stub_configuration
19
+ Rails.configuration.stubs(:assets).returns({})
20
+ Rails.configuration.assets[:enabled] = false
21
+ run_generator
22
+ assert_file 'config/initializers/client_side_validations.rb'
23
+ assert_file 'public/javascripts/rails.validations.js'
24
+ end
25
+
26
+ test 'Assert all files are properly created when asset pipeline present and enabled' do
27
+ stub_configuration
28
+ Rails.configuration.stubs(:assets).returns({})
29
+ Rails.configuration.assets[:enabled] = true
30
+ run_generator
31
+ assert_file 'config/initializers/client_side_validations.rb'
32
+ end
33
+
34
+ def stub_configuration
35
+ Rails.stubs(:configuration).returns(mock('Configuration'))
14
36
  end
15
37
  end
16
38
 
@@ -19,13 +41,30 @@ class CopyAssetGeneratorTest < Rails::Generators::TestCase
19
41
  destination File.expand_path('../../tmp', __FILE__)
20
42
  setup :prepare_destination
21
43
 
22
- test 'Assert file is properly created' do
44
+ test 'Assert file is properly created when no asset pipeline present' do
45
+ stub_configuration
23
46
  run_generator
24
- if Rails.version >= '3.1'
25
- assert_file 'app/assets/javascripts/rails.validations.js'
26
- else
27
- assert_file 'public/javascripts/rails.validations.js'
28
- end
47
+ assert_file 'public/javascripts/rails.validations.js'
48
+ end
49
+
50
+ test 'Assert file is properly created when asset pipeline present and disabled' do
51
+ stub_configuration
52
+ Rails.configuration.stubs(:assets).returns({})
53
+ Rails.configuration.assets[:enabled] = false
54
+ run_generator
55
+ assert_file 'public/javascripts/rails.validations.js'
56
+ end
57
+
58
+ test 'Assert file is properly created when asset pipeline present and enabled' do
59
+ stub_configuration
60
+ Rails.configuration.stubs(:assets).returns({})
61
+ Rails.configuration.assets[:enabled] = true
62
+ run_generator
63
+ assert_file 'app/assets/javascripts/rails.validations.js'
64
+ end
65
+
66
+ def stub_configuration
67
+ Rails.stubs(:configuration).returns(mock('Configuration'))
29
68
  end
30
69
  end
31
70
 
@@ -28,6 +28,15 @@ test('when only allowing integers and value is integer', function() {
28
28
  equal(clientSideValidations.validators.local.numericality(element, options), undefined);
29
29
  });
30
30
 
31
+ test('when only allowing integers and value has a negative or positive sign', function() {
32
+ var element = $('<input type="text" />');
33
+ var options = { messages: { only_integer: "failed validation"}, only_integer: true };
34
+ element.val('-23');
35
+ equal(clientSideValidations.validators.local.numericality(element, options), undefined);
36
+ element.val('+23');
37
+ equal(clientSideValidations.validators.local.numericality(element, options), undefined);
38
+ });
39
+
31
40
  test('when only allowing integers and value is not integer', function() {
32
41
  var element = $('<input type="text" />');
33
42
  var options = { messages: { only_integer: "failed validation" }, only_integer: true };
@@ -94,3 +94,14 @@ test('when matching uniqueness on a resource with a defined class name', functio
94
94
  equal(clientSideValidations.validators.remote.uniqueness(element, options), 'failed validation');
95
95
  });
96
96
 
97
+ test('when allowing blank', function() {
98
+ var element = $('<input type="text" name="user2[email]" />');
99
+ var options = { 'message': "failed validation", 'with': /\d+/, 'allow_blank': true };
100
+ equal(clientSideValidations.validators.remote.uniqueness(element, options), undefined);
101
+ });
102
+
103
+ test('when not allowing blank', function() {
104
+ var element = $('<input type="text" name="user2[email]" />');
105
+ var options = { 'message': "failed validation", 'with': /\d+/ };
106
+ equal(clientSideValidations.validators.remote.uniqueness(element, options), "failed validation");
107
+ });
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Rails 3 Client Side Validations - v3.1.1
2
+ * Rails 3 Client Side Validations - v3.1.3
3
3
  * https://github.com/bcardarlela/client_side_validations
4
4
  *
5
5
  * Copyright (c) 2011 Brian Cardarella
@@ -165,7 +165,7 @@ var clientSideValidations = {
165
165
  return options.messages.numericality;
166
166
  }
167
167
 
168
- if (options.only_integer && !/^\d+$/.test(element.val())) {
168
+ if (options.only_integer && !/^[+-]?\d+$/.test(element.val())) {
169
169
  return options.messages.only_integer;
170
170
  }
171
171
 
@@ -263,48 +263,54 @@ var clientSideValidations = {
263
263
  },
264
264
  remote: {
265
265
  uniqueness: function(element, options) {
266
- var data = {};
267
- data['case_sensitive'] = !!options.case_sensitive;
268
- if (options.id) {
269
- data['id'] = options.id;
270
- }
266
+ if ((message = clientSideValidations.validators.local.presence(element, options)) && options.allow_blank === true) {
267
+ return;
268
+ } else if (message) {
269
+ return message;
270
+ } else {
271
+ var data = {};
272
+ data['case_sensitive'] = !!options.case_sensitive;
273
+ if (options.id) {
274
+ data['id'] = options.id;
275
+ }
271
276
 
272
- if (options.scope) {
273
- data.scope = {}
274
- for (key in options.scope) {
275
- var scoped_element = jQuery('[name="' + element.attr('name').replace(/\[\w+]$/, '[' + key + ']' + '"]'));
276
- if (scoped_element[0] && scoped_element.val() != options.scope[key]) {
277
- data.scope[key] = scoped_element.val();
278
- scoped_element.unbind('change.' + element.id).bind('change.' + element.id, function() { element.trigger('change'); element.trigger('focusout'); });
279
- } else {
280
- data.scope[key] = options.scope[key];
277
+ if (options.scope) {
278
+ data.scope = {}
279
+ for (key in options.scope) {
280
+ var scoped_element = jQuery('[name="' + element.attr('name').replace(/\[\w+]$/, '[' + key + ']' + '"]'));
281
+ if (scoped_element[0] && scoped_element.val() != options.scope[key]) {
282
+ data.scope[key] = scoped_element.val();
283
+ scoped_element.unbind('change.' + element.id).bind('change.' + element.id, function() { element.trigger('change'); element.trigger('focusout'); });
284
+ } else {
285
+ data.scope[key] = options.scope[key];
286
+ }
281
287
  }
282
288
  }
283
- }
284
289
 
285
- // Kind of a hack but this will isolate the resource name and attribute.
286
- // e.g. user[records_attributes][0][title] => records[title]
287
- // e.g. user[record_attributes][title] => record[title]
288
- // Server side handles classifying the resource properly
289
- if (/_attributes]/.test(element.attr('name'))) {
290
- var name = element.attr('name').match(/\[\w+_attributes]/g).pop().match(/\[(\w+)_attributes]/).pop();
291
- name += /(\[\w+])$/.exec(element.attr('name'))[1];
292
- } else {
293
- var name = element.attr('name');
294
- }
290
+ // Kind of a hack but this will isolate the resource name and attribute.
291
+ // e.g. user[records_attributes][0][title] => records[title]
292
+ // e.g. user[record_attributes][title] => record[title]
293
+ // Server side handles classifying the resource properly
294
+ if (/_attributes]/.test(element.attr('name'))) {
295
+ var name = element.attr('name').match(/\[\w+_attributes]/g).pop().match(/\[(\w+)_attributes]/).pop();
296
+ name += /(\[\w+])$/.exec(element.attr('name'))[1];
297
+ } else {
298
+ var name = element.attr('name');
299
+ }
295
300
 
296
- // Override the name if a nested module class is passed
297
- if (options['class']) {
298
- name = options['class'] + '[' + name.split('[')[1]
299
- }
300
- data[name] = element.val();
301
+ // Override the name if a nested module class is passed
302
+ if (options['class']) {
303
+ name = options['class'] + '[' + name.split('[')[1]
304
+ }
305
+ data[name] = element.val();
301
306
 
302
- if (jQuery.ajax({
303
- url: '/validators/uniqueness',
304
- data: data,
305
- async: false
306
- }).status == 200) {
307
- return options.message;
307
+ if (jQuery.ajax({
308
+ url: '/validators/uniqueness',
309
+ data: data,
310
+ async: false
311
+ }).status == 200) {
312
+ return options.message;
313
+ }
308
314
  }
309
315
  }
310
316
  }
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: client_side_validations
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.1.1
5
+ version: 3.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brian Cardarella
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-10-25 00:00:00 -04:00
13
+ date: 2011-11-01 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -19,9 +19,9 @@ dependencies:
19
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
- - - "="
22
+ - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: 3.1.0.rc4
24
+ version: 3.1.0
25
25
  type: :development
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
@@ -85,9 +85,9 @@ dependencies:
85
85
  requirement: &id007 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
- - - ">="
88
+ - - ~>
89
89
  - !ruby/object:Gem::Version
90
- version: "0"
90
+ version: 1.5.0
91
91
  type: :development
92
92
  version_requirements: *id007
93
93
  - !ruby/object:Gem::Dependency
@@ -98,7 +98,7 @@ dependencies:
98
98
  requirements:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: 2.0.0.rc3
101
+ version: 2.0.0
102
102
  type: :development
103
103
  version_requirements: *id008
104
104
  - !ruby/object:Gem::Dependency