formtastic 2.1.0 → 4.0.0
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.
- checksums.yaml +7 -0
- data/.gitattributes +1 -0
- data/.github/workflows/test.yml +61 -0
- data/.gitignore +4 -2
- data/CHANGELOG.md +52 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +105 -0
- data/MIT-LICENSE +1 -1
- data/{README.textile → README.md} +204 -219
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +27 -29
- data/app/assets/stylesheets/formtastic.css +3 -2
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +11 -14
- data/gemfiles/rails_5.2/Gemfile +5 -0
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_6.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic/action_class_finder.rb +18 -0
- data/lib/formtastic/actions/button_action.rb +55 -60
- data/lib/formtastic/actions/input_action.rb +59 -57
- data/lib/formtastic/actions/link_action.rb +68 -67
- data/lib/formtastic/actions.rb +6 -3
- data/lib/formtastic/deprecation.rb +5 -0
- data/lib/formtastic/engine.rb +3 -1
- data/lib/formtastic/form_builder.rb +35 -16
- data/lib/formtastic/helpers/action_helper.rb +34 -28
- data/lib/formtastic/helpers/enum.rb +13 -0
- data/lib/formtastic/helpers/errors_helper.rb +2 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -12
- data/lib/formtastic/helpers/form_helper.rb +19 -16
- data/lib/formtastic/helpers/input_helper.rb +69 -97
- data/lib/formtastic/helpers/inputs_helper.rb +35 -25
- data/lib/formtastic/helpers/reflection.rb +4 -4
- data/lib/formtastic/helpers.rb +1 -2
- data/lib/formtastic/html_attributes.rb +12 -1
- data/lib/formtastic/i18n.rb +1 -1
- data/lib/formtastic/input_class_finder.rb +18 -0
- data/lib/formtastic/inputs/base/choices.rb +2 -2
- data/lib/formtastic/inputs/base/collections.rb +46 -14
- data/lib/formtastic/inputs/base/database.rb +7 -2
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
- data/lib/formtastic/inputs/base/errors.rb +7 -7
- data/lib/formtastic/inputs/base/hints.rb +2 -2
- data/lib/formtastic/inputs/base/html.rb +10 -9
- data/lib/formtastic/inputs/base/labelling.rb +5 -8
- data/lib/formtastic/inputs/base/naming.rb +4 -4
- data/lib/formtastic/inputs/base/numeric.rb +1 -1
- data/lib/formtastic/inputs/base/options.rb +3 -4
- data/lib/formtastic/inputs/base/stringish.rb +10 -2
- data/lib/formtastic/inputs/base/timeish.rb +34 -22
- data/lib/formtastic/inputs/base/validations.rb +41 -13
- data/lib/formtastic/inputs/base/wrapping.rb +29 -26
- data/lib/formtastic/inputs/base.rb +22 -15
- data/lib/formtastic/inputs/boolean_input.rb +26 -12
- data/lib/formtastic/inputs/check_boxes_input.rb +39 -31
- data/lib/formtastic/inputs/color_input.rb +41 -0
- data/lib/formtastic/inputs/country_input.rb +24 -5
- data/lib/formtastic/inputs/datalist_input.rb +41 -0
- data/lib/formtastic/inputs/date_picker_input.rb +93 -0
- data/lib/formtastic/inputs/{date_input.rb → date_select_input.rb} +1 -1
- data/lib/formtastic/inputs/datetime_picker_input.rb +103 -0
- data/lib/formtastic/inputs/{datetime_input.rb → datetime_select_input.rb} +1 -1
- data/lib/formtastic/inputs/file_input.rb +2 -2
- data/lib/formtastic/inputs/hidden_input.rb +2 -6
- data/lib/formtastic/inputs/radio_input.rb +28 -22
- data/lib/formtastic/inputs/select_input.rb +36 -39
- data/lib/formtastic/inputs/time_picker_input.rb +99 -0
- data/lib/formtastic/inputs/{time_input.rb → time_select_input.rb} +6 -2
- data/lib/formtastic/inputs/time_zone_input.rb +16 -6
- data/lib/formtastic/inputs.rb +32 -21
- data/lib/formtastic/localized_string.rb +1 -1
- data/lib/formtastic/localizer.rb +24 -24
- data/lib/formtastic/namespaced_class_finder.rb +99 -0
- data/lib/formtastic/version.rb +1 -1
- data/lib/formtastic.rb +20 -10
- data/lib/generators/formtastic/form/form_generator.rb +10 -4
- data/lib/generators/formtastic/input/input_generator.rb +46 -0
- data/lib/generators/formtastic/install/install_generator.rb +5 -19
- data/lib/generators/templates/_form.html.slim +2 -2
- data/lib/generators/templates/formtastic.rb +46 -25
- data/lib/generators/templates/input.rb +19 -0
- data/sample/basic_inputs.html +23 -3
- data/script/integration-template.rb +74 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +12 -0
- data/spec/actions/button_action_spec.rb +8 -8
- data/spec/actions/generic_action_spec.rb +92 -56
- data/spec/actions/input_action_spec.rb +7 -7
- data/spec/actions/link_action_spec.rb +10 -10
- data/spec/builder/custom_builder_spec.rb +36 -20
- data/spec/builder/error_proc_spec.rb +4 -4
- data/spec/builder/semantic_fields_for_spec.rb +28 -29
- data/spec/fast_spec_helper.rb +12 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +45 -32
- data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
- data/spec/helpers/action_helper_spec.rb +75 -103
- data/spec/helpers/actions_helper_spec.rb +17 -17
- data/spec/helpers/form_helper_spec.rb +84 -33
- data/spec/helpers/input_helper_spec.rb +333 -285
- data/spec/helpers/inputs_helper_spec.rb +167 -121
- data/spec/helpers/reflection_helper_spec.rb +3 -3
- data/spec/helpers/semantic_errors_helper_spec.rb +23 -23
- data/spec/i18n_spec.rb +26 -26
- data/spec/input_class_finder_spec.rb +10 -0
- data/spec/inputs/base/collections_spec.rb +76 -0
- data/spec/inputs/base/validations_spec.rb +480 -0
- data/spec/inputs/boolean_input_spec.rb +100 -65
- data/spec/inputs/check_boxes_input_spec.rb +200 -101
- data/spec/inputs/color_input_spec.rb +85 -0
- data/spec/inputs/country_input_spec.rb +20 -20
- data/spec/inputs/custom_input_spec.rb +3 -4
- data/spec/inputs/datalist_input_spec.rb +61 -0
- data/spec/inputs/date_picker_input_spec.rb +449 -0
- data/spec/inputs/date_select_input_spec.rb +249 -0
- data/spec/inputs/datetime_picker_input_spec.rb +490 -0
- data/spec/inputs/datetime_select_input_spec.rb +209 -0
- data/spec/inputs/email_input_spec.rb +5 -5
- data/spec/inputs/file_input_spec.rb +6 -6
- data/spec/inputs/hidden_input_spec.rb +22 -35
- data/spec/inputs/include_blank_spec.rb +11 -11
- data/spec/inputs/label_spec.rb +62 -25
- data/spec/inputs/number_input_spec.rb +112 -112
- data/spec/inputs/password_input_spec.rb +5 -5
- data/spec/inputs/phone_input_spec.rb +5 -5
- data/spec/inputs/placeholder_spec.rb +6 -6
- data/spec/inputs/radio_input_spec.rb +99 -55
- data/spec/inputs/range_input_spec.rb +66 -66
- data/spec/inputs/readonly_spec.rb +50 -0
- data/spec/inputs/search_input_spec.rb +5 -5
- data/spec/inputs/select_input_spec.rb +170 -170
- data/spec/inputs/string_input_spec.rb +68 -16
- data/spec/inputs/text_input_spec.rb +16 -16
- data/spec/inputs/time_picker_input_spec.rb +455 -0
- data/spec/inputs/time_select_input_spec.rb +261 -0
- data/spec/inputs/time_zone_input_spec.rb +54 -28
- data/spec/inputs/url_input_spec.rb +5 -5
- data/spec/inputs/with_options_spec.rb +7 -7
- data/spec/localizer_spec.rb +39 -17
- data/spec/namespaced_class_finder_spec.rb +79 -0
- data/spec/schema.rb +21 -0
- data/spec/spec_helper.rb +254 -221
- data/spec/support/custom_macros.rb +128 -95
- data/spec/support/shared_examples.rb +12 -0
- data/spec/support/specialized_class_finder_shared_example.rb +27 -0
- data/spec/support/test_environment.rb +26 -10
- metadata +177 -238
- data/.travis.yml +0 -8
- data/Appraisals +0 -11
- data/CHANGELOG +0 -371
- data/gemfiles/rails-3.0.gemfile +0 -7
- data/gemfiles/rails-3.1.gemfile +0 -7
- data/gemfiles/rails-3.2.gemfile +0 -7
- data/lib/formtastic/helpers/buttons_helper.rb +0 -310
- data/lib/formtastic/inputs/base/grouped_collections.rb +0 -77
- data/lib/formtastic/util.rb +0 -25
- data/lib/tasks/verify_rcov.rb +0 -44
- data/spec/helpers/buttons_helper_spec.rb +0 -166
- data/spec/helpers/commit_button_helper_spec.rb +0 -530
- data/spec/inputs/date_input_spec.rb +0 -227
- data/spec/inputs/datetime_input_spec.rb +0 -185
- data/spec/inputs/time_input_spec.rb +0 -267
- data/spec/support/deferred_garbage_collection.rb +0 -21
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
|
|
4
|
-
describe 'InputAction::Base' do
|
|
4
|
+
RSpec.describe 'InputAction::Base' do
|
|
5
5
|
|
|
6
6
|
# Most basic Action class to test Base
|
|
7
7
|
class ::GenericAction
|
|
@@ -36,15 +36,15 @@ describe 'InputAction::Base' do
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
it 'should add the #foo id to the li' do
|
|
39
|
-
output_buffer.
|
|
39
|
+
expect(output_buffer).to have_tag('li#post_submit_action')
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
it 'should add the .action and .generic_action classes to the li' do
|
|
43
|
-
output_buffer.
|
|
43
|
+
expect(output_buffer).to have_tag('li.action.generic_action')
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it 'should pass :wrapper_html HTML attributes to the wrapper' do
|
|
47
|
-
output_buffer.
|
|
47
|
+
expect(output_buffer).to have_tag('li.action.generic_action[@foo="bah"]')
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
context "when a custom :id is provided" do
|
|
@@ -58,7 +58,7 @@ describe 'InputAction::Base' do
|
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
it "should use the custom id" do
|
|
61
|
-
output_buffer.
|
|
61
|
+
expect(output_buffer).to have_tag('li#foo_bah_bing')
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
end
|
|
@@ -74,7 +74,7 @@ describe 'InputAction::Base' do
|
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
it "should add the custom class strng to the existing classes" do
|
|
77
|
-
output_buffer.
|
|
77
|
+
expect(output_buffer).to have_tag('li.action.generic_action.foo_bah_bing')
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
end
|
|
@@ -90,7 +90,7 @@ describe 'InputAction::Base' do
|
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
it "should add the custom class strng to the existing classes" do
|
|
93
|
-
output_buffer.
|
|
93
|
+
expect(output_buffer).to have_tag('li.action.generic_action.foo_bah_bing.zing_boo')
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
end
|
|
@@ -108,7 +108,7 @@ describe 'InputAction::Base' do
|
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
it 'should pass :button_html HTML attributes to the button' do
|
|
111
|
-
output_buffer.
|
|
111
|
+
expect(output_buffer).to have_tag('li.action.generic_action input[@foo="bah"]')
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
it 'should respect a default_commit_button_accesskey configuration with nil' do
|
|
@@ -116,7 +116,7 @@ describe 'InputAction::Base' do
|
|
|
116
116
|
concat(semantic_form_for(@new_post) do |builder|
|
|
117
117
|
concat(builder.action(:submit, :as => :generic))
|
|
118
118
|
end)
|
|
119
|
-
output_buffer.
|
|
119
|
+
expect(output_buffer).not_to have_tag('li.action input[@accesskey]')
|
|
120
120
|
end
|
|
121
121
|
end
|
|
122
122
|
|
|
@@ -125,7 +125,7 @@ describe 'InputAction::Base' do
|
|
|
125
125
|
concat(semantic_form_for(@new_post) do |builder|
|
|
126
126
|
concat(builder.action(:submit, :as => :generic))
|
|
127
127
|
end)
|
|
128
|
-
output_buffer.
|
|
128
|
+
expect(output_buffer).to have_tag('li.action input[@accesskey="s"]')
|
|
129
129
|
end
|
|
130
130
|
end
|
|
131
131
|
|
|
@@ -134,8 +134,8 @@ describe 'InputAction::Base' do
|
|
|
134
134
|
concat(semantic_form_for(@new_post) do |builder|
|
|
135
135
|
concat(builder.action(:submit, :as => :generic, :accesskey => 'o'))
|
|
136
136
|
end)
|
|
137
|
-
output_buffer.
|
|
138
|
-
output_buffer.
|
|
137
|
+
expect(output_buffer).not_to have_tag('li.action input[@accesskey="s"]')
|
|
138
|
+
expect(output_buffer).to have_tag('li.action input[@accesskey="o"]')
|
|
139
139
|
end
|
|
140
140
|
end
|
|
141
141
|
|
|
@@ -152,9 +152,9 @@ describe 'InputAction::Base' do
|
|
|
152
152
|
concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
|
|
153
153
|
concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
|
|
154
154
|
end)
|
|
155
|
-
output_buffer.
|
|
156
|
-
output_buffer.
|
|
157
|
-
output_buffer.
|
|
155
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Click!"]')
|
|
156
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Reset!"]')
|
|
157
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel!"]')
|
|
158
158
|
end
|
|
159
159
|
end
|
|
160
160
|
|
|
@@ -164,7 +164,14 @@ describe 'InputAction::Base' do
|
|
|
164
164
|
::I18n.backend.store_translations :en, :formtastic => {
|
|
165
165
|
:submit => 'Submit %{model}',
|
|
166
166
|
:reset => 'Reset %{model}',
|
|
167
|
-
:cancel => 'Cancel %{model}'
|
|
167
|
+
:cancel => 'Cancel %{model}',
|
|
168
|
+
:actions => {
|
|
169
|
+
:message => {
|
|
170
|
+
:submit => 'Submit message',
|
|
171
|
+
:reset => 'Reset message',
|
|
172
|
+
:cancel => 'Cancel message'
|
|
173
|
+
}
|
|
174
|
+
}
|
|
168
175
|
}
|
|
169
176
|
end
|
|
170
177
|
|
|
@@ -178,9 +185,20 @@ describe 'InputAction::Base' do
|
|
|
178
185
|
concat(builder.action(:reset, :as => :generic))
|
|
179
186
|
concat(builder.action(:cancel, :as => :generic))
|
|
180
187
|
end)
|
|
181
|
-
output_buffer.
|
|
182
|
-
output_buffer.
|
|
183
|
-
output_buffer.
|
|
188
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Submit Post"]')
|
|
189
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel Post"]')
|
|
190
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Reset Post"]')
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
it 'should render an input with custom resource name localized label' do
|
|
194
|
+
concat(semantic_form_for(:post, :as => :message, :url => 'http://example.com') do |builder|
|
|
195
|
+
concat(builder.action(:submit, :as => :generic))
|
|
196
|
+
concat(builder.action(:reset, :as => :generic))
|
|
197
|
+
concat(builder.action(:cancel, :as => :generic))
|
|
198
|
+
end)
|
|
199
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Submit message"]')
|
|
200
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel message"]')
|
|
201
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Reset message"]')
|
|
184
202
|
end
|
|
185
203
|
end
|
|
186
204
|
|
|
@@ -219,9 +237,9 @@ describe 'InputAction::Base' do
|
|
|
219
237
|
concat(builder.action(:reset, :as => :generic))
|
|
220
238
|
concat(builder.action(:cancel, :as => :generic))
|
|
221
239
|
end)
|
|
222
|
-
output_buffer.
|
|
223
|
-
output_buffer.
|
|
224
|
-
output_buffer.
|
|
240
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Submit Post"]})
|
|
241
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
|
|
242
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
|
|
225
243
|
end
|
|
226
244
|
end
|
|
227
245
|
|
|
@@ -232,9 +250,9 @@ describe 'InputAction::Base' do
|
|
|
232
250
|
concat(builder.action(:reset, :as => :generic))
|
|
233
251
|
concat(builder.action(:cancel, :as => :generic))
|
|
234
252
|
end)
|
|
235
|
-
output_buffer.
|
|
236
|
-
output_buffer.
|
|
237
|
-
output_buffer.
|
|
253
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Submit"]})
|
|
254
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
|
|
255
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
|
|
238
256
|
end
|
|
239
257
|
end
|
|
240
258
|
|
|
@@ -244,7 +262,7 @@ describe 'InputAction::Base' do
|
|
|
244
262
|
|
|
245
263
|
describe 'when used on a new record' do
|
|
246
264
|
before do
|
|
247
|
-
@new_post.
|
|
265
|
+
allow(@new_post).to receive(:new_record?).and_return(true)
|
|
248
266
|
end
|
|
249
267
|
|
|
250
268
|
describe 'when explicit label is provided' do
|
|
@@ -254,9 +272,9 @@ describe 'InputAction::Base' do
|
|
|
254
272
|
concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
|
|
255
273
|
concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
|
|
256
274
|
end)
|
|
257
|
-
output_buffer.
|
|
258
|
-
output_buffer.
|
|
259
|
-
output_buffer.
|
|
275
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Click!"]')
|
|
276
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Reset!"]')
|
|
277
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel!"]')
|
|
260
278
|
end
|
|
261
279
|
end
|
|
262
280
|
|
|
@@ -280,9 +298,9 @@ describe 'InputAction::Base' do
|
|
|
280
298
|
concat(builder.action(:reset, :as => :generic))
|
|
281
299
|
concat(builder.action(:cancel, :as => :generic))
|
|
282
300
|
end)
|
|
283
|
-
output_buffer.
|
|
284
|
-
output_buffer.
|
|
285
|
-
output_buffer.
|
|
301
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Create Post"]')
|
|
302
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Reset Post"]')
|
|
303
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel Post"]')
|
|
286
304
|
end
|
|
287
305
|
end
|
|
288
306
|
|
|
@@ -319,9 +337,9 @@ describe 'InputAction::Base' do
|
|
|
319
337
|
concat(builder.action(:reset, :as => :generic))
|
|
320
338
|
concat(builder.action(:cancel, :as => :generic))
|
|
321
339
|
end)
|
|
322
|
-
output_buffer.
|
|
323
|
-
output_buffer.
|
|
324
|
-
output_buffer.
|
|
340
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Create Post"]})
|
|
341
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
|
|
342
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
|
|
325
343
|
end
|
|
326
344
|
end
|
|
327
345
|
|
|
@@ -332,9 +350,9 @@ describe 'InputAction::Base' do
|
|
|
332
350
|
concat(builder.action(:reset, :as => :generic))
|
|
333
351
|
concat(builder.action(:cancel, :as => :generic))
|
|
334
352
|
end)
|
|
335
|
-
output_buffer.
|
|
336
|
-
output_buffer.
|
|
337
|
-
output_buffer.
|
|
353
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Create"]})
|
|
354
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
|
|
355
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
|
|
338
356
|
end
|
|
339
357
|
end
|
|
340
358
|
|
|
@@ -344,7 +362,7 @@ describe 'InputAction::Base' do
|
|
|
344
362
|
|
|
345
363
|
describe 'when used on an existing record' do
|
|
346
364
|
before do
|
|
347
|
-
@new_post.
|
|
365
|
+
allow(@new_post).to receive(:persisted?).and_return(true)
|
|
348
366
|
end
|
|
349
367
|
|
|
350
368
|
describe 'when explicit label is provided' do
|
|
@@ -354,9 +372,9 @@ describe 'InputAction::Base' do
|
|
|
354
372
|
concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
|
|
355
373
|
concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
|
|
356
374
|
end)
|
|
357
|
-
output_buffer.
|
|
358
|
-
output_buffer.
|
|
359
|
-
output_buffer.
|
|
375
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Click!"]')
|
|
376
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Reset!"]')
|
|
377
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel!"]')
|
|
360
378
|
end
|
|
361
379
|
end
|
|
362
380
|
|
|
@@ -366,7 +384,14 @@ describe 'InputAction::Base' do
|
|
|
366
384
|
::I18n.backend.store_translations :en, :formtastic => {
|
|
367
385
|
:update => 'Save %{model}',
|
|
368
386
|
:reset => 'Reset %{model}',
|
|
369
|
-
:cancel => 'Cancel %{model}'
|
|
387
|
+
:cancel => 'Cancel %{model}',
|
|
388
|
+
:actions => {
|
|
389
|
+
:message => {
|
|
390
|
+
:submit => 'Submit message',
|
|
391
|
+
:reset => 'Reset message',
|
|
392
|
+
:cancel => 'Cancel message'
|
|
393
|
+
}
|
|
394
|
+
}
|
|
370
395
|
}
|
|
371
396
|
end
|
|
372
397
|
|
|
@@ -380,9 +405,20 @@ describe 'InputAction::Base' do
|
|
|
380
405
|
concat(builder.action(:reset, :as => :generic))
|
|
381
406
|
concat(builder.action(:cancel, :as => :generic))
|
|
382
407
|
end)
|
|
383
|
-
output_buffer.
|
|
384
|
-
output_buffer.
|
|
385
|
-
output_buffer.
|
|
408
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Save Post"]')
|
|
409
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Reset Post"]')
|
|
410
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel Post"]')
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
it 'should render an input with custom resource name localized label' do
|
|
414
|
+
concat(semantic_form_for(:post, :as => :message, :url => 'http://example.com') do |builder|
|
|
415
|
+
concat(builder.action(:submit, :as => :generic))
|
|
416
|
+
concat(builder.action(:reset, :as => :generic))
|
|
417
|
+
concat(builder.action(:cancel, :as => :generic))
|
|
418
|
+
end)
|
|
419
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Submit message"]')
|
|
420
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Cancel message"]')
|
|
421
|
+
expect(output_buffer).to have_tag('li.generic_action input[@value="Reset message"]')
|
|
386
422
|
end
|
|
387
423
|
end
|
|
388
424
|
|
|
@@ -420,9 +456,9 @@ describe 'InputAction::Base' do
|
|
|
420
456
|
concat(builder.action(:reset, :as => :generic))
|
|
421
457
|
concat(builder.action(:cancel, :as => :generic))
|
|
422
458
|
end)
|
|
423
|
-
output_buffer.
|
|
424
|
-
output_buffer.
|
|
425
|
-
output_buffer.
|
|
459
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Save Post"]})
|
|
460
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
|
|
461
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
|
|
426
462
|
end
|
|
427
463
|
end
|
|
428
464
|
|
|
@@ -433,9 +469,9 @@ describe 'InputAction::Base' do
|
|
|
433
469
|
concat(builder.action(:reset, :as => :generic))
|
|
434
470
|
concat(builder.action(:cancel, :as => :generic))
|
|
435
471
|
end)
|
|
436
|
-
output_buffer.
|
|
437
|
-
output_buffer.
|
|
438
|
-
output_buffer.
|
|
472
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Save"]})
|
|
473
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
|
|
474
|
+
expect(output_buffer).to have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
|
|
439
475
|
::I18n.backend.store_translations :en, :formtastic => {}
|
|
440
476
|
end
|
|
441
477
|
end
|
|
@@ -466,7 +502,7 @@ describe 'InputAction::Base' do
|
|
|
466
502
|
end
|
|
467
503
|
@new_user_post = ::UserPost.new
|
|
468
504
|
|
|
469
|
-
@new_user_post.
|
|
505
|
+
allow(@new_user_post).to receive(:new_record?).and_return(true)
|
|
470
506
|
concat(semantic_form_for(@new_user_post, :url => '') do |builder|
|
|
471
507
|
concat(builder.action(:submit, :as => :generic))
|
|
472
508
|
concat(builder.action(:reset, :as => :generic))
|
|
@@ -475,9 +511,9 @@ describe 'InputAction::Base' do
|
|
|
475
511
|
end
|
|
476
512
|
|
|
477
513
|
it "should render the string as the value of the button" do
|
|
478
|
-
output_buffer.
|
|
479
|
-
output_buffer.
|
|
480
|
-
output_buffer.
|
|
514
|
+
expect(output_buffer).to have_tag('li input[@value="Create User post"]')
|
|
515
|
+
expect(output_buffer).to have_tag('li input[@value="Reset User post"]')
|
|
516
|
+
expect(output_buffer).to have_tag('li input[@value="Cancel User post"]')
|
|
481
517
|
end
|
|
482
518
|
|
|
483
519
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
|
|
4
|
-
describe 'InputAction', 'when submitting' do
|
|
4
|
+
RSpec.describe 'InputAction', 'when submitting' do
|
|
5
5
|
|
|
6
6
|
include FormtasticSpecHelper
|
|
7
7
|
|
|
@@ -15,12 +15,12 @@ describe 'InputAction', 'when submitting' do
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it 'should render a submit type of input' do
|
|
18
|
-
output_buffer.
|
|
18
|
+
expect(output_buffer).to have_tag('li.action.input_action input[@type="submit"]')
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
describe 'InputAction', 'when resetting' do
|
|
23
|
+
RSpec.describe 'InputAction', 'when resetting' do
|
|
24
24
|
|
|
25
25
|
include FormtasticSpecHelper
|
|
26
26
|
|
|
@@ -34,12 +34,12 @@ describe 'InputAction', 'when resetting' do
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it 'should render a reset type of input' do
|
|
37
|
-
output_buffer.
|
|
37
|
+
expect(output_buffer).to have_tag('li.action.input_action input[@type="reset"]')
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
describe 'InputAction', 'when cancelling' do
|
|
42
|
+
RSpec.describe 'InputAction', 'when cancelling' do
|
|
43
43
|
|
|
44
44
|
include FormtasticSpecHelper
|
|
45
45
|
|
|
@@ -49,11 +49,11 @@ describe 'InputAction', 'when cancelling' do
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
it 'should raise an error' do
|
|
52
|
-
|
|
52
|
+
expect {
|
|
53
53
|
concat(semantic_form_for(@new_post) do |builder|
|
|
54
54
|
concat(builder.action(:cancel, :as => :input))
|
|
55
55
|
end)
|
|
56
|
-
}.
|
|
56
|
+
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
|
|
4
|
-
describe 'LinkAction', 'when cancelling' do
|
|
4
|
+
RSpec.describe 'LinkAction', 'when cancelling' do
|
|
5
5
|
|
|
6
6
|
include FormtasticSpecHelper
|
|
7
7
|
|
|
@@ -18,7 +18,7 @@ describe 'LinkAction', 'when cancelling' do
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it 'should render a submit type of input' do
|
|
21
|
-
output_buffer.
|
|
21
|
+
expect(output_buffer).to have_tag('li.action.link_action a[@href="javascript:history.back()"]')
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
end
|
|
@@ -32,7 +32,7 @@ describe 'LinkAction', 'when cancelling' do
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
it 'should render a submit type of input' do
|
|
35
|
-
output_buffer.
|
|
35
|
+
expect(output_buffer).to have_tag('li.action.link_action a[@href="http://foo.bah/baz"]')
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
end
|
|
@@ -46,14 +46,14 @@ describe 'LinkAction', 'when cancelling' do
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it 'should render a submit type of input' do
|
|
49
|
-
output_buffer.
|
|
49
|
+
expect(output_buffer).to have_tag('li.action.link_action a[@href="/mock/path"]')
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
describe 'LinkAction', 'when submitting' do
|
|
56
|
+
RSpec.describe 'LinkAction', 'when submitting' do
|
|
57
57
|
|
|
58
58
|
include FormtasticSpecHelper
|
|
59
59
|
|
|
@@ -63,16 +63,16 @@ describe 'LinkAction', 'when submitting' do
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
it 'should raise an error' do
|
|
66
|
-
|
|
66
|
+
expect {
|
|
67
67
|
concat(semantic_form_for(@new_post) do |builder|
|
|
68
68
|
concat(builder.action(:submit, :as => :link))
|
|
69
69
|
end)
|
|
70
|
-
}.
|
|
70
|
+
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
describe 'LinkAction', 'when submitting' do
|
|
75
|
+
RSpec.describe 'LinkAction', 'when submitting' do
|
|
76
76
|
|
|
77
77
|
include FormtasticSpecHelper
|
|
78
78
|
|
|
@@ -82,11 +82,11 @@ describe 'LinkAction', 'when submitting' do
|
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
it 'should raise an error' do
|
|
85
|
-
|
|
85
|
+
expect {
|
|
86
86
|
concat(semantic_form_for(@new_post) do |builder|
|
|
87
87
|
concat(builder.action(:reset, :as => :link))
|
|
88
88
|
end)
|
|
89
|
-
}.
|
|
89
|
+
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
|
|
4
|
-
describe 'Formtastic::Helpers::FormHelper.builder' do
|
|
4
|
+
RSpec.describe 'Formtastic::Helpers::FormHelper.builder' do
|
|
5
5
|
|
|
6
6
|
include FormtasticSpecHelper
|
|
7
7
|
|
|
8
8
|
class MyCustomFormBuilder < Formtastic::FormBuilder
|
|
9
9
|
end
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
# TODO should be a separate spec for custom inputs
|
|
12
12
|
class Formtastic::Inputs::AwesomeInput
|
|
13
13
|
include Formtastic::Inputs::Base
|
|
@@ -22,32 +22,32 @@ describe 'Formtastic::Helpers::FormHelper.builder' do
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it 'is the Formtastic::FormBuilder by default' do
|
|
25
|
-
Formtastic::Helpers::FormHelper.builder.
|
|
25
|
+
expect(Formtastic::Helpers::FormHelper.builder).to eq(Formtastic::FormBuilder)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
it 'can be configured to use your own custom form builder' do
|
|
29
29
|
# Set it to a custom builder class
|
|
30
30
|
Formtastic::Helpers::FormHelper.builder = MyCustomFormBuilder
|
|
31
|
-
Formtastic::Helpers::FormHelper.builder.
|
|
31
|
+
expect(Formtastic::Helpers::FormHelper.builder).to eq(MyCustomFormBuilder)
|
|
32
32
|
|
|
33
33
|
# Reset it to the default
|
|
34
34
|
Formtastic::Helpers::FormHelper.builder = Formtastic::FormBuilder
|
|
35
|
-
Formtastic::Helpers::FormHelper.builder.
|
|
35
|
+
expect(Formtastic::Helpers::FormHelper.builder).to eq(Formtastic::FormBuilder)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
it 'should allow custom settings per form builder subclass' do
|
|
39
39
|
with_config(:all_fields_required_by_default, true) do
|
|
40
40
|
MyCustomFormBuilder.all_fields_required_by_default = false
|
|
41
41
|
|
|
42
|
-
MyCustomFormBuilder.all_fields_required_by_default.
|
|
43
|
-
Formtastic::FormBuilder.all_fields_required_by_default.
|
|
42
|
+
expect(MyCustomFormBuilder.all_fields_required_by_default).to be_falsey
|
|
43
|
+
expect(Formtastic::FormBuilder.all_fields_required_by_default).to be_truthy
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
describe "when using a custom builder" do
|
|
48
48
|
|
|
49
49
|
before do
|
|
50
|
-
@new_post.
|
|
50
|
+
allow(@new_post).to receive(:title)
|
|
51
51
|
Formtastic::Helpers::FormHelper.builder = MyCustomFormBuilder
|
|
52
52
|
end
|
|
53
53
|
|
|
@@ -59,10 +59,10 @@ describe 'Formtastic::Helpers::FormHelper.builder' do
|
|
|
59
59
|
|
|
60
60
|
it "should yield an instance of the custom builder" do
|
|
61
61
|
semantic_form_for(@new_post) do |builder|
|
|
62
|
-
builder.class.
|
|
62
|
+
expect(builder.class).to be(MyCustomFormBuilder)
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
# TODO should be a separate spec for custom inputs
|
|
67
67
|
it "should allow me to call my custom input" do
|
|
68
68
|
semantic_form_for(@new_post) do |builder|
|
|
@@ -70,31 +70,47 @@ describe 'Formtastic::Helpers::FormHelper.builder' do
|
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
# See: https://github.com/
|
|
73
|
+
# See: https://github.com/formtastic/formtastic/issues/657
|
|
74
74
|
it "should not conflict with navigasmic" do
|
|
75
|
-
|
|
75
|
+
allow_any_instance_of(self.class).to receive(:builder).and_return('navigasmic')
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
expect { semantic_form_for(@new_post) { |f| } }.not_to raise_error
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
+
it "should use the custom builder's skipped_columns config for inputs" do
|
|
81
|
+
class AnotherCustomFormBuilder < Formtastic::FormBuilder
|
|
82
|
+
configure :skipped_columns, [:title, :created_at]
|
|
83
|
+
end
|
|
84
|
+
#AnotherCustomFormBuilder.skipped_columns = [:title, :created_at]
|
|
85
|
+
|
|
86
|
+
concat(semantic_form_for(@new_post, builder: AnotherCustomFormBuilder) do |builder|
|
|
87
|
+
concat(builder.inputs)
|
|
88
|
+
end)
|
|
89
|
+
|
|
90
|
+
expect(output_buffer).to_not have_tag('input#post_title')
|
|
91
|
+
expect(output_buffer).to_not have_tag('li#post_created_at_input')
|
|
92
|
+
expect(output_buffer).to have_tag('textarea#post_body')
|
|
93
|
+
end
|
|
80
94
|
end
|
|
81
95
|
|
|
82
96
|
describe "fields_for" do
|
|
83
97
|
|
|
84
98
|
it "should yield an instance of the parent form builder" do
|
|
85
|
-
@new_post.
|
|
86
|
-
@new_post.
|
|
99
|
+
allow(@new_post).to receive(:comment).and_return([@fred])
|
|
100
|
+
allow(@new_post).to receive(:comment_attributes=)
|
|
87
101
|
semantic_form_for(@new_post, :builder => MyCustomFormBuilder) do |builder|
|
|
88
|
-
builder.class.
|
|
89
|
-
|
|
102
|
+
expect(builder.class).to be(MyCustomFormBuilder)
|
|
103
|
+
|
|
90
104
|
builder.fields_for(:comment) do |nested_builder|
|
|
91
|
-
nested_builder.class.
|
|
105
|
+
expect(nested_builder.class).to be(MyCustomFormBuilder)
|
|
92
106
|
end
|
|
93
107
|
end
|
|
94
108
|
end
|
|
95
109
|
|
|
96
110
|
end
|
|
97
111
|
|
|
112
|
+
|
|
113
|
+
|
|
98
114
|
end
|
|
99
115
|
|
|
100
116
|
describe "when using a builder passed to form options" do
|
|
@@ -102,10 +118,10 @@ describe 'Formtastic::Helpers::FormHelper.builder' do
|
|
|
102
118
|
describe "fields_for" do
|
|
103
119
|
|
|
104
120
|
it "should yield an instance of the parent form builder" do
|
|
105
|
-
@new_post.
|
|
121
|
+
allow(@new_post).to receive(:author_attributes=)
|
|
106
122
|
semantic_form_for(@new_post, :builder => MyCustomFormBuilder) do |builder|
|
|
107
123
|
builder.fields_for(:author) do |nested_builder|
|
|
108
|
-
nested_builder.class.
|
|
124
|
+
expect(nested_builder.class).to be(MyCustomFormBuilder)
|
|
109
125
|
end
|
|
110
126
|
end
|
|
111
127
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
|
|
4
|
-
describe 'Rails field_error_proc' do
|
|
4
|
+
RSpec.describe 'Rails field_error_proc' do
|
|
5
5
|
|
|
6
6
|
include FormtasticSpecHelper
|
|
7
7
|
|
|
@@ -14,13 +14,13 @@ describe 'Rails field_error_proc' do
|
|
|
14
14
|
current_field_error_proc = ::ActionView::Base.field_error_proc
|
|
15
15
|
|
|
16
16
|
semantic_form_for(@new_post) do |builder|
|
|
17
|
-
::ActionView::Base.field_error_proc.
|
|
17
|
+
expect(::ActionView::Base.field_error_proc).not_to eq(current_field_error_proc)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
::ActionView::Base.field_error_proc.
|
|
20
|
+
expect(::ActionView::Base.field_error_proc).to eq(current_field_error_proc)
|
|
21
21
|
|
|
22
22
|
form_for(@new_post) do |builder|
|
|
23
|
-
::ActionView::Base.field_error_proc.
|
|
23
|
+
expect(::ActionView::Base.field_error_proc).to eq(current_field_error_proc)
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|