formtastic 4.0.0 → 5.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 +4 -4
- data/.github/workflows/test.yml +13 -13
- data/CHANGELOG.md +10 -1
- data/Gemfile.lock +99 -64
- data/README.md +7 -2
- data/formtastic.gemspec +5 -3
- data/gemfiles/{rails_5.2 → rails_7.0}/Gemfile +1 -1
- data/gemfiles/rails_7.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +1 -1
- data/lib/formtastic/action_class_finder.rb +1 -0
- data/lib/formtastic/actions/base.rb +1 -0
- data/lib/formtastic/actions/button_action.rb +1 -0
- data/lib/formtastic/actions/buttonish.rb +1 -0
- data/lib/formtastic/actions/input_action.rb +1 -0
- data/lib/formtastic/actions/link_action.rb +1 -0
- data/lib/formtastic/actions.rb +1 -0
- data/lib/formtastic/deprecation.rb +2 -1
- data/lib/formtastic/engine.rb +1 -0
- data/lib/formtastic/form_builder.rb +1 -0
- data/lib/formtastic/helpers/action_helper.rb +1 -0
- data/lib/formtastic/helpers/actions_helper.rb +1 -0
- data/lib/formtastic/helpers/enum.rb +1 -0
- data/lib/formtastic/helpers/errors_helper.rb +1 -0
- data/lib/formtastic/helpers/fieldset_wrapper.rb +1 -0
- data/lib/formtastic/helpers/file_column_detection.rb +1 -0
- data/lib/formtastic/helpers/form_helper.rb +1 -0
- data/lib/formtastic/helpers/input_helper.rb +2 -4
- data/lib/formtastic/helpers/inputs_helper.rb +2 -1
- data/lib/formtastic/helpers/reflection.rb +1 -0
- data/lib/formtastic/helpers.rb +1 -1
- data/lib/formtastic/html_attributes.rb +1 -0
- data/lib/formtastic/i18n.rb +1 -0
- data/lib/formtastic/input_class_finder.rb +1 -0
- data/lib/formtastic/inputs/base/associations.rb +1 -0
- data/lib/formtastic/inputs/base/choices.rb +2 -1
- data/lib/formtastic/inputs/base/collections.rb +4 -1
- data/lib/formtastic/inputs/base/database.rb +5 -7
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +1 -0
- data/lib/formtastic/inputs/base/errors.rb +3 -2
- data/lib/formtastic/inputs/base/fileish.rb +1 -0
- data/lib/formtastic/inputs/base/hints.rb +1 -0
- data/lib/formtastic/inputs/base/html.rb +2 -1
- data/lib/formtastic/inputs/base/labelling.rb +3 -2
- data/lib/formtastic/inputs/base/naming.rb +1 -0
- data/lib/formtastic/inputs/base/numeric.rb +1 -0
- data/lib/formtastic/inputs/base/options.rb +1 -0
- 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 +4 -3
- data/lib/formtastic/inputs/base/validations.rb +2 -1
- data/lib/formtastic/inputs/base/wrapping.rb +1 -0
- data/lib/formtastic/inputs/base.rb +3 -2
- data/lib/formtastic/inputs/boolean_input.rb +2 -1
- data/lib/formtastic/inputs/check_boxes_input.rb +2 -1
- data/lib/formtastic/inputs/color_input.rb +1 -0
- data/lib/formtastic/inputs/country_input.rb +1 -0
- data/lib/formtastic/inputs/datalist_input.rb +1 -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 +1 -0
- 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 +1 -0
- 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 +1 -0
- 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 +1 -0
- data/lib/formtastic/inputs/url_input.rb +1 -0
- data/lib/formtastic/inputs.rb +1 -0
- data/lib/formtastic/localized_string.rb +1 -0
- data/lib/formtastic/localizer.rb +1 -0
- data/lib/formtastic/namespaced_class_finder.rb +7 -8
- data/lib/formtastic/version.rb +2 -1
- data/lib/formtastic.rb +1 -0
- data/lib/generators/formtastic/form/form_generator.rb +1 -0
- data/lib/generators/formtastic/input/input_generator.rb +1 -0
- data/lib/generators/formtastic/install/install_generator.rb +1 -0
- data/lib/generators/templates/formtastic.rb +1 -0
- data/script/integration-template.rb +2 -3
- data/spec/action_class_finder_spec.rb +1 -0
- data/spec/actions/button_action_spec.rb +17 -16
- data/spec/actions/generic_action_spec.rb +130 -129
- data/spec/actions/input_action_spec.rb +16 -15
- data/spec/actions/link_action_spec.rb +25 -24
- data/spec/builder/custom_builder_spec.rb +5 -4
- data/spec/builder/error_proc_spec.rb +2 -1
- data/spec/builder/semantic_fields_for_spec.rb +26 -25
- data/spec/fast_spec_helper.rb +1 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +8 -7
- data/spec/generators/formtastic/input/input_generator_spec.rb +1 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +1 -0
- data/spec/helpers/action_helper_spec.rb +15 -14
- data/spec/helpers/actions_helper_spec.rb +42 -41
- data/spec/helpers/form_helper_spec.rb +26 -19
- data/spec/helpers/input_helper_spec.rb +70 -69
- data/spec/helpers/inputs_helper_spec.rb +179 -179
- data/spec/helpers/reflection_helper_spec.rb +4 -3
- data/spec/helpers/semantic_errors_helper_spec.rb +4 -3
- data/spec/i18n_spec.rb +13 -12
- data/spec/input_class_finder_spec.rb +1 -0
- data/spec/inputs/base/collections_spec.rb +2 -0
- data/spec/inputs/base/validations_spec.rb +1 -0
- data/spec/inputs/boolean_input_spec.rb +66 -65
- data/spec/inputs/check_boxes_input_spec.rb +89 -88
- data/spec/inputs/color_input_spec.rb +7 -6
- data/spec/inputs/country_input_spec.rb +10 -9
- data/spec/inputs/custom_input_spec.rb +1 -0
- data/spec/inputs/datalist_input_spec.rb +2 -1
- data/spec/inputs/date_picker_input_spec.rb +109 -108
- data/spec/inputs/date_select_input_spec.rb +63 -62
- data/spec/inputs/datetime_picker_input_spec.rb +118 -117
- data/spec/inputs/datetime_select_input_spec.rb +72 -71
- data/spec/inputs/email_input_spec.rb +16 -15
- data/spec/inputs/file_input_spec.rb +17 -16
- data/spec/inputs/hidden_input_spec.rb +29 -28
- data/spec/inputs/include_blank_spec.rb +7 -6
- data/spec/inputs/label_spec.rb +25 -24
- data/spec/inputs/number_input_spec.rb +159 -158
- data/spec/inputs/password_input_spec.rb +16 -15
- data/spec/inputs/phone_input_spec.rb +16 -15
- data/spec/inputs/placeholder_spec.rb +17 -16
- data/spec/inputs/radio_input_spec.rb +58 -57
- data/spec/inputs/range_input_spec.rb +108 -107
- data/spec/inputs/readonly_spec.rb +5 -4
- data/spec/inputs/search_input_spec.rb +15 -14
- data/spec/inputs/select_input_spec.rb +144 -93
- data/spec/inputs/string_input_spec.rb +36 -35
- data/spec/inputs/text_input_spec.rb +32 -31
- data/spec/inputs/time_picker_input_spec.rb +110 -109
- data/spec/inputs/time_select_input_spec.rb +71 -70
- data/spec/inputs/time_zone_input_spec.rb +21 -20
- data/spec/inputs/url_input_spec.rb +16 -15
- data/spec/inputs/with_options_spec.rb +8 -7
- data/spec/localizer_spec.rb +1 -0
- data/spec/namespaced_class_finder_spec.rb +17 -5
- data/spec/schema.rb +1 -0
- data/spec/spec_helper.rb +8 -8
- data/spec/support/custom_macros.rb +64 -63
- data/spec/support/deprecation.rb +2 -1
- data/spec/support/shared_examples.rb +2 -1
- data/spec/support/specialized_class_finder_shared_example.rb +1 -0
- data/spec/support/test_environment.rb +1 -0
- metadata +29 -14
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module Formtastic
|
|
2
3
|
module Inputs
|
|
3
4
|
module Base
|
|
@@ -43,7 +44,7 @@ module Formtastic
|
|
|
43
44
|
# TODO there's no coverage for this case, not sure how to create a scenario for it
|
|
44
45
|
builder.auto_index
|
|
45
46
|
else
|
|
46
|
-
""
|
|
47
|
+
+""
|
|
47
48
|
end
|
|
48
49
|
end
|
|
49
50
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module Formtastic
|
|
2
3
|
module Inputs
|
|
3
4
|
module Base
|
|
@@ -6,7 +7,7 @@ module Formtastic
|
|
|
6
7
|
include Formtastic::LocalizedString
|
|
7
8
|
|
|
8
9
|
def label_html
|
|
9
|
-
render_label? ? builder.label(input_name, label_text, label_html_options) : "".html_safe
|
|
10
|
+
render_label? ? builder.label(input_name, label_text, label_html_options) : +"".html_safe
|
|
10
11
|
end
|
|
11
12
|
|
|
12
13
|
def label_html_options
|
|
@@ -49,4 +50,4 @@ module Formtastic
|
|
|
49
50
|
end
|
|
50
51
|
end
|
|
51
52
|
end
|
|
52
|
-
end
|
|
53
|
+
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module Formtastic
|
|
2
3
|
module Inputs
|
|
3
4
|
module Base
|
|
@@ -156,7 +157,7 @@ module Formtastic
|
|
|
156
157
|
|
|
157
158
|
def fragment_label_html(fragment)
|
|
158
159
|
text = fragment_label(fragment)
|
|
159
|
-
text.blank? ? "".html_safe : template.content_tag(:label, text, :for => fragment_id(fragment))
|
|
160
|
+
text.blank? ? +"".html_safe : template.content_tag(:label, text, :for => fragment_id(fragment))
|
|
160
161
|
end
|
|
161
162
|
|
|
162
163
|
def value
|
|
@@ -217,7 +218,7 @@ module Formtastic
|
|
|
217
218
|
:class => "label"
|
|
218
219
|
)
|
|
219
220
|
else
|
|
220
|
-
"".html_safe
|
|
221
|
+
+"".html_safe
|
|
221
222
|
end
|
|
222
223
|
end
|
|
223
224
|
|
|
@@ -228,7 +229,7 @@ module Formtastic
|
|
|
228
229
|
end
|
|
229
230
|
|
|
230
231
|
def hidden_fragments
|
|
231
|
-
"".html_safe
|
|
232
|
+
+"".html_safe
|
|
232
233
|
end
|
|
233
234
|
|
|
234
235
|
def hidden_field_name(fragment)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module Formtastic
|
|
2
3
|
module Inputs
|
|
3
4
|
module Base
|
|
@@ -208,7 +209,7 @@ module Formtastic
|
|
|
208
209
|
private
|
|
209
210
|
|
|
210
211
|
# Loosely based on
|
|
211
|
-
# https://github.com/rails/rails/blob/
|
|
212
|
+
# https://github.com/rails/rails/blob/459e7cf62252558bbf65f582a230562ab1a76c5e/activemodel/lib/active_model/validations/numericality.rb#L65-L70
|
|
212
213
|
def option_value(option, object)
|
|
213
214
|
case option
|
|
214
215
|
when Symbol
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module Formtastic
|
|
2
3
|
module Inputs
|
|
3
4
|
module Base
|
|
@@ -21,7 +22,7 @@ module Formtastic
|
|
|
21
22
|
# Usefull for deprecating options.
|
|
22
23
|
def warn_and_correct_option!(old_option_name, new_option_name)
|
|
23
24
|
if options.key?(old_option_name)
|
|
24
|
-
|
|
25
|
+
Deprecation.warn("The :#{old_option_name} option is deprecated in favour of :#{new_option_name} and will be removed from Formtastic in the next version", caller(6))
|
|
25
26
|
options[new_option_name] = options.delete(old_option_name)
|
|
26
27
|
end
|
|
27
28
|
end
|
|
@@ -29,7 +30,7 @@ module Formtastic
|
|
|
29
30
|
# Usefull for deprecating options.
|
|
30
31
|
def warn_deprecated_option!(old_option_name, instructions)
|
|
31
32
|
if options.key?(old_option_name)
|
|
32
|
-
|
|
33
|
+
Deprecation.warn("The :#{old_option_name} option is deprecated in favour of `#{instructions}`. :#{old_option_name} will be removed in the next version", caller(6))
|
|
33
34
|
end
|
|
34
35
|
end
|
|
35
36
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module Formtastic
|
|
2
3
|
module Inputs
|
|
3
4
|
# Boolean inputs are used to render an input for a single checkbox, typically for attributes
|
|
@@ -59,7 +60,7 @@ module Formtastic
|
|
|
59
60
|
end
|
|
60
61
|
|
|
61
62
|
def label_text_with_embedded_checkbox
|
|
62
|
-
check_box_html << "" << label_text
|
|
63
|
+
check_box_html << +"" << label_text
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
def check_box_html
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module Formtastic
|
|
2
3
|
module Inputs
|
|
3
4
|
|
|
@@ -100,7 +101,7 @@ module Formtastic
|
|
|
100
101
|
|
|
101
102
|
def hidden_field_for_all
|
|
102
103
|
if hidden_fields_for_every?
|
|
103
|
-
''
|
|
104
|
+
+''
|
|
104
105
|
else
|
|
105
106
|
options = {}
|
|
106
107
|
options[:class] = [method.to_s.singularize, 'default'].join('_') if value_as_class?
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module Formtastic
|
|
2
3
|
module Inputs
|
|
3
4
|
|
|
@@ -42,7 +43,7 @@ module Formtastic
|
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
def error_html
|
|
45
|
-
""
|
|
46
|
+
+""
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
def errors?
|
|
@@ -50,7 +51,7 @@ module Formtastic
|
|
|
50
51
|
end
|
|
51
52
|
|
|
52
53
|
def hint_html
|
|
53
|
-
""
|
|
54
|
+
+""
|
|
54
55
|
end
|
|
55
56
|
|
|
56
57
|
def hint?
|
data/lib/formtastic/inputs.rb
CHANGED
data/lib/formtastic/localizer.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module Formtastic
|
|
2
3
|
# This class implements class resolution in a namespace chain. It
|
|
3
4
|
# is used both by Formtastic::Helpers::InputHelper and
|
|
@@ -32,6 +33,10 @@ module Formtastic
|
|
|
32
33
|
defined?(Rails) && ::Rails.application && ::Rails.application.config.respond_to?(:eager_load) && ::Rails.application.config.eager_load
|
|
33
34
|
end
|
|
34
35
|
|
|
36
|
+
def self.finder_method
|
|
37
|
+
@finder_method ||= use_const_defined? ? :find_with_const_defined : :find_by_trying
|
|
38
|
+
end
|
|
39
|
+
|
|
35
40
|
# @param namespaces [Array<Module>]
|
|
36
41
|
def initialize(namespaces)
|
|
37
42
|
@namespaces = namespaces.flatten
|
|
@@ -66,14 +71,8 @@ module Formtastic
|
|
|
66
71
|
|
|
67
72
|
private
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
find_with_const_defined(class_name)
|
|
72
|
-
end
|
|
73
|
-
else
|
|
74
|
-
def finder(class_name) # @private
|
|
75
|
-
find_by_trying(class_name)
|
|
76
|
-
end
|
|
74
|
+
def finder(class_name) # @private
|
|
75
|
+
send(self.class.finder_method, class_name)
|
|
77
76
|
end
|
|
78
77
|
|
|
79
78
|
# Looks up the given class name in the configured namespaces in order,
|
data/lib/formtastic/version.rb
CHANGED
data/lib/formtastic.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
gem 'formtastic', path: '..'
|
|
2
3
|
gem 'bcrypt', '~> 3.1.7'
|
|
3
4
|
gem 'rails-dom-testing', group: :test
|
|
@@ -14,8 +15,6 @@ elsif Rails.version >= '6.1'
|
|
|
14
15
|
gsub_file 'Gemfile', /gem 'rails'.*/, "gem 'rails', '~> #{Rails.version}', github: 'rails/rails', branch: '6-1-stable'"
|
|
15
16
|
elsif Rails.version >= '6.0'
|
|
16
17
|
gsub_file 'Gemfile', /gem 'rails'.*/, "gem 'rails', '~> #{Rails.version}', github: 'rails/rails', branch: '6-0-stable'"
|
|
17
|
-
elsif Rails.version >= '5.2'
|
|
18
|
-
gsub_file 'Gemfile', /gem 'rails'.*/, "gem 'rails', '~> #{Rails.version}', github: 'rails/rails', branch: '5-2-stable'"
|
|
19
18
|
end
|
|
20
19
|
|
|
21
20
|
### Ensure Dummy App's Ruby version matches the current environments Ruby Version
|
|
@@ -40,7 +39,7 @@ end
|
|
|
40
39
|
formtastic = -> do
|
|
41
40
|
generate(:scaffold, 'user name:string password:digest')
|
|
42
41
|
generate('formtastic:install')
|
|
43
|
-
generate('formtastic:form', 'user name password
|
|
42
|
+
generate('formtastic:form', 'user name password --force')
|
|
44
43
|
|
|
45
44
|
rails_command('db:migrate')
|
|
46
45
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
5
|
RSpec.describe 'ButtonAction', 'when submitting' do
|
|
@@ -6,16 +7,16 @@ RSpec.describe 'ButtonAction', 'when submitting' do
|
|
|
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
|
+
|
|
12
13
|
concat(semantic_form_for(@new_post) do |builder|
|
|
13
14
|
concat(builder.action(:submit, :as => :button))
|
|
14
15
|
end)
|
|
15
16
|
end
|
|
16
|
-
|
|
17
|
+
|
|
17
18
|
it 'should render a submit type of button' do
|
|
18
|
-
expect(output_buffer).to have_tag('li.action.button_action button[@type="submit"]')
|
|
19
|
+
expect(output_buffer.to_str).to have_tag('li.action.button_action button[@type="submit"]')
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
end
|
|
@@ -23,41 +24,41 @@ end
|
|
|
23
24
|
RSpec.describe 'ButtonAction', 'when resetting' do
|
|
24
25
|
|
|
25
26
|
include FormtasticSpecHelper
|
|
26
|
-
|
|
27
|
+
|
|
27
28
|
before do
|
|
28
|
-
@output_buffer = ''
|
|
29
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
29
30
|
mock_everything
|
|
30
|
-
|
|
31
|
+
|
|
31
32
|
concat(semantic_form_for(@new_post) do |builder|
|
|
32
33
|
concat(builder.action(:reset, :as => :button))
|
|
33
34
|
end)
|
|
34
35
|
end
|
|
35
|
-
|
|
36
|
+
|
|
36
37
|
it 'should render a reset type of button' do
|
|
37
|
-
expect(output_buffer).to have_tag('li.action.button_action button[@type="reset"]', :text => "Reset Post")
|
|
38
|
+
expect(output_buffer.to_str).to have_tag('li.action.button_action button[@type="reset"]', :text => "Reset Post")
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
it 'should not render a value attribute' do
|
|
41
|
-
expect(output_buffer).not_to have_tag('li.action.button_action button[@value]')
|
|
42
|
+
expect(output_buffer.to_str).not_to have_tag('li.action.button_action button[@value]')
|
|
42
43
|
end
|
|
43
|
-
|
|
44
|
+
|
|
44
45
|
end
|
|
45
46
|
|
|
46
47
|
RSpec.describe 'InputAction', 'when cancelling' do
|
|
47
48
|
|
|
48
49
|
include FormtasticSpecHelper
|
|
49
|
-
|
|
50
|
+
|
|
50
51
|
before do
|
|
51
|
-
@output_buffer = ''
|
|
52
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
52
53
|
mock_everything
|
|
53
54
|
end
|
|
54
|
-
|
|
55
|
+
|
|
55
56
|
it 'should raise an error' do
|
|
56
|
-
expect {
|
|
57
|
+
expect {
|
|
57
58
|
concat(semantic_form_for(@new_post) do |builder|
|
|
58
59
|
concat(builder.action(:cancel, :as => :button))
|
|
59
60
|
end)
|
|
60
61
|
}.to raise_error(Formtastic::UnsupportedMethodForAction)
|
|
61
62
|
end
|
|
62
|
-
|
|
63
|
+
|
|
63
64
|
end
|