formtastic 2.0.2 → 2.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/.gitignore +4 -1
  2. data/Appraisals +11 -0
  3. data/CHANGELOG +2 -2
  4. data/Gemfile +0 -2
  5. data/README.textile +183 -151
  6. data/Rakefile +9 -5
  7. data/app/assets/stylesheets/formtastic.css +16 -3
  8. data/formtastic.gemspec +6 -2
  9. data/gemfiles/rails-3.0.gemfile +7 -0
  10. data/gemfiles/rails-3.1.gemfile +7 -0
  11. data/gemfiles/rails-3.2.gemfile +7 -0
  12. data/lib/formtastic.rb +10 -2
  13. data/lib/formtastic/actions.rb +11 -0
  14. data/lib/formtastic/actions/base.rb +156 -0
  15. data/lib/formtastic/actions/button_action.rb +72 -0
  16. data/lib/formtastic/actions/buttonish.rb +17 -0
  17. data/lib/formtastic/actions/input_action.rb +68 -0
  18. data/lib/formtastic/actions/link_action.rb +87 -0
  19. data/lib/formtastic/engine.rb +5 -1
  20. data/lib/formtastic/form_builder.rb +3 -0
  21. data/lib/formtastic/helpers.rb +2 -1
  22. data/lib/formtastic/helpers/action_helper.rb +109 -0
  23. data/lib/formtastic/helpers/actions_helper.rb +168 -0
  24. data/lib/formtastic/helpers/buttons_helper.rb +22 -9
  25. data/lib/formtastic/helpers/errors_helper.rb +0 -54
  26. data/lib/formtastic/helpers/fieldset_wrapper.rb +10 -5
  27. data/lib/formtastic/helpers/form_helper.rb +2 -2
  28. data/lib/formtastic/helpers/input_helper.rb +1 -10
  29. data/lib/formtastic/helpers/inputs_helper.rb +6 -3
  30. data/lib/formtastic/i18n.rb +3 -2
  31. data/lib/formtastic/inputs/base.rb +11 -3
  32. data/lib/formtastic/inputs/base/choices.rb +6 -1
  33. data/lib/formtastic/inputs/base/collections.rb +36 -13
  34. data/lib/formtastic/inputs/base/grouped_collections.rb +1 -1
  35. data/lib/formtastic/inputs/base/numeric.rb +50 -0
  36. data/lib/formtastic/inputs/base/options.rb +1 -1
  37. data/lib/formtastic/inputs/base/placeholder.rb +17 -0
  38. data/lib/formtastic/inputs/base/stringish.rb +2 -7
  39. data/lib/formtastic/inputs/base/timeish.rb +21 -5
  40. data/lib/formtastic/inputs/base/validations.rb +1 -1
  41. data/lib/formtastic/inputs/base/wrapping.rb +10 -3
  42. data/lib/formtastic/inputs/boolean_input.rb +10 -2
  43. data/lib/formtastic/inputs/check_boxes_input.rb +18 -9
  44. data/lib/formtastic/inputs/country_input.rb +2 -2
  45. data/lib/formtastic/inputs/date_input.rb +19 -1
  46. data/lib/formtastic/inputs/datetime_input.rb +1 -1
  47. data/lib/formtastic/inputs/email_input.rb +2 -1
  48. data/lib/formtastic/inputs/file_input.rb +1 -1
  49. data/lib/formtastic/inputs/hidden_input.rb +1 -1
  50. data/lib/formtastic/inputs/number_input.rb +6 -36
  51. data/lib/formtastic/inputs/password_input.rb +2 -1
  52. data/lib/formtastic/inputs/phone_input.rb +3 -2
  53. data/lib/formtastic/inputs/radio_input.rb +1 -1
  54. data/lib/formtastic/inputs/range_input.rb +8 -32
  55. data/lib/formtastic/inputs/search_input.rb +2 -1
  56. data/lib/formtastic/inputs/select_input.rb +56 -28
  57. data/lib/formtastic/inputs/string_input.rb +3 -1
  58. data/lib/formtastic/inputs/text_input.rb +5 -4
  59. data/lib/formtastic/inputs/time_input.rb +4 -8
  60. data/lib/formtastic/inputs/time_zone_input.rb +1 -1
  61. data/lib/formtastic/inputs/url_input.rb +2 -1
  62. data/lib/formtastic/localized_string.rb +6 -94
  63. data/lib/formtastic/localizer.rb +110 -0
  64. data/lib/formtastic/version.rb +1 -1
  65. data/lib/generators/formtastic/form/form_generator.rb +105 -0
  66. data/lib/generators/templates/_form.html.erb +2 -2
  67. data/lib/generators/templates/_form.html.haml +4 -4
  68. data/lib/generators/templates/_form.html.slim +2 -2
  69. data/lib/generators/templates/formtastic.rb +4 -0
  70. data/lib/locale/en.yml +2 -0
  71. data/sample/basic_inputs.html +22 -0
  72. data/spec/actions/button_action_spec.rb +63 -0
  73. data/spec/actions/generic_action_spec.rb +484 -0
  74. data/spec/actions/input_action_spec.rb +59 -0
  75. data/spec/actions/link_action_spec.rb +92 -0
  76. data/spec/builder/semantic_fields_for_spec.rb +14 -0
  77. data/spec/generators/formtastic/form/form_generator_spec.rb +118 -0
  78. data/spec/generators/formtastic/install/install_generator_spec.rb +47 -0
  79. data/spec/helpers/action_helper_spec.rb +365 -0
  80. data/spec/helpers/actions_helper_spec.rb +143 -0
  81. data/spec/helpers/buttons_helper_spec.rb +39 -23
  82. data/spec/helpers/commit_button_helper_spec.rb +153 -93
  83. data/spec/helpers/inputs_helper_spec.rb +14 -0
  84. data/spec/i18n_spec.rb +11 -0
  85. data/spec/inputs/boolean_input_spec.rb +31 -2
  86. data/spec/inputs/check_boxes_input_spec.rb +29 -1
  87. data/spec/inputs/date_input_spec.rb +95 -0
  88. data/spec/inputs/datetime_input_spec.rb +49 -0
  89. data/spec/inputs/email_input_spec.rb +28 -0
  90. data/spec/inputs/file_input_spec.rb +28 -0
  91. data/spec/inputs/hidden_input_spec.rb +28 -0
  92. data/spec/inputs/include_blank_spec.rb +53 -45
  93. data/spec/inputs/number_input_spec.rb +34 -4
  94. data/spec/inputs/password_input_spec.rb +28 -0
  95. data/spec/inputs/phone_input_spec.rb +28 -0
  96. data/spec/inputs/placeholder_spec.rb +10 -10
  97. data/spec/inputs/radio_input_spec.rb +51 -6
  98. data/spec/inputs/range_input_spec.rb +30 -2
  99. data/spec/inputs/search_input_spec.rb +27 -0
  100. data/spec/inputs/select_input_spec.rb +52 -6
  101. data/spec/inputs/string_input_spec.rb +28 -0
  102. data/spec/inputs/text_input_spec.rb +27 -0
  103. data/spec/inputs/time_input_spec.rb +67 -1
  104. data/spec/inputs/time_zone_input_spec.rb +28 -0
  105. data/spec/inputs/url_input_spec.rb +28 -0
  106. data/spec/inputs/with_options_spec.rb +43 -0
  107. data/spec/spec_helper.rb +22 -6
  108. data/spec/support/custom_macros.rb +6 -134
  109. data/spec/support/test_environment.rb +0 -1
  110. metadata +104 -17
  111. data/lib/formtastic/helpers/semantic_form_helper.rb +0 -11
  112. data/lib/formtastic/inputs/numeric_input.rb +0 -21
  113. data/lib/formtastic/railtie.rb +0 -12
  114. data/lib/formtastic/semantic_form_builder.rb +0 -11
  115. data/spec/builder/errors_spec.rb +0 -203
  116. data/spec/inputs/numeric_input_spec.rb +0 -41
@@ -9,7 +9,6 @@ RSpec.configure do |config|
9
9
  end
10
10
 
11
11
  require "action_controller/railtie"
12
- require "active_resource/railtie"
13
12
  require 'active_model'
14
13
 
15
14
  # Create a simple rails application for use in testing the viewhelper
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formtastic
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease:
4
+ hash: 62196465
5
+ prerelease: 6
6
6
  segments:
7
7
  - 2
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 2.0.2
10
+ - beta
11
+ - 1
12
+ version: 2.1.0.beta1
11
13
  platform: ruby
12
14
  authors:
13
15
  - Justin French
@@ -15,11 +17,11 @@ autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2011-10-06 00:00:00 +11:00
20
+ date: 2012-01-15 00:00:00 +11:00
19
21
  default_executable:
20
22
  dependencies:
21
23
  - !ruby/object:Gem::Dependency
22
- name: rails
24
+ name: actionpack
23
25
  prerelease: false
24
26
  requirement: &id001 !ruby/object:Gem::Requirement
25
27
  none: false
@@ -41,11 +43,12 @@ dependencies:
41
43
  requirements:
42
44
  - - ~>
43
45
  - !ruby/object:Gem::Version
44
- hash: 9
46
+ hash: 47
45
47
  segments:
46
48
  - 2
47
- - 5
48
- version: "2.5"
49
+ - 8
50
+ - 0
51
+ version: 2.8.0
49
52
  type: :development
50
53
  version_requirements: *id002
51
54
  - !ruby/object:Gem::Dependency
@@ -139,6 +142,64 @@ dependencies:
139
142
  version: "0"
140
143
  type: :development
141
144
  version_requirements: *id008
145
+ - !ruby/object:Gem::Dependency
146
+ name: tzinfo
147
+ prerelease: false
148
+ requirement: &id009 !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ hash: 3
154
+ segments:
155
+ - 0
156
+ version: "0"
157
+ type: :development
158
+ version_requirements: *id009
159
+ - !ruby/object:Gem::Dependency
160
+ name: ammeter
161
+ prerelease: false
162
+ requirement: &id010 !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ~>
166
+ - !ruby/object:Gem::Version
167
+ hash: 19
168
+ segments:
169
+ - 0
170
+ - 2
171
+ - 2
172
+ version: 0.2.2
173
+ type: :development
174
+ version_requirements: *id010
175
+ - !ruby/object:Gem::Dependency
176
+ name: appraisal
177
+ prerelease: false
178
+ requirement: &id011 !ruby/object:Gem::Requirement
179
+ none: false
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ hash: 3
184
+ segments:
185
+ - 0
186
+ version: "0"
187
+ type: :development
188
+ version_requirements: *id011
189
+ - !ruby/object:Gem::Dependency
190
+ name: rake
191
+ prerelease: false
192
+ requirement: &id012 !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ hash: 3
198
+ segments:
199
+ - 0
200
+ version: "0"
201
+ type: :development
202
+ version_requirements: *id012
142
203
  description: A Rails form builder plugin/gem with semantically rich and accessible markup
143
204
  email:
144
205
  - justin@indent.com.au
@@ -153,6 +214,7 @@ files:
153
214
  - .rspec
154
215
  - .travis.yml
155
216
  - .yardopts
217
+ - Appraisals
156
218
  - CHANGELOG
157
219
  - Gemfile
158
220
  - MIT-LICENSE
@@ -163,10 +225,21 @@ files:
163
225
  - app/assets/stylesheets/formtastic_ie6.css
164
226
  - app/assets/stylesheets/formtastic_ie7.css
165
227
  - formtastic.gemspec
228
+ - gemfiles/rails-3.0.gemfile
229
+ - gemfiles/rails-3.1.gemfile
230
+ - gemfiles/rails-3.2.gemfile
166
231
  - lib/formtastic.rb
232
+ - lib/formtastic/actions.rb
233
+ - lib/formtastic/actions/base.rb
234
+ - lib/formtastic/actions/button_action.rb
235
+ - lib/formtastic/actions/buttonish.rb
236
+ - lib/formtastic/actions/input_action.rb
237
+ - lib/formtastic/actions/link_action.rb
167
238
  - lib/formtastic/engine.rb
168
239
  - lib/formtastic/form_builder.rb
169
240
  - lib/formtastic/helpers.rb
241
+ - lib/formtastic/helpers/action_helper.rb
242
+ - lib/formtastic/helpers/actions_helper.rb
170
243
  - lib/formtastic/helpers/buttons_helper.rb
171
244
  - lib/formtastic/helpers/errors_helper.rb
172
245
  - lib/formtastic/helpers/fieldset_wrapper.rb
@@ -175,7 +248,6 @@ files:
175
248
  - lib/formtastic/helpers/input_helper.rb
176
249
  - lib/formtastic/helpers/inputs_helper.rb
177
250
  - lib/formtastic/helpers/reflection.rb
178
- - lib/formtastic/helpers/semantic_form_helper.rb
179
251
  - lib/formtastic/html_attributes.rb
180
252
  - lib/formtastic/i18n.rb
181
253
  - lib/formtastic/inputs.rb
@@ -191,7 +263,9 @@ files:
191
263
  - lib/formtastic/inputs/base/html.rb
192
264
  - lib/formtastic/inputs/base/labelling.rb
193
265
  - lib/formtastic/inputs/base/naming.rb
266
+ - lib/formtastic/inputs/base/numeric.rb
194
267
  - lib/formtastic/inputs/base/options.rb
268
+ - lib/formtastic/inputs/base/placeholder.rb
195
269
  - lib/formtastic/inputs/base/stringish.rb
196
270
  - lib/formtastic/inputs/base/timeish.rb
197
271
  - lib/formtastic/inputs/base/validations.rb
@@ -205,7 +279,6 @@ files:
205
279
  - lib/formtastic/inputs/file_input.rb
206
280
  - lib/formtastic/inputs/hidden_input.rb
207
281
  - lib/formtastic/inputs/number_input.rb
208
- - lib/formtastic/inputs/numeric_input.rb
209
282
  - lib/formtastic/inputs/password_input.rb
210
283
  - lib/formtastic/inputs/phone_input.rb
211
284
  - lib/formtastic/inputs/radio_input.rb
@@ -218,10 +291,10 @@ files:
218
291
  - lib/formtastic/inputs/time_zone_input.rb
219
292
  - lib/formtastic/inputs/url_input.rb
220
293
  - lib/formtastic/localized_string.rb
221
- - lib/formtastic/railtie.rb
222
- - lib/formtastic/semantic_form_builder.rb
294
+ - lib/formtastic/localizer.rb
223
295
  - lib/formtastic/util.rb
224
296
  - lib/formtastic/version.rb
297
+ - lib/generators/formtastic/form/form_generator.rb
225
298
  - lib/generators/formtastic/install/install_generator.rb
226
299
  - lib/generators/templates/_form.html.erb
227
300
  - lib/generators/templates/_form.html.haml
@@ -232,10 +305,17 @@ files:
232
305
  - sample/basic_inputs.html
233
306
  - sample/config.ru
234
307
  - sample/index.html
308
+ - spec/actions/button_action_spec.rb
309
+ - spec/actions/generic_action_spec.rb
310
+ - spec/actions/input_action_spec.rb
311
+ - spec/actions/link_action_spec.rb
235
312
  - spec/builder/custom_builder_spec.rb
236
313
  - spec/builder/error_proc_spec.rb
237
- - spec/builder/errors_spec.rb
238
314
  - spec/builder/semantic_fields_for_spec.rb
315
+ - spec/generators/formtastic/form/form_generator_spec.rb
316
+ - spec/generators/formtastic/install/install_generator_spec.rb
317
+ - spec/helpers/action_helper_spec.rb
318
+ - spec/helpers/actions_helper_spec.rb
239
319
  - spec/helpers/buttons_helper_spec.rb
240
320
  - spec/helpers/commit_button_helper_spec.rb
241
321
  - spec/helpers/form_helper_spec.rb
@@ -256,7 +336,6 @@ files:
256
336
  - spec/inputs/include_blank_spec.rb
257
337
  - spec/inputs/label_spec.rb
258
338
  - spec/inputs/number_input_spec.rb
259
- - spec/inputs/numeric_input_spec.rb
260
339
  - spec/inputs/password_input_spec.rb
261
340
  - spec/inputs/phone_input_spec.rb
262
341
  - spec/inputs/placeholder_spec.rb
@@ -269,6 +348,7 @@ files:
269
348
  - spec/inputs/time_input_spec.rb
270
349
  - spec/inputs/time_zone_input_spec.rb
271
350
  - spec/inputs/url_input_spec.rb
351
+ - spec/inputs/with_options_spec.rb
272
352
  - spec/spec.opts
273
353
  - spec/spec_helper.rb
274
354
  - spec/support/custom_macros.rb
@@ -310,10 +390,17 @@ signing_key:
310
390
  specification_version: 3
311
391
  summary: A Rails form builder plugin/gem with semantically rich and accessible markup
312
392
  test_files:
393
+ - spec/actions/button_action_spec.rb
394
+ - spec/actions/generic_action_spec.rb
395
+ - spec/actions/input_action_spec.rb
396
+ - spec/actions/link_action_spec.rb
313
397
  - spec/builder/custom_builder_spec.rb
314
398
  - spec/builder/error_proc_spec.rb
315
- - spec/builder/errors_spec.rb
316
399
  - spec/builder/semantic_fields_for_spec.rb
400
+ - spec/generators/formtastic/form/form_generator_spec.rb
401
+ - spec/generators/formtastic/install/install_generator_spec.rb
402
+ - spec/helpers/action_helper_spec.rb
403
+ - spec/helpers/actions_helper_spec.rb
317
404
  - spec/helpers/buttons_helper_spec.rb
318
405
  - spec/helpers/commit_button_helper_spec.rb
319
406
  - spec/helpers/form_helper_spec.rb
@@ -334,7 +421,6 @@ test_files:
334
421
  - spec/inputs/include_blank_spec.rb
335
422
  - spec/inputs/label_spec.rb
336
423
  - spec/inputs/number_input_spec.rb
337
- - spec/inputs/numeric_input_spec.rb
338
424
  - spec/inputs/password_input_spec.rb
339
425
  - spec/inputs/phone_input_spec.rb
340
426
  - spec/inputs/placeholder_spec.rb
@@ -347,6 +433,7 @@ test_files:
347
433
  - spec/inputs/time_input_spec.rb
348
434
  - spec/inputs/time_zone_input_spec.rb
349
435
  - spec/inputs/url_input_spec.rb
436
+ - spec/inputs/with_options_spec.rb
350
437
  - spec/spec.opts
351
438
  - spec/spec_helper.rb
352
439
  - spec/support/custom_macros.rb
@@ -1,11 +0,0 @@
1
- module Formtastic
2
- # Quick hack/shim for anything expecting the old SemanticFormHelper module.
3
- # TODO remove from 2.0 with a helpful upgrade path/warning.
4
- # @private
5
- module SemanticFormHelper
6
- include Formtastic::Helpers::FormHelper
7
- @@builder = Formtastic::Helpers::FormHelper.builder
8
- @@default_form_class = Formtastic::Helpers::FormHelper.default_form_class
9
- mattr_accessor :builder, :default_form_class
10
- end
11
- end
@@ -1,21 +0,0 @@
1
- module Formtastic
2
- module Inputs
3
- # Alias for NumberInput for backwards compatibility with 1.x.
4
- #
5
- # @example:
6
- # f.input :age, :as => :numeric
7
- #
8
- # @deprecated Use :as => :number instead
9
- #
10
- # @todo Remove on or after 2.1
11
- class NumericInput < NumberInput
12
-
13
- def initialize(builder, template, object, object_name, method, options)
14
- ActiveSupport::Deprecation.warn(':as => :numeric has been deprecated in favor of :as => :number and will be removed on or after version 2.1', caller)
15
- super
16
- end
17
-
18
- end
19
- end
20
- end
21
-
@@ -1,12 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Formtastic
4
- # @private
5
- class Railtie < Rails::Railtie
6
- initializer 'formtastic.initialize' do
7
- ActiveSupport.on_load(:action_view) do
8
- include Formtastic::Helpers::FormHelper
9
- end
10
- end
11
- end
12
- end
@@ -1,11 +0,0 @@
1
- module Formtastic
2
- # Quick hack/shim so that any code expecting the old SemanticFormBuilder class still works.
3
- # TODO remove from 2.0 with a helpful upgrade path/warning.
4
- # @private
5
- class SemanticFormBuilder < Formtastic::FormBuilder
6
- def initialize(*args)
7
- ActiveSupport::Deprecation.warn('Formtastic::SemanticFormBuilder has been deprecated in favor of Formtastic::FormBuilder.', caller)
8
- super
9
- end
10
- end
11
- end
@@ -1,203 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe 'Formtastic::FormBuilder#errors_on' do
5
-
6
- include FormtasticSpecHelper
7
-
8
- before do
9
- @output_buffer = ''
10
- mock_everything
11
- @title_errors = ['must not be blank', 'must be longer than 10 characters', 'must be awesome']
12
- @errors = mock('errors')
13
- @new_post.stub!(:errors).and_return(@errors)
14
- end
15
-
16
- describe 'when there are errors' do
17
- before do
18
- @errors.stub!(:[]).with(:title).and_return(@title_errors)
19
- end
20
-
21
- after do
22
- Formtastic::FormBuilder.default_inline_error_class = 'inline-errors'
23
- Formtastic::FormBuilder.default_error_list_class = 'errors'
24
- end
25
-
26
- it 'should render a paragraph with the errors joined into a sentence when inline_errors config is :sentence' do
27
- Formtastic::FormBuilder.inline_errors = :sentence
28
- concat(semantic_form_for(@new_post) do |builder|
29
- builder.input :title
30
- end)
31
- output_buffer.should have_tag('p.inline-errors', @title_errors.to_sentence)
32
- end
33
-
34
- it 'should render a paragraph with a overridden default class' do
35
- Formtastic::FormBuilder.inline_errors = :sentence
36
- Formtastic::FormBuilder.default_inline_error_class = 'better-errors'
37
- concat(semantic_form_for(@new_post) do |builder|
38
- builder.input(:title)
39
- end)
40
- output_buffer.should have_tag('p.better-errors', @title_errors.to_sentence)
41
- end
42
-
43
- it 'should render a paragraph with the errors joined into a sentence when inline_errors config is :sentence with a customized error class' do
44
- Formtastic::FormBuilder.inline_errors = :sentence
45
- concat(semantic_form_for(@new_post) do |builder|
46
- builder.input(:title, :error_class => 'better-errors')
47
- end)
48
- output_buffer.should have_tag('p.better-errors', @title_errors.to_sentence)
49
- end
50
-
51
- it 'should render an unordered list with the class errors when inline_errors config is :list' do
52
- Formtastic::FormBuilder.inline_errors = :list
53
- concat(semantic_form_for(@new_post) do |builder|
54
- builder.input(:title)
55
- end)
56
- output_buffer.should have_tag('ul.errors')
57
- @title_errors.each do |error|
58
- output_buffer.should have_tag('ul.errors li', error)
59
- end
60
- end
61
-
62
- it 'should render an unordered list with the class overridden default class' do
63
- Formtastic::FormBuilder.inline_errors = :list
64
- Formtastic::FormBuilder.default_error_list_class = "better-errors"
65
- concat(semantic_form_for(@new_post) do |builder|
66
- builder.input :title
67
- end)
68
- output_buffer.should have_tag('ul.better-errors')
69
- @title_errors.each do |error|
70
- output_buffer.should have_tag('ul.better-errors li', error)
71
- end
72
- end
73
-
74
- it 'should render an unordered list with the class errors when inline_errors config is :list with a customized error class' do
75
- Formtastic::FormBuilder.inline_errors = :list
76
- concat(semantic_form_for(@new_post) do |builder|
77
- builder.input :title, :error_class => "better-errors"
78
- end)
79
- output_buffer.should have_tag('ul.better-errors')
80
- @title_errors.each do |error|
81
- output_buffer.should have_tag('ul.better-errors li', error)
82
- end
83
- end
84
-
85
- it 'should render a paragraph with the first error when inline_errors config is :first' do
86
- Formtastic::FormBuilder.inline_errors = :first
87
- concat(semantic_form_for(@new_post) do |builder|
88
- builder.input :title
89
- end)
90
- output_buffer.should have_tag('p.inline-errors', @title_errors.first)
91
-
92
- end
93
-
94
- it 'should render a paragraph with the first error when inline_errors config is :first with a customized error class' do
95
- Formtastic::FormBuilder.inline_errors = :first
96
- concat(semantic_form_for(@new_post) do |builder|
97
- builder.input :title, :error_class => "better-errors"
98
- end)
99
- output_buffer.should have_tag('p.better-errors', @title_errors.first)
100
- end
101
-
102
- it 'should return nil when inline_errors config is :none' do
103
- Formtastic::FormBuilder.inline_errors = :none
104
- concat(semantic_form_for(@new_post) do |builder|
105
- builder.input :title
106
- end)
107
- output_buffer.should_not have_tag('p.inine-errors')
108
- output_buffer.should_not have_tag('ul.errors')
109
- end
110
-
111
- it 'should allow calling deprecated errors_on and inline_errors_for helpers' do
112
- Formtastic::FormBuilder.inline_errors = :sentence
113
- with_deprecation_silenced do
114
- concat(semantic_form_for(@new_post) do |builder|
115
- builder.errors_on :title
116
- builder.inline_errors_for :title
117
- end)
118
- end
119
- end
120
-
121
- end
122
-
123
- describe 'when there are no errors (nil)' do
124
- before do
125
- @errors.stub!(:[]).with(:title).and_return(nil)
126
- end
127
-
128
- it 'should return nil when inline_errors config is :sentence, :list or :none' do
129
- with_deprecation_silenced do
130
- [:sentence, :list, :none].each do |config|
131
- with_config :inline_errors, config do
132
- semantic_form_for(@new_post) do |builder|
133
- builder.errors_on(:title).should be_nil
134
- end
135
- end
136
- end
137
- end
138
- end
139
- end
140
-
141
- describe 'when there are no errors (empty array)' do
142
- before do
143
- @errors.stub!(:[]).with(:title).and_return([])
144
- end
145
-
146
- it 'should return nil when inline_errors config is :sentence, :list or :none' do
147
- with_deprecation_silenced do
148
- [:sentence, :list, :none].each do |config|
149
- Formtastic::FormBuilder.inline_errors = config
150
- semantic_form_for(@new_post) do |builder|
151
- builder.errors_on(:title).should be_nil
152
- end
153
- end
154
- end
155
- end
156
- end
157
-
158
- describe 'when file type columns have errors' do
159
- it "should list errors added on metadata fields" do
160
- @errors.stub!(:[]).with(:document_file_name).and_return(['must be provided'])
161
- @errors.stub!(:[]).with(:document_file_size).and_return(['must be less than 4mb'])
162
- @errors.stub!(:[]).with(:document_content_type).and_return(['must be an image'])
163
- @errors.stub!(:[]).with(:document).and_return(nil)
164
-
165
- with_config :inline_errors, :sentence do
166
- concat(semantic_form_for(@new_post) do |builder|
167
- concat(builder.input(:document))
168
- end)
169
- end
170
- output_buffer.should have_tag("li.error")
171
- output_buffer.should have_tag('p.inline-errors', (['must be an image','must be provided', 'must be less than 4mb']).to_sentence)
172
- end
173
- end
174
-
175
- describe 'when there are errors on the association and column' do
176
-
177
- it "should list all unique errors" do
178
- ::Post.stub!(:reflections).and_return({:author => mock('reflection', :options => {}, :macro => :belongs_to)})
179
-
180
- @errors.stub!(:[]).with(:author).and_return(['must not be blank'])
181
- @errors.stub!(:[]).with(:author_id).and_return(['is already taken', 'must not be blank']) # note the duplicate of association
182
-
183
- with_config :inline_errors, :list do
184
- concat(semantic_form_for(@new_post) do |builder|
185
- concat(builder.input(:author))
186
- end)
187
- end
188
- output_buffer.should have_tag("ul.errors li", /must not be blank/, :count => 1)
189
- output_buffer.should have_tag("ul.errors li", /is already taken/, :count => 1)
190
- end
191
-
192
- end
193
-
194
- describe "when there are errors on a has_many association" do
195
- it "should include the association ids error messages" do
196
- semantic_form_for(@new_post) do |builder|
197
- builder.send(:error_keys, :sub_posts, {}).should include(:sub_post_ids)
198
- end
199
- end
200
- end
201
-
202
- end
203
-