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,56 +0,0 @@
1
- require 'active_record/cases/test_base'
2
-
3
- class ActiveRecord::UniquenessValidatorTest < ClientSideValidations::ActiveRecordTestBase
4
-
5
- def test_uniqueness_client_side_hash
6
- expected_hash = { :message => "has already been taken", :case_sensitive => true }
7
- assert_equal expected_hash, UniquenessValidator.new(:attributes => [:name]).client_side_hash(@user, :name)
8
- end
9
-
10
- def test_uniqueness_client_side_hash_with_custom_message
11
- expected_hash = { :message => "is not available", :case_sensitive => true }
12
- assert_equal expected_hash, UniquenessValidator.new(:attributes => [:name], :message => "is not available").client_side_hash(@user, :name)
13
- end
14
-
15
- def test_uniqueness_client_side_hash
16
- @user.stubs(:new_record?).returns(false)
17
- @user.stubs(:id).returns(1)
18
- expected_hash = { :message => "has already been taken", :case_sensitive => true, :id => 1 }
19
- assert_equal expected_hash, UniquenessValidator.new(:attributes => [:name]).client_side_hash(@user, :name)
20
- end
21
-
22
- def test_uniqueness_client_side_hash_with_single_scope_item
23
- @user.stubs(:age).returns(30)
24
- @user.stubs(:title).returns("test title")
25
- expected_hash = { :message => "has already been taken", :case_sensitive => true, :scope => {:title => "test title"} }
26
- result_hash = UniquenessValidator.new(:attributes => [:name], :scope => :title).client_side_hash(@user, :name)
27
- assert_equal expected_hash, result_hash
28
- end
29
-
30
- def test_uniqueness_client_side_hash_with_multiple_scope_items
31
- @user.stubs(:age).returns(30)
32
- @user.stubs(:title).returns("test title")
33
- expected_hash = { :message => "has already been taken", :case_sensitive => true, :scope => {:age => 30, :title => "test title"} }
34
- result_hash = UniquenessValidator.new(:attributes => [:name], :scope => [:age, :title]).client_side_hash(@user, :name)
35
- assert_equal expected_hash, result_hash
36
- end
37
-
38
- def test_uniqueness_client_side_hash_with_empty_scope_array
39
- expected_hash = { :message => "has already been taken", :case_sensitive => true }
40
- result_hash = UniquenessValidator.new(:attributes => [:name], :scope => []).client_side_hash(@user, :name)
41
- assert_equal expected_hash, result_hash
42
- end
43
-
44
- def test_uniqueness_client_side_hash_when_nested_module
45
- @user = ActiveRecordTestModule::User2.new
46
- expected_hash = { :message => "has already been taken", :case_sensitive => true, :class => 'active_record_test_module/user2' }
47
- assert_equal expected_hash, UniquenessValidator.new(:attributes => [:name]).client_side_hash(@user, :name)
48
- end
49
-
50
- def test_uniqueness_client_side_hash_with_allow_blank
51
- expected_hash = { :message => "has already been taken", :case_sensitive => true, :allow_blank => true }
52
- assert_equal expected_hash, UniquenessValidator.new(:attributes => [:name], :allow_blank => true).client_side_hash(@user, :name)
53
- end
54
-
55
- end
56
-
@@ -1,7 +0,0 @@
1
- guids_table = %{CREATE TABLE guids (id INTEGER PRIMARY KEY, key text);}
2
- ActiveRecord::Base.connection.execute(guids_table)
3
-
4
- class Guid < ActiveRecord::Base
5
-
6
- end
7
-
@@ -1,14 +0,0 @@
1
- users_table = %{CREATE TABLE users (id INTEGER PRIMARY KEY, age INTEGER, name TEXT, email TEXT, title VARCHAR(5));}
2
- ActiveRecord::Base.connection.execute(users_table)
3
-
4
- class User < ActiveRecord::Base
5
-
6
- end
7
-
8
- class IneptWizard < User; end
9
- class Conjurer < IneptWizard; end
10
- class Thaumaturgist < Conjurer; end
11
-
12
- module ActiveRecordTestModule
13
- class User2 < User; end
14
- end
data/test/base_helper.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- Bundler.setup
4
- require 'test/unit'
5
- if RUBY_VERSION >= '1.9.3'
6
- require 'debugger'
7
- end
8
- require 'mocha'
9
- require 'rails'
10
-
11
- # Pulled from railties/test/abstract_unit in Rails 3.1
12
- module TestApp
13
- class Application < Rails::Application
14
- config.root = File.dirname(__FILE__)
15
- config.active_support.deprecation = :log
16
- config.logger = Logger.new(STDOUT)
17
- end
18
- end
19
-
20
-
21
- module ClientSideValidations; end
@@ -1,46 +0,0 @@
1
- require 'base_helper'
2
- require 'client_side_validations/core_ext'
3
-
4
- class CoreExtTest < Test::Unit::TestCase
5
- def test_regexp_as_json
6
- regexp = //
7
- assert_equal regexp, regexp.as_json
8
- end
9
-
10
- def test_regexp_replace_A_and_Z
11
- test_regexp = /\A\Z/
12
- expected_regexp = /^$/
13
- assert_equal expected_regexp, test_regexp.as_json
14
- end
15
-
16
- def test_regexp_replace_a_and_z
17
- test_regexp = /\A\z/
18
- expected_regexp = /^$/
19
- assert_equal expected_regexp, test_regexp.as_json
20
- end
21
-
22
- def test_regexp_to_json
23
- assert_equal "/^$/", /\A\Z/.to_json(nil)
24
- end
25
-
26
- def test_regexp_encode_json
27
- assert_equal "//", //.encode_json(nil)
28
- end
29
-
30
- def test_regexp_as_jason_with_options
31
- assert_equal //i, //i.as_json
32
- end
33
-
34
- def test_range_as_json
35
- assert_equal [1,3], (1..3).as_json
36
- end
37
-
38
- def test_range_to_json
39
- assert_equal '[1, 3]', (1..3).to_json(nil)
40
- end
41
-
42
- def test_range_as_json_with_floats
43
- assert_equal [0.5,5.5], (0.5..5.5).as_json
44
- end
45
- end
46
-
@@ -1,7 +0,0 @@
1
- # encoding: utf-8
2
- require 'active_support'
3
- require 'formtastic/railtie' if defined?(::Rails)
4
- require 'formtastic/engine' if defined?(::Rails)
5
- require 'formtastic'
6
- require 'client_side_validations/formtastic'
7
-
@@ -1,11 +0,0 @@
1
- require 'formtastic/cases/helper'
2
-
3
- class ClientSideValidations::Formtastic::FormBuilderTest < Test::Unit::TestCase
4
- def test_client_side_form_js_hash
5
- expected = {
6
- :type => 'Formtastic::FormBuilder',
7
- :inline_error_class => 'inline-errors'
8
- }
9
- assert_equal expected, Formtastic::FormBuilder.client_side_form_settings(nil, nil)
10
- end
11
- end
@@ -1,21 +0,0 @@
1
- require 'action_view/cases/helper'
2
- require 'formtastic/cases/helper'
3
-
4
- class ClientSideValidations::Formtastic::FormHelperTest < ActionView::TestCase
5
- include ActionViewTestSetup
6
- include Formtastic::Helpers::FormHelper
7
-
8
- def client_side_form_settings_helper
9
- ""
10
- end
11
-
12
- def test_semantic_form_for
13
- semantic_form_for(@post, :validate => true) do |f|
14
- concat f.input(:cost)
15
- end
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]" 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
- 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
- end
20
-
21
- end
@@ -1,70 +0,0 @@
1
- require 'rails/generators/test_case'
2
- require 'generators/client_side_validations/install_generator'
3
- require 'generators/client_side_validations/copy_asset_generator'
4
-
5
- class InstallGeneratorTest < Rails::Generators::TestCase
6
- tests ClientSideValidations::Generators::InstallGenerator
7
- destination File.expand_path('../../tmp', __FILE__)
8
- setup :prepare_destination
9
-
10
- test 'Assert all files are properly created when no asset pipeline present' do
11
- stub_configuration
12
- run_generator
13
- assert_file 'config/initializers/client_side_validations.rb'
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'))
36
- end
37
- end
38
-
39
- class CopyAssetGeneratorTest < Rails::Generators::TestCase
40
- tests ClientSideValidations::Generators::CopyAssetGenerator
41
- destination File.expand_path('../../tmp', __FILE__)
42
- setup :prepare_destination
43
-
44
- test 'Assert file is properly created when no asset pipeline present' do
45
- stub_configuration
46
- run_generator
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'))
68
- end
69
- end
70
-
@@ -1,3 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('..', __FILE__)
2
- require 'server'
3
- run Sinatra::Application
@@ -1,54 +0,0 @@
1
- module('Element Validate After Callback', {
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: {"user[name]":{"presence":{"message": "must be present"}}}
8
- }
9
-
10
- $('#qunit-fixture')
11
- .append($('<span id="result" />'))
12
- .append($('<form />', {
13
- action: '/users',
14
- 'data-validate': true,
15
- method: 'post',
16
- id: 'new_user'
17
- }))
18
- .find('form')
19
- .append($('<input />', {
20
- name: 'user[name]',
21
- id: 'user_name',
22
- 'data-validate': 'true',
23
- type: 'text'
24
- }))
25
- .append($('<label for="user_name">Name</label>'));
26
-
27
- clientSideValidations.callbacks.element.after = function(element, message) {
28
- $('#result').text('Element Validate After ' + element.attr('id'));
29
- }
30
- $('form#new_user').validate();
31
- },
32
- teardown: function() {
33
- clientSideValidations.callbacks.element.after = function(element, eventData) {}
34
- }
35
- });
36
-
37
- test('runs callback when form element validate', function() {
38
- var input = $('input');
39
-
40
- equal($('#result').text(), '');
41
-
42
- input.trigger('focusout');
43
- equal($('#result').text(), 'Element Validate After user_name');
44
- });
45
-
46
- test('runs callback when form validates', function() {
47
- var form = $('form'), input = form.find('input');
48
-
49
- equal($('#result').text(), '');
50
-
51
- form.submit();
52
- equal($('#result').text(), 'Element Validate After user_name');
53
- });
54
-
@@ -1,54 +0,0 @@
1
- module('Element Validate Before Callback', {
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: {"user[name]":{"{presence":{"message": "must be present"}}}
8
- }
9
-
10
- $('#qunit-fixture')
11
- .append($('<span id="result" />'))
12
- .append($('<form />', {
13
- action: '/users',
14
- 'data-validate': true,
15
- method: 'post',
16
- id: 'new_user'
17
- }))
18
- .find('form')
19
- .append($('<input />', {
20
- name: 'user[name]',
21
- id: 'user_name',
22
- 'data-validate': 'true',
23
- type: 'text'
24
- }))
25
- .append($('<label for="user_name">Name</label>'));
26
-
27
- clientSideValidations.callbacks.element.before = function(element) {
28
- $('#result').text('Element Validate Before ' + element.attr('id'));
29
- }
30
- $('form#new_user').validate();
31
- },
32
- teardown: function() {
33
- clientSideValidations.callbacks.element.before = function(element, eventData) {}
34
- }
35
- });
36
-
37
- test('runs callback when form element validate', function() {
38
- var input = $('input');
39
-
40
- equal($('#result').text(), '');
41
-
42
- input.trigger('focusout');
43
- equal($('#result').text(), 'Element Validate Before user_name');
44
- });
45
-
46
- test('runs callback when form validates', function() {
47
- var form = $('form'), input = form.find('input');
48
-
49
- equal($('#result').text(), '');
50
-
51
- form.submit();
52
- equal($('#result').text(), 'Element Validate Before user_name');
53
- });
54
-
@@ -1,70 +0,0 @@
1
- module('Element Validate Fail Callback', {
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: {"user[name]":{"presence":{"message": "must be present"}}}
8
- }
9
-
10
- $('#qunit-fixture')
11
- .append($('<span id="result" />'))
12
- .append($('<form />', {
13
- action: '/users',
14
- 'data-validate': true,
15
- method: 'post',
16
- id: 'new_user'
17
- }))
18
- .find('form')
19
- .append($('<input />', {
20
- name: 'user[name]',
21
- id: 'user_name',
22
- 'data-validate': 'true',
23
- type: 'text'
24
- }))
25
- .append($('<label for="user_name">Name</label>'));
26
-
27
- clientSideValidations.callbacks.element.fail = function(element, message) {
28
- $('#result').text('Element Validate Fail ' + element.attr('id') + ' ' + message);
29
- }
30
- $('form#new_user').validate();
31
- },
32
- teardown: function() {
33
- clientSideValidations.callbacks.element.fail = function(element, message, callback) { callback(); }
34
- }
35
- });
36
-
37
- test('runs callback when form element validate', function() {
38
- var input = $('input');
39
-
40
- equal($('#result').text(), '');
41
-
42
- input.val('test')
43
- input.trigger('change');
44
- input.trigger('focusout');
45
- equal($('#result').text(), '');
46
-
47
- input.val('')
48
- input.trigger('change');
49
- input.trigger('focusout');
50
- equal($('#result').text(), 'Element Validate Fail user_name must be present');
51
- });
52
-
53
- test('runs callback when form validates', function() {
54
- var form = $('form'), input = form.find('input');
55
-
56
- equal($('#result').text(), '');
57
-
58
- input.val('test')
59
- input.trigger('change');
60
- form.trigger('submit');
61
-
62
- equal($('#result').text(), '');
63
-
64
- input.val('')
65
- input.trigger('change');
66
- form.trigger('submit');
67
-
68
- equal($('#result').text(), 'Element Validate Fail user_name must be present');
69
- });
70
-