formtastic 3.1.6 → 4.0.0.rc1

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 (114) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +1 -0
  3. data/.gitignore +3 -2
  4. data/.travis.yml +28 -40
  5. data/CHANGELOG.md +49 -0
  6. data/DEPRECATIONS +1 -1
  7. data/Gemfile.lock +104 -0
  8. data/README.md +628 -629
  9. data/Rakefile +20 -1
  10. data/app/assets/stylesheets/formtastic.css +1 -1
  11. data/bin/appraisal +8 -0
  12. data/formtastic.gemspec +9 -14
  13. data/gemfiles/rails_5.2/Gemfile +5 -0
  14. data/gemfiles/rails_6.0/Gemfile +5 -0
  15. data/gemfiles/rails_edge/Gemfile +13 -0
  16. data/lib/formtastic/actions.rb +6 -3
  17. data/lib/formtastic/deprecation.rb +1 -38
  18. data/lib/formtastic/engine.rb +3 -1
  19. data/lib/formtastic/form_builder.rb +8 -24
  20. data/lib/formtastic/helpers/action_helper.rb +1 -48
  21. data/lib/formtastic/helpers/errors_helper.rb +2 -2
  22. data/lib/formtastic/helpers/fieldset_wrapper.rb +7 -3
  23. data/lib/formtastic/helpers/input_helper.rb +18 -76
  24. data/lib/formtastic/helpers/inputs_helper.rb +12 -3
  25. data/lib/formtastic/i18n.rb +1 -1
  26. data/lib/formtastic/inputs/base/collections.rb +1 -5
  27. data/lib/formtastic/inputs/base/errors.rb +4 -4
  28. data/lib/formtastic/inputs/base/hints.rb +1 -1
  29. data/lib/formtastic/inputs/base/timeish.rb +5 -1
  30. data/lib/formtastic/inputs/base/validations.rb +19 -9
  31. data/lib/formtastic/inputs/check_boxes_input.rb +3 -3
  32. data/lib/formtastic/inputs/color_input.rb +0 -1
  33. data/lib/formtastic/inputs/select_input.rb +1 -1
  34. data/lib/formtastic/inputs.rb +32 -29
  35. data/lib/formtastic/localizer.rb +4 -3
  36. data/lib/formtastic/version.rb +1 -1
  37. data/lib/formtastic.rb +5 -11
  38. data/lib/generators/templates/formtastic.rb +4 -6
  39. data/script/integration-template.rb +71 -0
  40. data/script/integration.sh +19 -0
  41. data/spec/action_class_finder_spec.rb +1 -1
  42. data/spec/actions/button_action_spec.rb +8 -8
  43. data/spec/actions/generic_action_spec.rb +60 -60
  44. data/spec/actions/input_action_spec.rb +7 -7
  45. data/spec/actions/link_action_spec.rb +10 -10
  46. data/spec/builder/custom_builder_spec.rb +36 -20
  47. data/spec/builder/error_proc_spec.rb +4 -4
  48. data/spec/builder/semantic_fields_for_spec.rb +27 -27
  49. data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
  50. data/spec/generators/formtastic/input/input_generator_spec.rb +31 -31
  51. data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
  52. data/spec/helpers/action_helper_spec.rb +328 -10
  53. data/spec/helpers/actions_helper_spec.rb +17 -17
  54. data/spec/helpers/form_helper_spec.rb +33 -33
  55. data/spec/helpers/input_helper_spec.rb +975 -2
  56. data/spec/helpers/inputs_helper_spec.rb +120 -105
  57. data/spec/helpers/reflection_helper_spec.rb +3 -3
  58. data/spec/helpers/semantic_errors_helper_spec.rb +22 -22
  59. data/spec/i18n_spec.rb +26 -26
  60. data/spec/input_class_finder_spec.rb +1 -1
  61. data/spec/inputs/base/collections_spec.rb +6 -6
  62. data/spec/inputs/base/validations_spec.rb +157 -19
  63. data/spec/inputs/boolean_input_spec.rb +55 -55
  64. data/spec/inputs/check_boxes_input_spec.rb +96 -95
  65. data/spec/inputs/color_input_spec.rb +51 -63
  66. data/spec/inputs/country_input_spec.rb +20 -20
  67. data/spec/inputs/custom_input_spec.rb +2 -6
  68. data/spec/inputs/datalist_input_spec.rb +1 -1
  69. data/spec/inputs/date_picker_input_spec.rb +42 -42
  70. data/spec/inputs/date_select_input_spec.rb +51 -37
  71. data/spec/inputs/datetime_picker_input_spec.rb +46 -46
  72. data/spec/inputs/datetime_select_input_spec.rb +53 -37
  73. data/spec/inputs/email_input_spec.rb +5 -5
  74. data/spec/inputs/file_input_spec.rb +6 -6
  75. data/spec/inputs/hidden_input_spec.rb +18 -18
  76. data/spec/inputs/include_blank_spec.rb +8 -8
  77. data/spec/inputs/label_spec.rb +20 -20
  78. data/spec/inputs/number_input_spec.rb +112 -112
  79. data/spec/inputs/password_input_spec.rb +5 -5
  80. data/spec/inputs/phone_input_spec.rb +5 -5
  81. data/spec/inputs/placeholder_spec.rb +5 -5
  82. data/spec/inputs/radio_input_spec.rb +63 -65
  83. data/spec/inputs/range_input_spec.rb +66 -66
  84. data/spec/inputs/readonly_spec.rb +4 -4
  85. data/spec/inputs/search_input_spec.rb +5 -5
  86. data/spec/inputs/select_input_spec.rb +92 -96
  87. data/spec/inputs/string_input_spec.rb +23 -23
  88. data/spec/inputs/text_input_spec.rb +16 -16
  89. data/spec/inputs/time_picker_input_spec.rb +43 -43
  90. data/spec/inputs/time_select_input_spec.rb +67 -54
  91. data/spec/inputs/time_zone_input_spec.rb +19 -19
  92. data/spec/inputs/url_input_spec.rb +5 -5
  93. data/spec/inputs/with_options_spec.rb +7 -7
  94. data/spec/localizer_spec.rb +17 -17
  95. data/spec/namespaced_class_finder_spec.rb +2 -2
  96. data/spec/schema.rb +21 -0
  97. data/spec/spec_helper.rb +163 -223
  98. data/spec/support/custom_macros.rb +72 -75
  99. data/spec/support/shared_examples.rb +0 -1301
  100. data/spec/support/test_environment.rb +23 -9
  101. metadata +36 -122
  102. data/Appraisals +0 -43
  103. data/CHANGELOG +0 -54
  104. data/gemfiles/rails_3.2.gemfile +0 -9
  105. data/gemfiles/rails_4.0.4.gemfile +0 -8
  106. data/gemfiles/rails_4.1.gemfile +0 -8
  107. data/gemfiles/rails_4.2.gemfile +0 -8
  108. data/gemfiles/rails_4.gemfile +0 -8
  109. data/gemfiles/rails_5.0.gemfile +0 -8
  110. data/gemfiles/rails_edge.gemfile +0 -15
  111. data/lib/formtastic/util.rb +0 -57
  112. data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
  113. data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
  114. data/spec/util_spec.rb +0 -66
@@ -1,19 +1,337 @@
1
- # encoding: utf-8
2
1
  require 'spec_helper'
3
2
 
4
- describe 'Formtastic::FormBuilder#action' do
5
- include_context 'Action Helper' # from spec/support/shared_examples.rb
3
+ RSpec.describe 'with action class finder' do
4
+ include_context 'form builder'
5
+
6
+ describe 'arguments and options' do
7
+
8
+ it 'should require the first argument (the action method)' do
9
+ expect {
10
+ concat(semantic_form_for(@new_post) do |builder|
11
+ concat(builder.action()) # no args passed in at all
12
+ end)
13
+ }.to raise_error(ArgumentError)
14
+ end
15
+
16
+ describe ':as option' do
17
+
18
+ describe 'when not provided' do
19
+
20
+ it 'should default to a commit for commit' do
21
+ concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
22
+ concat(builder.action(:submit))
23
+ end)
24
+ expect(output_buffer).to have_tag('form li.action.input_action', :count => 1)
25
+ end
26
+
27
+ it 'should default to a button for reset' do
28
+ concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
29
+ concat(builder.action(:reset))
30
+ end)
31
+ expect(output_buffer).to have_tag('form li.action.input_action', :count => 1)
32
+ end
33
+
34
+ it 'should default to a link for cancel' do
35
+ concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
36
+ concat(builder.action(:cancel))
37
+ end)
38
+ expect(output_buffer).to have_tag('form li.action.link_action', :count => 1)
39
+ end
40
+ end
41
+
42
+ it 'should call the corresponding action class with .to_html' do
43
+ [:input, :button, :link].each do |action_style|
44
+ semantic_form_for(:project, :url => "http://test.host") do |builder|
45
+ action_instance = double('Action instance')
46
+ action_class = "#{action_style.to_s}_action".classify
47
+ action_constant = "Formtastic::Actions::#{action_class}".constantize
48
+
49
+ expect(action_constant).to receive(:new).and_return(action_instance)
50
+ expect(action_instance).to receive(:to_html).and_return("some HTML")
51
+
52
+ concat(builder.action(:submit, :as => action_style))
53
+ end
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ #describe ':label option' do
60
+ #
61
+ # describe 'when provided' do
62
+ # it 'should be passed down to the label tag' do
63
+ # concat(semantic_form_for(@new_post) do |builder|
64
+ # concat(builder.input(:title, :label => "Kustom"))
65
+ # end)
66
+ # output_buffer.should have_tag("form li label", /Kustom/)
67
+ # end
68
+ #
69
+ # it 'should not generate a label if false' do
70
+ # concat(semantic_form_for(@new_post) do |builder|
71
+ # concat(builder.input(:title, :label => false))
72
+ # end)
73
+ # output_buffer.should_not have_tag("form li label")
74
+ # end
75
+ #
76
+ # it 'should be dupped if frozen' do
77
+ # concat(semantic_form_for(@new_post) do |builder|
78
+ # concat(builder.input(:title, :label => "Kustom".freeze))
79
+ # end)
80
+ # output_buffer.should have_tag("form li label", /Kustom/)
81
+ # end
82
+ # end
83
+ #
84
+ # describe 'when not provided' do
85
+ # describe 'when localized label is provided' do
86
+ # describe 'and object is given' do
87
+ # describe 'and label_str_method not :humanize' do
88
+ # it 'should render a label with localized text and not apply the label_str_method' do
89
+ # with_config :label_str_method, :reverse do
90
+ # @localized_label_text = 'Localized title'
91
+ # @new_post.stub(:meta_description)
92
+ # ::I18n.backend.store_translations :en,
93
+ # :formtastic => {
94
+ # :labels => {
95
+ # :meta_description => @localized_label_text
96
+ # }
97
+ # }
98
+ #
99
+ # concat(semantic_form_for(@new_post) do |builder|
100
+ # concat(builder.input(:meta_description))
101
+ # end)
102
+ # output_buffer.should have_tag('form li label', /Localized title/)
103
+ # end
104
+ # end
105
+ # end
106
+ # end
107
+ # end
108
+ #
109
+ # describe 'when localized label is NOT provided' do
110
+ # describe 'and object is not given' do
111
+ # it 'should default the humanized method name, passing it down to the label tag' do
112
+ # ::I18n.backend.store_translations :en, :formtastic => {}
113
+ # with_config :label_str_method, :humanize do
114
+ # concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
115
+ # concat(builder.input(:meta_description))
116
+ # end)
117
+ # output_buffer.should have_tag("form li label", /#{'meta_description'.humanize}/)
118
+ # end
119
+ # end
120
+ # end
121
+ #
122
+ # describe 'and object is given' do
123
+ # it 'should delegate the label logic to class human attribute name and pass it down to the label tag' do
124
+ # @new_post.stub(:meta_description) # a two word method name
125
+ # @new_post.class.should_receive(:human_attribute_name).with('meta_description').and_return('meta_description'.humanize)
126
+ #
127
+ # concat(semantic_form_for(@new_post) do |builder|
128
+ # concat(builder.input(:meta_description))
129
+ # end)
130
+ # output_buffer.should have_tag("form li label", /#{'meta_description'.humanize}/)
131
+ # end
132
+ # end
133
+ #
134
+ # describe 'and object is given with label_str_method set to :capitalize' do
135
+ # it 'should capitalize method name, passing it down to the label tag' do
136
+ # with_config :label_str_method, :capitalize do
137
+ # @new_post.stub(:meta_description)
138
+ #
139
+ # concat(semantic_form_for(@new_post) do |builder|
140
+ # concat(builder.input(:meta_description))
141
+ # end)
142
+ # output_buffer.should have_tag("form li label", /#{'meta_description'.capitalize}/)
143
+ # end
144
+ # end
145
+ # end
146
+ # end
147
+ #
148
+ # describe 'when localized label is provided' do
149
+ # before do
150
+ # @localized_label_text = 'Localized title'
151
+ # @default_localized_label_text = 'Default localized title'
152
+ # ::I18n.backend.store_translations :en,
153
+ # :formtastic => {
154
+ # :labels => {
155
+ # :title => @default_localized_label_text,
156
+ # :published => @default_localized_label_text,
157
+ # :post => {
158
+ # :title => @localized_label_text,
159
+ # :published => @default_localized_label_text
160
+ # }
161
+ # }
162
+ # }
163
+ # end
164
+ #
165
+ # it 'should render a label with localized label (I18n)' do
166
+ # with_config :i18n_lookups_by_default, false do
167
+ # concat(semantic_form_for(@new_post) do |builder|
168
+ # concat(builder.input(:title, :label => true))
169
+ # concat(builder.input(:published, :as => :boolean, :label => true))
170
+ # end)
171
+ # output_buffer.should have_tag('form li label', Regexp.new('^' + @localized_label_text))
172
+ # end
173
+ # end
174
+ #
175
+ # it 'should render a hint paragraph containing an optional localized label (I18n) if first is not set' do
176
+ # with_config :i18n_lookups_by_default, false do
177
+ # ::I18n.backend.store_translations :en,
178
+ # :formtastic => {
179
+ # :labels => {
180
+ # :post => {
181
+ # :title => nil,
182
+ # :published => nil
183
+ # }
184
+ # }
185
+ # }
186
+ # concat(semantic_form_for(@new_post) do |builder|
187
+ # concat(builder.input(:title, :label => true))
188
+ # concat(builder.input(:published, :as => :boolean, :label => true))
189
+ # end)
190
+ # output_buffer.should have_tag('form li label', Regexp.new('^' + @default_localized_label_text))
191
+ # end
192
+ # end
193
+ # end
194
+ # end
195
+ #
196
+ #end
197
+ #
198
+ describe ':wrapper_html option' do
199
+
200
+ describe 'when provided' do
201
+ it 'should be passed down to the li tag' do
202
+ concat(semantic_form_for(@new_post) do |builder|
203
+ concat(builder.action(:submit, :wrapper_html => {:id => :another_id}))
204
+ end)
205
+ expect(output_buffer).to have_tag("form li#another_id")
206
+ end
207
+
208
+ it 'should append given classes to li default classes' do
209
+ concat(semantic_form_for(@new_post) do |builder|
210
+ concat(builder.action(:submit, :wrapper_html => {:class => :another_class}))
211
+ end)
212
+ expect(output_buffer).to have_tag("form li.action")
213
+ expect(output_buffer).to have_tag("form li.input_action")
214
+ expect(output_buffer).to have_tag("form li.another_class")
215
+ end
216
+
217
+ it 'should allow classes to be an array' do
218
+ concat(semantic_form_for(@new_post) do |builder|
219
+ concat(builder.action(:submit, :wrapper_html => {:class => [ :my_class, :another_class ]}))
220
+ end)
221
+ expect(output_buffer).to have_tag("form li.action")
222
+ expect(output_buffer).to have_tag("form li.input_action")
223
+ expect(output_buffer).to have_tag("form li.my_class")
224
+ expect(output_buffer).to have_tag("form li.another_class")
225
+ end
226
+ end
227
+
228
+ describe 'when not provided' do
229
+ it 'should use default id and class' do
230
+ concat(semantic_form_for(@new_post) do |builder|
231
+ concat(builder.action(:submit))
232
+ end)
233
+ expect(output_buffer).to have_tag("form li#post_submit_action")
234
+ expect(output_buffer).to have_tag("form li.action")
235
+ expect(output_buffer).to have_tag("form li.input_action")
236
+ end
237
+ end
238
+
239
+ end
240
+
241
+ end
6
242
 
7
- # TODO: remove this in Formtastic 4.0
8
243
  describe 'instantiating an action class' do
9
- context 'of unknown action' do
10
- it "should try to load class named as the action" do
244
+ context 'when a class does not exist' do
245
+ it "should raise an error" do
11
246
  expect {
12
- semantic_form_for(@new_post) do |builder|
13
- builder.action(:destroy)
14
- end
15
- }.to raise_error(Formtastic::UnknownActionError, 'Unable to find action destroy')
247
+ concat(semantic_form_for(@new_post) do |builder|
248
+ builder.action(:submit, :as => :non_existant)
249
+ end)
250
+ }.to raise_error(Formtastic::UnknownActionError)
16
251
  end
17
252
  end
253
+
254
+ context 'when a customized top-level class does not exist' do
255
+ it 'should instantiate the Formtastic action' do
256
+ action = double('action', :to_html => 'some HTML')
257
+ expect(Formtastic::Actions::ButtonAction).to receive(:new).and_return(action)
258
+ concat(semantic_form_for(@new_post) do |builder|
259
+ builder.action(:commit, :as => :button)
260
+ end)
261
+ end
262
+ end
263
+
264
+ describe 'when a top-level (custom) action class exists' do
265
+ it "should instantiate the top-level action instead of the Formtastic one" do
266
+ class ::ButtonAction < Formtastic::Actions::ButtonAction
267
+ end
268
+
269
+ action = double('action', :to_html => 'some HTML')
270
+ expect(Formtastic::Actions::ButtonAction).not_to receive(:new)
271
+ expect(::ButtonAction).to receive(:new).and_return(action)
272
+
273
+ concat(semantic_form_for(@new_post) do |builder|
274
+ builder.action(:commit, :as => :button)
275
+ end)
276
+ end
277
+ end
278
+
279
+ describe 'support for :as on each action' do
280
+
281
+ it "should raise an error when the action does not support the :as" do
282
+ expect {
283
+ concat(semantic_form_for(@new_post) do |builder|
284
+ concat(builder.action(:submit, :as => :link))
285
+ end)
286
+ }.to raise_error(Formtastic::UnsupportedMethodForAction)
287
+
288
+ expect {
289
+ concat(semantic_form_for(@new_post) do |builder|
290
+ concat(builder.action(:cancel, :as => :input))
291
+ end)
292
+ }.to raise_error(Formtastic::UnsupportedMethodForAction)
293
+
294
+ expect {
295
+ concat(semantic_form_for(@new_post) do |builder|
296
+ concat(builder.action(:cancel, :as => :button))
297
+ end)
298
+ }.to raise_error(Formtastic::UnsupportedMethodForAction)
299
+ end
300
+
301
+ it "should not raise an error when the action does not support the :as" do
302
+ expect {
303
+ concat(semantic_form_for(@new_post) do |builder|
304
+ concat(builder.action(:cancel, :as => :link))
305
+ end)
306
+ }.not_to raise_error
307
+
308
+ expect {
309
+ concat(semantic_form_for(@new_post) do |builder|
310
+ concat(builder.action(:submit, :as => :input))
311
+ end)
312
+ }.not_to raise_error
313
+
314
+ expect {
315
+ concat(semantic_form_for(@new_post) do |builder|
316
+ concat(builder.action(:submit, :as => :button))
317
+ end)
318
+ }.not_to raise_error
319
+
320
+ expect {
321
+ concat(semantic_form_for(@new_post) do |builder|
322
+ concat(builder.action(:reset, :as => :input))
323
+ end)
324
+ }.not_to raise_error
325
+
326
+ expect {
327
+ concat(semantic_form_for(@new_post) do |builder|
328
+ concat(builder.action(:reset, :as => :button))
329
+ end)
330
+ }.not_to raise_error
331
+ end
332
+
333
+ end
334
+
18
335
  end
336
+
19
337
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'Formtastic::FormBuilder#actions' do
4
+ RSpec.describe 'Formtastic::FormBuilder#actions' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
@@ -21,19 +21,19 @@ describe 'Formtastic::FormBuilder#actions' do
21
21
  end
22
22
 
23
23
  it 'should render a fieldset inside the form, with a class of "actions"' do
24
- output_buffer.should have_tag("form fieldset.actions")
24
+ expect(output_buffer).to have_tag("form fieldset.actions")
25
25
  end
26
26
 
27
27
  it 'should render an ol inside the fieldset' do
28
- output_buffer.should have_tag("form fieldset.actions ol")
28
+ expect(output_buffer).to have_tag("form fieldset.actions ol")
29
29
  end
30
30
 
31
31
  it 'should render the contents of the block inside the ol' do
32
- output_buffer.should have_tag("form fieldset.actions ol", /hello/)
32
+ expect(output_buffer).to have_tag("form fieldset.actions ol", :text => /hello/)
33
33
  end
34
34
 
35
35
  it 'should not render a legend inside the fieldset' do
36
- output_buffer.should_not have_tag("form fieldset.actions legend")
36
+ expect(output_buffer).not_to have_tag("form fieldset.actions legend")
37
37
  end
38
38
  end
39
39
 
@@ -47,7 +47,7 @@ describe 'Formtastic::FormBuilder#actions' do
47
47
  end)
48
48
  end
49
49
  it 'should render a fieldset inside the form' do
50
- output_buffer.should have_tag("form fieldset.actions legend", /#{@legend_text}/)
50
+ expect(output_buffer).to have_tag("form fieldset.actions legend", :text => /#{@legend_text}/)
51
51
  end
52
52
  end
53
53
 
@@ -62,8 +62,8 @@ describe 'Formtastic::FormBuilder#actions' do
62
62
  end)
63
63
  end
64
64
  it 'should pass the options into the fieldset tag as attributes' do
65
- output_buffer.should have_tag("form fieldset##{@id_option}")
66
- output_buffer.should have_tag("form fieldset.#{@class_option}")
65
+ expect(output_buffer).to have_tag("form fieldset##{@id_option}")
66
+ expect(output_buffer).to have_tag("form fieldset.#{@class_option}")
67
67
  end
68
68
  end
69
69
 
@@ -80,23 +80,23 @@ describe 'Formtastic::FormBuilder#actions' do
80
80
  end
81
81
 
82
82
  it 'should render a form' do
83
- output_buffer.should have_tag('form')
83
+ expect(output_buffer).to have_tag('form')
84
84
  end
85
85
 
86
86
  it 'should render an actions fieldset inside the form' do
87
- output_buffer.should have_tag('form fieldset.actions')
87
+ expect(output_buffer).to have_tag('form fieldset.actions')
88
88
  end
89
89
 
90
90
  it 'should not render a legend in the fieldset' do
91
- output_buffer.should_not have_tag('form fieldset.actions legend')
91
+ expect(output_buffer).not_to have_tag('form fieldset.actions legend')
92
92
  end
93
93
 
94
94
  it 'should render an ol in the fieldset' do
95
- output_buffer.should have_tag('form fieldset.actions ol')
95
+ expect(output_buffer).to have_tag('form fieldset.actions ol')
96
96
  end
97
97
 
98
98
  it 'should render a list item in the ol for each default action' do
99
- output_buffer.should have_tag('form fieldset.actions ol li.action.input_action', :count => 1)
99
+ expect(output_buffer).to have_tag('form fieldset.actions ol li.action.input_action', :count => 1)
100
100
  end
101
101
 
102
102
  end
@@ -110,7 +110,7 @@ describe 'Formtastic::FormBuilder#actions' do
110
110
  end
111
111
 
112
112
  it 'should render a form with a fieldset containing a list item for each button arg' do
113
- output_buffer.should have_tag('form > fieldset.actions > ol > li.action', :count => 3)
113
+ expect(output_buffer).to have_tag('form > fieldset.actions > ol > li.action', :count => 3)
114
114
  end
115
115
 
116
116
  end
@@ -124,15 +124,15 @@ describe 'Formtastic::FormBuilder#actions' do
124
124
  end
125
125
 
126
126
  it 'should render a form with a fieldset containing a list item for each button arg' do
127
- output_buffer.should have_tag('form > fieldset.actions > ol > li.action', :count => 3)
127
+ expect(output_buffer).to have_tag('form > fieldset.actions > ol > li.action', :count => 3)
128
128
  end
129
129
 
130
130
  it 'should pass the options down to the fieldset' do
131
- output_buffer.should have_tag('form > fieldset#my-id.actions')
131
+ expect(output_buffer).to have_tag('form > fieldset#my-id.actions')
132
132
  end
133
133
 
134
134
  it 'should use the special :name option as a text for the legend tag' do
135
- output_buffer.should have_tag('form > fieldset#my-id.actions > legend', /Now click a button/)
135
+ expect(output_buffer).to have_tag('form > fieldset#my-id.actions > legend', :text => /Now click a button/)
136
136
  end
137
137
 
138
138
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'FormHelper' do
4
+ RSpec.describe 'FormHelper' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
@@ -14,21 +14,21 @@ describe 'FormHelper' do
14
14
 
15
15
  it 'yields an instance of Formtastic::FormBuilder' do
16
16
  semantic_form_for(@new_post, :url => '/hello') do |builder|
17
- builder.class.should == Formtastic::FormBuilder
17
+ expect(builder.class).to eq(Formtastic::FormBuilder)
18
18
  end
19
19
  end
20
20
 
21
21
  it 'adds a class of "formtastic" to the generated form' do
22
22
  concat(semantic_form_for(@new_post, :url => '/hello') do |builder|
23
23
  end)
24
- output_buffer.should have_tag("form.formtastic")
24
+ expect(output_buffer).to have_tag("form.formtastic")
25
25
  end
26
26
 
27
27
  it 'does not add "novalidate" attribute to the generated form when configured to do so' do
28
28
  with_config :perform_browser_validations, true do
29
29
  concat(semantic_form_for(@new_post, :url => '/hello') do |builder|
30
30
  end)
31
- output_buffer.should_not have_tag("form[@novalidate]")
31
+ expect(output_buffer).not_to have_tag("form[@novalidate]")
32
32
  end
33
33
  end
34
34
 
@@ -36,7 +36,7 @@ describe 'FormHelper' do
36
36
  with_config :perform_browser_validations, false do
37
37
  concat(semantic_form_for(@new_post, :url => '/hello') do |builder|
38
38
  end)
39
- output_buffer.should have_tag("form[@novalidate]")
39
+ expect(output_buffer).to have_tag("form[@novalidate]")
40
40
  end
41
41
  end
42
42
 
@@ -44,7 +44,7 @@ describe 'FormHelper' do
44
44
  with_config :perform_browser_validations, false do
45
45
  concat(semantic_form_for(@new_post, :url => '/hello', :html => { :novalidate => true }) do |builder|
46
46
  end)
47
- output_buffer.should have_tag("form[@novalidate]")
47
+ expect(output_buffer).to have_tag("form[@novalidate]")
48
48
  end
49
49
  end
50
50
 
@@ -52,7 +52,7 @@ describe 'FormHelper' do
52
52
  with_config :perform_browser_validations, true do
53
53
  concat(semantic_form_for(@new_post, :url => '/hello', :html => { :novalidate => false }) do |builder|
54
54
  end)
55
- output_buffer.should_not have_tag("form[@novalidate]")
55
+ expect(output_buffer).not_to have_tag("form[@novalidate]")
56
56
  end
57
57
  end
58
58
 
@@ -60,103 +60,103 @@ describe 'FormHelper' do
60
60
  Formtastic::Helpers::FormHelper.default_form_class = 'xyz'
61
61
  concat(semantic_form_for(::Post.new, :as => :post, :url => '/hello') do |builder|
62
62
  end)
63
- output_buffer.should have_tag("form.xyz")
63
+ expect(output_buffer).to have_tag("form.xyz")
64
64
  end
65
65
 
66
66
  it 'omits the leading spaces from the classes in the generated form when the default class is nil' do
67
67
  Formtastic::Helpers::FormHelper.default_form_class = nil
68
68
  concat(semantic_form_for(::Post.new, :as => :post, :url => '/hello') do |builder|
69
69
  end)
70
- output_buffer.should have_tag("form[class='post']")
70
+ expect(output_buffer).to have_tag("form[class='post']")
71
71
  end
72
72
 
73
73
  it 'adds class matching the object name to the generated form when a symbol is provided' do
74
74
  concat(semantic_form_for(@new_post, :url => '/hello') do |builder|
75
75
  end)
76
- output_buffer.should have_tag("form.post")
76
+ expect(output_buffer).to have_tag("form.post")
77
77
 
78
78
  concat(semantic_form_for(:project, :url => '/hello') do |builder|
79
79
  end)
80
- output_buffer.should have_tag("form.project")
80
+ expect(output_buffer).to have_tag("form.project")
81
81
  end
82
82
 
83
83
  it 'adds class matching the :as option when provided' do
84
84
  concat(semantic_form_for(@new_post, :as => :message, :url => '/hello') do |builder|
85
85
  end)
86
- output_buffer.should have_tag("form.message")
86
+ expect(output_buffer).to have_tag("form.message")
87
87
 
88
88
  concat(semantic_form_for([:admins, @new_post], :as => :message, :url => '/hello') do |builder|
89
89
  end)
90
- output_buffer.should have_tag("form.message")
90
+ expect(output_buffer).to have_tag("form.message")
91
91
  end
92
92
 
93
93
  it 'adds class matching the object\'s class to the generated form when an object is provided' do
94
94
  concat(semantic_form_for(@new_post) do |builder|
95
95
  end)
96
- output_buffer.should have_tag("form.post")
96
+ expect(output_buffer).to have_tag("form.post")
97
97
  end
98
98
 
99
99
  it 'adds a namespaced class to the generated form' do
100
100
  concat(semantic_form_for(::Namespaced::Post.new, :url => '/hello') do |builder|
101
101
  end)
102
- output_buffer.should have_tag("form.namespaced_post")
102
+ expect(output_buffer).to have_tag("form.namespaced_post")
103
103
  end
104
104
 
105
105
  it 'adds a customized class to the generated form' do
106
106
  Formtastic::Helpers::FormHelper.default_form_model_class_proc = lambda { |model_class_name| "#{model_class_name}_form" }
107
107
  concat(semantic_form_for(@new_post, :url => '/hello') do |builder|
108
108
  end)
109
- output_buffer.should have_tag("form.post_form")
109
+ expect(output_buffer).to have_tag("form.post_form")
110
110
 
111
111
  concat(semantic_form_for(:project, :url => '/hello') do |builder|
112
112
  end)
113
- output_buffer.should have_tag("form.project_form")
113
+ expect(output_buffer).to have_tag("form.project_form")
114
114
  end
115
115
 
116
116
  describe 'allows :html options' do
117
- before(:each) do
117
+ before(:example) do
118
118
  concat(semantic_form_for(@new_post, :url => '/hello', :html => { :id => "something-special", :class => "something-extra", :multipart => true }) do |builder|
119
119
  end)
120
120
  end
121
121
 
122
122
  it 'to add a id of "something-special" to generated form' do
123
- output_buffer.should have_tag("form#something-special")
123
+ expect(output_buffer).to have_tag("form#something-special")
124
124
  end
125
125
 
126
126
  it 'to add a class of "something-extra" to generated form' do
127
- output_buffer.should have_tag("form.something-extra")
127
+ expect(output_buffer).to have_tag("form.something-extra")
128
128
  end
129
129
 
130
130
  it 'to add enctype="multipart/form-data"' do
131
- output_buffer.should have_tag('form[@enctype="multipart/form-data"]')
131
+ expect(output_buffer).to have_tag('form[@enctype="multipart/form-data"]')
132
132
  end
133
133
  end
134
134
 
135
135
  it 'can be called with a resource-oriented style' do
136
136
  semantic_form_for(@new_post) do |builder|
137
- builder.object.class.should == ::Post
138
- builder.object_name.should == "post"
137
+ expect(builder.object.class).to eq(::Post)
138
+ expect(builder.object_name).to eq("post")
139
139
  end
140
140
  end
141
141
 
142
142
  it 'can be called with a generic style and instance variable' do
143
143
  semantic_form_for(@new_post, :as => :post, :url => new_post_path) do |builder|
144
- builder.object.class.should == ::Post
145
- builder.object_name.to_s.should == "post" # TODO: is this forced .to_s a bad assumption somewhere?
144
+ expect(builder.object.class).to eq(::Post)
145
+ expect(builder.object_name.to_s).to eq("post") # TODO: is this forced .to_s a bad assumption somewhere?
146
146
  end
147
147
  end
148
148
 
149
149
  it 'can be called with a generic style and inline object' do
150
150
  semantic_form_for(@new_post, :url => new_post_path) do |builder|
151
- builder.object.class.should == ::Post
152
- builder.object_name.to_s.should == "post" # TODO: is this forced .to_s a bad assumption somewhere?
151
+ expect(builder.object.class).to eq(::Post)
152
+ expect(builder.object_name.to_s).to eq("post") # TODO: is this forced .to_s a bad assumption somewhere?
153
153
  end
154
154
  end
155
155
 
156
156
  describe 'ActionView::Base.field_error_proc' do
157
157
  it 'is set to no-op wrapper by default' do
158
158
  semantic_form_for(@new_post, :url => '/hello') do |builder|
159
- ::ActionView::Base.field_error_proc.call("html", nil).should == "html"
159
+ expect(::ActionView::Base.field_error_proc.call("html", nil)).to eq("html")
160
160
  end
161
161
  end
162
162
 
@@ -164,15 +164,15 @@ describe 'FormHelper' do
164
164
  field_error_proc = double()
165
165
  Formtastic::Helpers::FormHelper.formtastic_field_error_proc = field_error_proc
166
166
  semantic_form_for(@new_post, :url => '/hello') do |builder|
167
- ::ActionView::Base.field_error_proc.should == field_error_proc
167
+ expect(::ActionView::Base.field_error_proc).to eq(field_error_proc)
168
168
  end
169
169
  end
170
170
 
171
171
  it 'is restored to its original value after the form is rendered' do
172
- lambda do
172
+ expect do
173
173
  Formtastic::Helpers::FormHelper.formtastic_field_error_proc = proc {""}
174
174
  semantic_form_for(@new_post, :url => '/hello') { |builder| }
175
- end.should_not change(::ActionView::Base, :field_error_proc)
175
+ end.not_to change(::ActionView::Base, :field_error_proc)
176
176
  end
177
177
  end
178
178
 
@@ -181,7 +181,7 @@ describe 'FormHelper' do
181
181
  class MyAwesomeCustomBuilder < Formtastic::FormBuilder
182
182
  end
183
183
  semantic_form_for(@new_post, :url => '/hello', :builder => MyAwesomeCustomBuilder) do |builder|
184
- builder.class.should == MyAwesomeCustomBuilder
184
+ expect(builder.class).to eq(MyAwesomeCustomBuilder)
185
185
  end
186
186
  end
187
187
  end
@@ -209,7 +209,7 @@ describe 'FormHelper' do
209
209
  describe '#semantic_fields_for' do
210
210
  it 'yields an instance of Formtastic::FormBuilder' do
211
211
  semantic_fields_for(@new_post) do |builder|
212
- builder.class.should.kind_of?(Formtastic::FormBuilder)
212
+ expect(builder.class).to be(Formtastic::FormBuilder)
213
213
  end
214
214
  end
215
215
  end