formtastic 3.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitattributes +1 -0
- data/.github/workflows/test.yml +61 -0
- data/.gitignore +3 -2
- data/CHANGELOG.md +61 -0
- data/Gemfile.lock +140 -0
- data/MIT-LICENSE +1 -1
- data/{README.textile → README.md} +191 -168
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +24 -8
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +13 -17
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_6.1/Gemfile +5 -0
- data/gemfiles/rails_7.0/Gemfile +5 -0
- data/gemfiles/rails_7.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic/action_class_finder.rb +19 -0
- data/lib/formtastic/actions/base.rb +1 -0
- data/lib/formtastic/actions/button_action.rb +56 -53
- data/lib/formtastic/actions/buttonish.rb +1 -0
- data/lib/formtastic/actions/input_action.rb +60 -57
- data/lib/formtastic/actions/link_action.rb +69 -67
- data/lib/formtastic/actions.rb +7 -3
- data/lib/formtastic/deprecation.rb +6 -0
- data/lib/formtastic/engine.rb +4 -1
- data/lib/formtastic/form_builder.rb +32 -25
- data/lib/formtastic/helpers/action_helper.rb +22 -31
- data/lib/formtastic/helpers/actions_helper.rb +1 -0
- data/lib/formtastic/helpers/enum.rb +14 -0
- data/lib/formtastic/helpers/errors_helper.rb +3 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -11
- data/lib/formtastic/helpers/file_column_detection.rb +1 -0
- data/lib/formtastic/helpers/form_helper.rb +4 -3
- data/lib/formtastic/helpers/input_helper.rb +59 -80
- data/lib/formtastic/helpers/inputs_helper.rb +33 -27
- data/lib/formtastic/helpers/reflection.rb +5 -4
- data/lib/formtastic/helpers.rb +2 -2
- data/lib/formtastic/html_attributes.rb +13 -1
- data/lib/formtastic/i18n.rb +2 -1
- data/lib/formtastic/input_class_finder.rb +19 -0
- data/lib/formtastic/inputs/base/associations.rb +1 -0
- data/lib/formtastic/inputs/base/choices.rb +4 -3
- data/lib/formtastic/inputs/base/collections.rb +47 -11
- data/lib/formtastic/inputs/base/database.rb +8 -5
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +1 -0
- data/lib/formtastic/inputs/base/errors.rb +7 -6
- data/lib/formtastic/inputs/base/fileish.rb +1 -0
- data/lib/formtastic/inputs/base/hints.rb +2 -1
- data/lib/formtastic/inputs/base/html.rb +12 -10
- data/lib/formtastic/inputs/base/labelling.rb +3 -2
- data/lib/formtastic/inputs/base/naming.rb +5 -4
- data/lib/formtastic/inputs/base/numeric.rb +1 -0
- data/lib/formtastic/inputs/base/options.rb +3 -3
- data/lib/formtastic/inputs/base/placeholder.rb +1 -0
- data/lib/formtastic/inputs/base/stringish.rb +1 -0
- data/lib/formtastic/inputs/base/timeish.rb +9 -4
- data/lib/formtastic/inputs/base/validations.rb +39 -12
- data/lib/formtastic/inputs/base/wrapping.rb +2 -3
- data/lib/formtastic/inputs/base.rb +17 -12
- data/lib/formtastic/inputs/boolean_input.rb +2 -1
- data/lib/formtastic/inputs/check_boxes_input.rb +16 -24
- data/lib/formtastic/inputs/color_input.rb +1 -1
- data/lib/formtastic/inputs/country_input.rb +4 -1
- data/lib/formtastic/inputs/datalist_input.rb +42 -0
- data/lib/formtastic/inputs/date_picker_input.rb +1 -0
- data/lib/formtastic/inputs/date_select_input.rb +1 -0
- data/lib/formtastic/inputs/datetime_picker_input.rb +1 -0
- data/lib/formtastic/inputs/datetime_select_input.rb +1 -0
- data/lib/formtastic/inputs/email_input.rb +1 -0
- data/lib/formtastic/inputs/file_input.rb +3 -2
- data/lib/formtastic/inputs/hidden_input.rb +3 -2
- data/lib/formtastic/inputs/number_input.rb +1 -0
- data/lib/formtastic/inputs/password_input.rb +1 -0
- data/lib/formtastic/inputs/phone_input.rb +1 -0
- data/lib/formtastic/inputs/radio_input.rb +26 -21
- data/lib/formtastic/inputs/range_input.rb +1 -0
- data/lib/formtastic/inputs/search_input.rb +1 -0
- data/lib/formtastic/inputs/select_input.rb +32 -10
- data/lib/formtastic/inputs/string_input.rb +1 -0
- data/lib/formtastic/inputs/text_input.rb +1 -0
- data/lib/formtastic/inputs/time_picker_input.rb +1 -0
- data/lib/formtastic/inputs/time_select_input.rb +1 -0
- data/lib/formtastic/inputs/time_zone_input.rb +17 -6
- data/lib/formtastic/inputs/url_input.rb +1 -0
- data/lib/formtastic/inputs.rb +33 -28
- data/lib/formtastic/localized_string.rb +2 -1
- data/lib/formtastic/localizer.rb +23 -24
- data/lib/formtastic/namespaced_class_finder.rb +98 -0
- data/lib/formtastic/version.rb +2 -1
- data/lib/formtastic.rb +19 -14
- data/lib/generators/formtastic/form/form_generator.rb +8 -2
- data/lib/generators/formtastic/input/input_generator.rb +47 -0
- data/lib/generators/formtastic/install/install_generator.rb +2 -0
- data/lib/generators/templates/formtastic.rb +29 -7
- data/lib/generators/templates/input.rb +19 -0
- data/sample/basic_inputs.html +1 -1
- data/script/integration-template.rb +73 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +13 -0
- data/spec/actions/button_action_spec.rb +21 -20
- data/spec/actions/generic_action_spec.rb +134 -133
- data/spec/actions/input_action_spec.rb +20 -19
- data/spec/actions/link_action_spec.rb +30 -29
- data/spec/builder/custom_builder_spec.rb +39 -22
- data/spec/builder/error_proc_spec.rb +6 -5
- data/spec/builder/semantic_fields_for_spec.rb +46 -45
- data/spec/fast_spec_helper.rb +13 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +33 -32
- data/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +10 -9
- data/spec/helpers/action_helper_spec.rb +70 -97
- data/spec/helpers/actions_helper_spec.rb +43 -42
- data/spec/helpers/form_helper_spec.rb +56 -39
- data/spec/helpers/input_helper_spec.rb +314 -255
- data/spec/helpers/inputs_helper_spec.rb +217 -202
- data/spec/helpers/reflection_helper_spec.rb +7 -6
- data/spec/helpers/semantic_errors_helper_spec.rb +26 -25
- data/spec/i18n_spec.rb +30 -29
- data/spec/input_class_finder_spec.rb +11 -0
- data/spec/inputs/base/collections_spec.rb +78 -0
- data/spec/inputs/base/validations_spec.rb +481 -0
- data/spec/inputs/boolean_input_spec.rb +73 -72
- data/spec/inputs/check_boxes_input_spec.rb +174 -123
- data/spec/inputs/color_input_spec.rb +53 -64
- data/spec/inputs/country_input_spec.rb +23 -22
- data/spec/inputs/custom_input_spec.rb +3 -6
- data/spec/inputs/datalist_input_spec.rb +62 -0
- data/spec/inputs/date_picker_input_spec.rb +114 -113
- data/spec/inputs/date_select_input_spec.rb +76 -61
- data/spec/inputs/datetime_picker_input_spec.rb +123 -122
- data/spec/inputs/datetime_select_input_spec.rb +85 -68
- data/spec/inputs/email_input_spec.rb +17 -16
- data/spec/inputs/file_input_spec.rb +18 -17
- data/spec/inputs/hidden_input_spec.rb +32 -31
- data/spec/inputs/include_blank_spec.rb +10 -9
- data/spec/inputs/label_spec.rb +36 -31
- data/spec/inputs/number_input_spec.rb +212 -211
- data/spec/inputs/password_input_spec.rb +17 -16
- data/spec/inputs/phone_input_spec.rb +17 -16
- data/spec/inputs/placeholder_spec.rb +18 -17
- data/spec/inputs/radio_input_spec.rb +92 -65
- data/spec/inputs/range_input_spec.rb +136 -135
- data/spec/inputs/readonly_spec.rb +51 -0
- data/spec/inputs/search_input_spec.rb +16 -15
- data/spec/inputs/select_input_spec.rb +209 -102
- data/spec/inputs/string_input_spec.rb +51 -50
- data/spec/inputs/text_input_spec.rb +34 -33
- data/spec/inputs/time_picker_input_spec.rb +115 -114
- data/spec/inputs/time_select_input_spec.rb +84 -70
- data/spec/inputs/time_zone_input_spec.rb +58 -31
- data/spec/inputs/url_input_spec.rb +17 -16
- data/spec/inputs/with_options_spec.rb +9 -8
- data/spec/localizer_spec.rb +18 -17
- data/spec/namespaced_class_finder_spec.rb +91 -0
- data/spec/schema.rb +22 -0
- data/spec/spec_helper.rb +180 -249
- data/spec/support/custom_macros.rb +128 -98
- data/spec/support/deprecation.rb +2 -1
- data/spec/support/shared_examples.rb +13 -0
- data/spec/support/specialized_class_finder_shared_example.rb +28 -0
- data/spec/support/test_environment.rb +25 -10
- metadata +95 -136
- data/.travis.yml +0 -28
- data/Appraisals +0 -25
- data/CHANGELOG +0 -27
- data/gemfiles/rails_3.2.gemfile +0 -7
- data/gemfiles/rails_4.0.4.gemfile +0 -7
- data/gemfiles/rails_4.1.gemfile +0 -7
- data/gemfiles/rails_4.gemfile +0 -7
- data/gemfiles/rails_edge.gemfile +0 -10
- data/lib/formtastic/util.rb +0 -53
- data/spec/support/deferred_garbage_collection.rb +0 -21
- data/spec/util_spec.rb +0 -52
@@ -1,12 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
|
-
describe 'FormHelper' do
|
5
|
+
RSpec.describe 'FormHelper' do
|
5
6
|
|
6
7
|
include FormtasticSpecHelper
|
7
8
|
|
8
9
|
before do
|
9
|
-
@output_buffer = ''
|
10
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
10
11
|
mock_everything
|
11
12
|
end
|
12
13
|
|
@@ -14,45 +15,45 @@ describe 'FormHelper' do
|
|
14
15
|
|
15
16
|
it 'yields an instance of Formtastic::FormBuilder' do
|
16
17
|
semantic_form_for(@new_post, :url => '/hello') do |builder|
|
17
|
-
builder.class.
|
18
|
+
expect(builder.class).to eq(Formtastic::FormBuilder)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
it 'adds a class of "formtastic" to the generated form' do
|
22
23
|
concat(semantic_form_for(@new_post, :url => '/hello') do |builder|
|
23
24
|
end)
|
24
|
-
output_buffer.
|
25
|
+
expect(output_buffer.to_str).to have_tag("form.formtastic")
|
25
26
|
end
|
26
27
|
|
27
|
-
it '
|
28
|
+
it 'does not add "novalidate" attribute to the generated form when configured to do so' do
|
28
29
|
with_config :perform_browser_validations, true do
|
29
30
|
concat(semantic_form_for(@new_post, :url => '/hello') do |builder|
|
30
31
|
end)
|
31
|
-
output_buffer.
|
32
|
+
expect(output_buffer.to_str).not_to have_tag("form[@novalidate]")
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
it '
|
36
|
+
it 'adds "novalidate" attribute to the generated form when configured to do so' do
|
36
37
|
with_config :perform_browser_validations, false do
|
37
38
|
concat(semantic_form_for(@new_post, :url => '/hello') do |builder|
|
38
39
|
end)
|
39
|
-
output_buffer.
|
40
|
+
expect(output_buffer.to_str).to have_tag("form[@novalidate]")
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
|
-
it 'allows form HTML to override "novalidate" attribute when
|
44
|
+
it 'allows form HTML to override "novalidate" attribute when configured to validate' do
|
44
45
|
with_config :perform_browser_validations, false do
|
45
46
|
concat(semantic_form_for(@new_post, :url => '/hello', :html => { :novalidate => true }) do |builder|
|
46
47
|
end)
|
47
|
-
output_buffer.
|
48
|
+
expect(output_buffer.to_str).to have_tag("form[@novalidate]")
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
it 'allows form HTML to override "novalidate" attribute when
|
52
|
+
it 'allows form HTML to override "novalidate" attribute when configured to not validate' do
|
52
53
|
with_config :perform_browser_validations, true do
|
53
54
|
concat(semantic_form_for(@new_post, :url => '/hello', :html => { :novalidate => false }) do |builder|
|
54
55
|
end)
|
55
|
-
output_buffer.
|
56
|
+
expect(output_buffer.to_str).not_to have_tag("form[@novalidate]")
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
@@ -60,103 +61,109 @@ describe 'FormHelper' do
|
|
60
61
|
Formtastic::Helpers::FormHelper.default_form_class = 'xyz'
|
61
62
|
concat(semantic_form_for(::Post.new, :as => :post, :url => '/hello') do |builder|
|
62
63
|
end)
|
63
|
-
output_buffer.
|
64
|
+
expect(output_buffer.to_str).to have_tag("form.xyz")
|
64
65
|
end
|
65
66
|
|
66
67
|
it 'omits the leading spaces from the classes in the generated form when the default class is nil' do
|
67
68
|
Formtastic::Helpers::FormHelper.default_form_class = nil
|
68
69
|
concat(semantic_form_for(::Post.new, :as => :post, :url => '/hello') do |builder|
|
69
70
|
end)
|
70
|
-
output_buffer.
|
71
|
+
expect(output_buffer.to_str).to have_tag("form[class='post']")
|
71
72
|
end
|
72
73
|
|
73
74
|
it 'adds class matching the object name to the generated form when a symbol is provided' do
|
74
75
|
concat(semantic_form_for(@new_post, :url => '/hello') do |builder|
|
75
76
|
end)
|
76
|
-
output_buffer.
|
77
|
+
expect(output_buffer.to_str).to have_tag("form.post")
|
77
78
|
|
78
79
|
concat(semantic_form_for(:project, :url => '/hello') do |builder|
|
79
80
|
end)
|
80
|
-
output_buffer.
|
81
|
+
expect(output_buffer.to_str).to have_tag("form.project")
|
81
82
|
end
|
82
83
|
|
83
84
|
it 'adds class matching the :as option when provided' do
|
84
85
|
concat(semantic_form_for(@new_post, :as => :message, :url => '/hello') do |builder|
|
85
86
|
end)
|
86
|
-
output_buffer.
|
87
|
+
expect(output_buffer.to_str).to have_tag("form.message")
|
87
88
|
|
88
89
|
concat(semantic_form_for([:admins, @new_post], :as => :message, :url => '/hello') do |builder|
|
89
90
|
end)
|
90
|
-
output_buffer.
|
91
|
+
expect(output_buffer.to_str).to have_tag("form.message")
|
91
92
|
end
|
92
93
|
|
93
94
|
it 'adds class matching the object\'s class to the generated form when an object is provided' do
|
94
95
|
concat(semantic_form_for(@new_post) do |builder|
|
95
96
|
end)
|
96
|
-
output_buffer.
|
97
|
+
expect(output_buffer.to_str).to have_tag("form.post")
|
97
98
|
end
|
98
99
|
|
99
100
|
it 'adds a namespaced class to the generated form' do
|
100
101
|
concat(semantic_form_for(::Namespaced::Post.new, :url => '/hello') do |builder|
|
101
102
|
end)
|
102
|
-
output_buffer.
|
103
|
+
expect(output_buffer.to_str).to have_tag("form.namespaced_post")
|
103
104
|
end
|
104
105
|
|
105
106
|
it 'adds a customized class to the generated form' do
|
106
107
|
Formtastic::Helpers::FormHelper.default_form_model_class_proc = lambda { |model_class_name| "#{model_class_name}_form" }
|
107
108
|
concat(semantic_form_for(@new_post, :url => '/hello') do |builder|
|
108
109
|
end)
|
109
|
-
output_buffer.
|
110
|
+
expect(output_buffer.to_str).to have_tag("form.post_form")
|
110
111
|
|
111
112
|
concat(semantic_form_for(:project, :url => '/hello') do |builder|
|
112
113
|
end)
|
113
|
-
output_buffer.
|
114
|
+
expect(output_buffer.to_str).to have_tag("form.project_form")
|
114
115
|
end
|
115
116
|
|
116
117
|
describe 'allows :html options' do
|
117
|
-
before(:
|
118
|
+
before(:example) do
|
118
119
|
concat(semantic_form_for(@new_post, :url => '/hello', :html => { :id => "something-special", :class => "something-extra", :multipart => true }) do |builder|
|
119
120
|
end)
|
120
121
|
end
|
121
122
|
|
122
123
|
it 'to add a id of "something-special" to generated form' do
|
123
|
-
output_buffer.
|
124
|
+
expect(output_buffer.to_str).to have_tag("form#something-special")
|
124
125
|
end
|
125
126
|
|
126
127
|
it 'to add a class of "something-extra" to generated form' do
|
127
|
-
output_buffer.
|
128
|
+
expect(output_buffer.to_str).to have_tag("form.something-extra")
|
128
129
|
end
|
129
130
|
|
130
131
|
it 'to add enctype="multipart/form-data"' do
|
131
|
-
output_buffer.
|
132
|
+
expect(output_buffer.to_str).to have_tag('form[@enctype="multipart/form-data"]')
|
132
133
|
end
|
133
134
|
end
|
134
135
|
|
135
136
|
it 'can be called with a resource-oriented style' do
|
136
137
|
semantic_form_for(@new_post) do |builder|
|
137
|
-
builder.object.class.
|
138
|
-
builder.object_name.
|
138
|
+
expect(builder.object.class).to eq(::Post)
|
139
|
+
expect(builder.object_name).to eq("post")
|
139
140
|
end
|
140
141
|
end
|
141
142
|
|
142
143
|
it 'can be called with a generic style and instance variable' do
|
143
144
|
semantic_form_for(@new_post, :as => :post, :url => new_post_path) do |builder|
|
144
|
-
builder.object.class.
|
145
|
-
builder.object_name.to_s.
|
145
|
+
expect(builder.object.class).to eq(::Post)
|
146
|
+
expect(builder.object_name.to_s).to eq("post") # TODO: is this forced .to_s a bad assumption somewhere?
|
146
147
|
end
|
147
148
|
end
|
148
149
|
|
149
150
|
it 'can be called with a generic style and inline object' do
|
150
151
|
semantic_form_for(@new_post, :url => new_post_path) do |builder|
|
151
|
-
builder.object.class.
|
152
|
-
builder.object_name.to_s.
|
152
|
+
expect(builder.object.class).to eq(::Post)
|
153
|
+
expect(builder.object_name.to_s).to eq("post") # TODO: is this forced .to_s a bad assumption somewhere?
|
153
154
|
end
|
154
155
|
end
|
155
156
|
|
156
157
|
describe 'ActionView::Base.field_error_proc' do
|
158
|
+
around do |ex|
|
159
|
+
error_proc = Formtastic::Helpers::FormHelper.formtastic_field_error_proc
|
160
|
+
ex.run
|
161
|
+
Formtastic::Helpers::FormHelper.formtastic_field_error_proc = error_proc
|
162
|
+
end
|
163
|
+
|
157
164
|
it 'is set to no-op wrapper by default' do
|
158
165
|
semantic_form_for(@new_post, :url => '/hello') do |builder|
|
159
|
-
::ActionView::Base.field_error_proc.call("html", nil).
|
166
|
+
expect(::ActionView::Base.field_error_proc.call("html", nil)).to eq("html")
|
160
167
|
end
|
161
168
|
end
|
162
169
|
|
@@ -164,15 +171,15 @@ describe 'FormHelper' do
|
|
164
171
|
field_error_proc = double()
|
165
172
|
Formtastic::Helpers::FormHelper.formtastic_field_error_proc = field_error_proc
|
166
173
|
semantic_form_for(@new_post, :url => '/hello') do |builder|
|
167
|
-
::ActionView::Base.field_error_proc.
|
174
|
+
expect(::ActionView::Base.field_error_proc).to eq(field_error_proc)
|
168
175
|
end
|
169
176
|
end
|
170
177
|
|
171
178
|
it 'is restored to its original value after the form is rendered' do
|
172
|
-
|
179
|
+
expect do
|
173
180
|
Formtastic::Helpers::FormHelper.formtastic_field_error_proc = proc {""}
|
174
181
|
semantic_form_for(@new_post, :url => '/hello') { |builder| }
|
175
|
-
end.
|
182
|
+
end.not_to change(::ActionView::Base, :field_error_proc)
|
176
183
|
end
|
177
184
|
end
|
178
185
|
|
@@ -181,7 +188,7 @@ describe 'FormHelper' do
|
|
181
188
|
class MyAwesomeCustomBuilder < Formtastic::FormBuilder
|
182
189
|
end
|
183
190
|
semantic_form_for(@new_post, :url => '/hello', :builder => MyAwesomeCustomBuilder) do |builder|
|
184
|
-
builder.class.
|
191
|
+
expect(builder.class).to eq(MyAwesomeCustomBuilder)
|
185
192
|
end
|
186
193
|
end
|
187
194
|
end
|
@@ -189,7 +196,17 @@ describe 'FormHelper' do
|
|
189
196
|
describe 'with :namespace option' do
|
190
197
|
it "should set the custom_namespace" do
|
191
198
|
semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
192
|
-
builder.
|
199
|
+
expect(builder.dom_id_namespace).to eq('context2')
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe 'without :namespace option' do
|
205
|
+
it 'defaults to class settings' do
|
206
|
+
expect(Formtastic::FormBuilder).to receive(:custom_namespace).and_return('context2')
|
207
|
+
|
208
|
+
semantic_form_for(@new_post) do |builder|
|
209
|
+
expect(builder.dom_id_namespace).to eq('context2')
|
193
210
|
end
|
194
211
|
end
|
195
212
|
end
|
@@ -199,7 +216,7 @@ describe 'FormHelper' do
|
|
199
216
|
describe '#semantic_fields_for' do
|
200
217
|
it 'yields an instance of Formtastic::FormBuilder' do
|
201
218
|
semantic_fields_for(@new_post) do |builder|
|
202
|
-
builder.class.
|
219
|
+
expect(builder.class).to be(Formtastic::FormBuilder)
|
203
220
|
end
|
204
221
|
end
|
205
222
|
end
|