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,217 +0,0 @@
1
- require 'action_view/cases/helper'
2
-
3
- class ClientSideValidations::LegacyActionViewHelpersTest < ActionView::TestCase
4
- include ActionViewTestSetup
5
-
6
- def test_text_field
7
- form_for(@post) do |f|
8
- concat f.text_field(:cost)
9
- end
10
-
11
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
12
- %{<input id="post_cost" name="post[cost]" size="30" type="text" />}
13
- end
14
- assert_equal expected, output_buffer
15
- end
16
-
17
- def test_password_field
18
- form_for(@post) do |f|
19
- concat f.password_field(:cost)
20
- end
21
-
22
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
23
- %{<input id="post_cost" name="post[cost]" size="30" type="password" />}
24
- end
25
- assert_equal expected, output_buffer
26
- end
27
-
28
- def test_file_field
29
- form_for(@post) do |f|
30
- concat f.file_field(:cost)
31
- end
32
-
33
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", :method => :put, :file => true) do
34
- %{<input id="post_cost" name="post[cost]" type="file" />}
35
- end
36
- assert_equal expected, output_buffer
37
- end
38
-
39
- def test_text_area
40
- form_for(@post) do |f|
41
- concat f.text_area(:cost)
42
- end
43
-
44
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
45
- %{<textarea cols="40" id="post_cost" name="post[cost]" rows="20"></textarea>}
46
- end
47
- assert_equal expected, output_buffer
48
- end
49
-
50
- def test_search_field
51
- form_for(@post) do |f|
52
- concat f.search_field(:cost)
53
- end
54
-
55
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
56
- %{<input id="post_cost" name="post[cost]" size="30" type="search" />}
57
- end
58
- assert_equal expected, output_buffer
59
- end
60
-
61
- def test_telephone_field
62
- form_for(@post) do |f|
63
- concat f.telephone_field(:cost)
64
- end
65
-
66
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
67
- %{<input id="post_cost" name="post[cost]" size="30" type="tel" />}
68
- end
69
- assert_equal expected, output_buffer
70
- end
71
-
72
- def test_phone_field
73
- form_for(@post) do |f|
74
- concat f.phone_field(:cost)
75
- end
76
-
77
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
78
- %{<input id="post_cost" name="post[cost]" size="30" type="tel" />}
79
- end
80
- assert_equal expected, output_buffer
81
- end
82
-
83
- def test_url_field
84
- form_for(@post) do |f|
85
- concat f.url_field(:cost)
86
- end
87
-
88
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
89
- %{<input id="post_cost" name="post[cost]" size="30" type="url" />}
90
- end
91
- assert_equal expected, output_buffer
92
- end
93
-
94
- def test_email_field
95
- form_for(@post) do |f|
96
- concat f.email_field(:cost)
97
- end
98
-
99
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
100
- %{<input id="post_cost" name="post[cost]" size="30" type="email" />}
101
- end
102
- assert_equal expected, output_buffer
103
- end
104
-
105
- def test_number_field
106
- form_for(@post) do |f|
107
- concat f.number_field(:cost)
108
- end
109
-
110
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
111
- %{<input id="post_cost" name="post[cost]" size="30" type="number" />}
112
- end
113
- assert_equal expected, output_buffer
114
- end
115
-
116
- def test_range_field
117
- form_for(@post) do |f|
118
- concat f.range_field(:cost)
119
- end
120
-
121
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
122
- %{<input id="post_cost" name="post[cost]" size="30" type="range" />}
123
- end
124
- assert_equal expected, output_buffer
125
- end
126
-
127
- def test_check_box
128
- form_for(@post) do |f|
129
- concat f.check_box(:cost)
130
- end
131
-
132
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
133
- %{<input name="post[cost]" type="hidden" value="0" />} +
134
- %{<input id="post_cost" name="post[cost]" type="checkbox" value="1" />}
135
- end
136
- assert_equal expected, output_buffer
137
- end
138
-
139
- def test_radio_button
140
- form_for(@post) do |f|
141
- concat f.radio_button(:cost, "10")
142
- end
143
-
144
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
145
- %{<input id="post_cost_10" name="post[cost]" type="radio" value="10" />}
146
- end
147
- assert_equal expected, output_buffer
148
- end
149
-
150
- def test_fields_for
151
- result = fields_for(@comment) do |c|
152
- c.text_field(:title)
153
- end
154
-
155
- expected = %{<input id="comment_title" name="comment[title]" size="30" type="text" />}
156
-
157
- assert_equal expected, result
158
- end
159
-
160
- def test_select
161
- form_for(@post) do |f|
162
- concat f.select(:cost, [])
163
- end
164
-
165
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
166
- %{<select id="post_cost" name="post[cost]"></select>}
167
- end
168
- assert_equal expected, output_buffer
169
- end
170
-
171
- def test_select_multiple
172
- form_for(@post) do |f|
173
- concat f.select(:cost, [], {}, :multiple => true)
174
- end
175
-
176
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
177
- %{<select id="post_cost" multiple="multiple" name="post[cost][]"></select>}
178
- end
179
- assert_equal expected, output_buffer
180
- end
181
-
182
- def test_collection_select
183
- form_for(@post) do |f|
184
- concat f.collection_select(:cost, [], :id, :name)
185
- end
186
-
187
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
188
- %{<select id="post_cost" name="post[cost]"></select>}
189
- end
190
- assert_equal expected, output_buffer
191
- end
192
-
193
- def test_grouped_collection_select
194
- form_for(@post) do |f|
195
- concat f.grouped_collection_select(:cost, [], :group_method, :group_label_method, :id, :name)
196
- end
197
-
198
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
199
- %{<select id="post_cost" name="post[cost]"></select>}
200
- end
201
- assert_equal expected, output_buffer
202
- end
203
-
204
- def test_time_zone_select
205
- zones = mock('TimeZones')
206
- zones.stubs(:all).returns([])
207
- form_for(@post) do |f|
208
- concat f.time_zone_select(:cost, nil, :model => zones)
209
- end
210
-
211
- expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") do
212
- %{<select id="post_cost" name="post[cost]"></select>}
213
- end
214
- assert_equal expected, output_buffer
215
- end
216
- end
217
-
@@ -1,3 +0,0 @@
1
- require 'active_model'
2
- require 'action_view/models/comment'
3
- require 'action_view/models/post'
@@ -1,35 +0,0 @@
1
- class Comment
2
- extend ActiveModel::Naming
3
- include ActiveModel::Conversion
4
- include ActiveModel::Validations
5
-
6
- attr_reader :id
7
- attr_reader :post_id
8
- attr_reader :title
9
-
10
- validates_presence_of :title
11
-
12
- def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end
13
- def to_key; id ? [id] : nil end
14
- def save; @id = 1; @post_id = 1 end
15
- def persisted?; @id.present? end
16
- def to_param; @id; end
17
- def name
18
- @id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
19
- end
20
-
21
- attr_accessor :relevances
22
- def relevances_attributes=(attributes); end
23
-
24
- def client_side_validation_hash
25
- {
26
- :title => {
27
- :presence => {
28
- :message => "can't be blank"
29
- }
30
- }
31
- }
32
- end
33
-
34
- end
35
-
@@ -1,35 +0,0 @@
1
- class Post < Struct.new(:title, :author_name, :body, :secret, :written_on, :cost)
2
- extend ActiveModel::Naming
3
- include ActiveModel::Conversion
4
- extend ActiveModel::Translation
5
-
6
- alias_method :secret?, :secret
7
-
8
- def persisted=(boolean)
9
- @persisted = boolean
10
- end
11
-
12
- def persisted?
13
- @persisted
14
- end
15
-
16
- def client_side_validation_hash
17
- {
18
- :cost => {
19
- :presence => {
20
- :message => "can't be blank"
21
- }
22
- }
23
- }
24
- end
25
-
26
- attr_accessor :author
27
- def author_attributes=(attributes); end
28
-
29
- attr_accessor :comments, :comment_ids
30
- def comments_attributes=(attributes); end
31
-
32
- attr_accessor :tags
33
- def tags_attributes=(attributes); end
34
- end
35
-
@@ -1,4 +0,0 @@
1
- require 'base_helper'
2
- require 'active_model'
3
- require 'client_side_validations/active_model'
4
- require 'active_model/models/person'
@@ -1,16 +0,0 @@
1
- require 'active_model/cases/test_base'
2
-
3
- class ActiveModel::AcceptanceValidatorTest < ClientSideValidations::ActiveModelTestBase
4
-
5
- def test_acceptance_client_side_hash
6
- expected_hash = { :message => "must be accepted", :accept => "1" }
7
- assert_equal expected_hash, AcceptanceValidator.new(:attributes => [:name]).client_side_hash(@person, :age)
8
- end
9
-
10
- def test_acceptance_client_side_hash_with_custom_message
11
- expected_hash = { :message => "you must accept", :accept => "1" }
12
- assert_equal expected_hash, AcceptanceValidator.new(:attributes => [:name], :message => "you must accept").client_side_hash(@person, :age)
13
- end
14
-
15
- end
16
-
@@ -1,11 +0,0 @@
1
- require 'active_model/cases/helper'
2
-
3
- class ClientSideValidations::ActiveModelTestBase < ActiveModel::TestCase
4
- include ActiveModel::Validations
5
-
6
- def setup
7
- @person = Person.new
8
- end
9
-
10
- end
11
-
@@ -1,16 +0,0 @@
1
- require 'active_model/cases/test_base'
2
-
3
- class ActiveModel::ConfirmationValidatorTest < ClientSideValidations::ActiveModelTestBase
4
-
5
- def test_confirmation_client_side_hash
6
- expected_hash = { :message => "doesn't match confirmation" }
7
- assert_equal expected_hash, ConfirmationValidator.new(:attributes => [:name]).client_side_hash(@person, :age)
8
- end
9
-
10
- def test_confirmation_client_side_hash_with_custom_message
11
- expected_hash = { :message => "you must confirm" }
12
- assert_equal expected_hash, ConfirmationValidator.new(:attributes => [:name], :message => "you must confirm").client_side_hash(@person, :age)
13
- end
14
-
15
- end
16
-
@@ -1,20 +0,0 @@
1
- require 'active_model/cases/test_base'
2
-
3
- class ActiveModel::ExclusionValidatorTest < ClientSideValidations::ActiveModelTestBase
4
-
5
- def test_exclusion_client_side_hash
6
- expected_hash = { :message => "is reserved", :in => [1, 2] }
7
- assert_equal expected_hash, ExclusionValidator.new(:attributes => [:name], :in => [1, 2]).client_side_hash(@person, :age)
8
- end
9
-
10
- def test_exclusion_client_side_hash_with_custom_message
11
- expected_hash = { :message => "is exclusive", :in => [1, 2] }
12
- assert_equal expected_hash, ExclusionValidator.new(:attributes => [:name], :in => [1, 2], :message => "is exclusive").client_side_hash(@person, :age)
13
- end
14
-
15
- def test_exclusion_client_side_hash_with_ranges
16
- expected_hash = { :message => "is reserved", :range => 1..2 }
17
- assert_equal expected_hash, ExclusionValidator.new(:attributes => [:name], :in => 1..2).client_side_hash(@person, :age)
18
- end
19
- end
20
-
@@ -1,21 +0,0 @@
1
- require 'active_model/cases/test_base'
2
-
3
- class ActiveModel::FormatValidatorTest < ClientSideValidations::ActiveModelTestBase
4
-
5
- def test_format_client_side_hash
6
- expected_hash = { :message => "is invalid", :with => /.+/ }
7
- assert_equal expected_hash, FormatValidator.new(:attributes => [:name], :with => /.+/).client_side_hash(@person, :age)
8
- end
9
-
10
- def test_format_client_side_hash_without
11
- expected_hash = { :message => "is invalid", :without => /.+/ }
12
- assert_equal expected_hash, FormatValidator.new(:attributes => [:name], :without => /.+/).client_side_hash(@person, :age)
13
- end
14
-
15
- def test_format_client_side_hash_with_custom_message
16
- expected_hash = { :message => "is wrong format", :with => /.+/ }
17
- assert_equal expected_hash, FormatValidator.new(:attributes => [:name], :with => /.+/, :message => "is wrong format").client_side_hash(@person, :age)
18
- end
19
-
20
- end
21
-
@@ -1,21 +0,0 @@
1
- require 'active_model/cases/test_base'
2
-
3
- class ActiveModel::InclusionValidatorTest < ClientSideValidations::ActiveModelTestBase
4
-
5
- def test_inclusion_client_side_hash
6
- expected_hash = { :message => "is not included in the list", :in => [1, 2] }
7
- assert_equal expected_hash, InclusionValidator.new(:attributes => [:name], :in => [1, 2]).client_side_hash(@person, :age)
8
- end
9
-
10
- def test_inclusion_client_side_hash_with_custom_message
11
- expected_hash = { :message => "is not a choice", :in => [1, 2] }
12
- assert_equal expected_hash, InclusionValidator.new(:attributes => [:name], :in => [1, 2], :message => "is not a choice").client_side_hash(@person, :age)
13
- end
14
-
15
- def test_inclusion_client_side_hash_with_range
16
- expected_hash = { :message => "is not included in the list", :range => 1..2 }
17
- assert_equal expected_hash, InclusionValidator.new(:attributes => [:name], :in => 1..2).client_side_hash(@person, :age)
18
- end
19
-
20
- end
21
-
@@ -1,61 +0,0 @@
1
- require 'active_model/cases/test_base'
2
-
3
- class ActiveModel::LengthValidatorTest < ClientSideValidations::ActiveModelTestBase
4
-
5
- def test_length_client_side_hash
6
- expected_hash = {
7
- :messages => {
8
- :is => "is the wrong length (should be 10 characters)"
9
- },
10
- :is => 10
11
- }
12
- assert_equal expected_hash, LengthValidator.new(:attributes => [:age], :is => 10).client_side_hash(@person, :first_name)
13
- end
14
-
15
- def test_length_client_side_hash_with_custom_message
16
- expected_hash = {
17
- :messages => {
18
- :is => "is the wrong length (should be 10 words)"
19
- },
20
- :is => 10
21
- }
22
- assert_equal expected_hash, LengthValidator.new(:attributes => [:age], :is => 10, :wrong_length => "is the wrong length (should be %{count} words)").client_side_hash(@person, :first_name)
23
- end
24
-
25
- def test_length_client_side_hash_with_js_tokenizer
26
- expected_hash = {
27
- :messages => {
28
- :is => "is the wrong length (should be 10 characters)"
29
- },
30
- :is => 10,
31
- :js_tokenizer => %q{match(/\w+/g)}
32
- }
33
- assert_equal expected_hash, LengthValidator.new(:attributes => [:age], :is => 10, :tokenizer => proc { |value| value.split(/\w+/) }, :js_tokenizer => %q{match(/\w+/g)}).client_side_hash(@person, :first_name)
34
- end
35
-
36
- def test_length_client_side_hash_with_minimum_and_maximum
37
- expected_hash = {
38
- :messages => {
39
- :minimum => "is too short (minimum is 5 characters)",
40
- :maximum => "is too long (maximum is 10 characters)"
41
- },
42
- :minimum => 5,
43
- :maximum => 10
44
- }
45
- assert_equal expected_hash, LengthValidator.new(:attributes => [:age], :minimum => 5, :maximum => 10).client_side_hash(@person, :first_name)
46
- end
47
-
48
- def test_length_client_side_hash_with_range
49
- expected_hash = {
50
- :messages => {
51
- :minimum => "is too short (minimum is 5 characters)",
52
- :maximum => "is too long (maximum is 10 characters)"
53
- },
54
- :minimum => 5,
55
- :maximum => 10
56
- }
57
- assert_equal expected_hash, LengthValidator.new(:attributes => [:age], :within => 5..10).client_side_hash(@person, :first_name)
58
- end
59
-
60
- end
61
-