formtastic 3.1.3 → 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 +7 -0
- 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} +183 -167
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +20 -1
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +12 -16
- 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 +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 +7 -3
- data/lib/formtastic/deprecation.rb +2 -38
- data/lib/formtastic/engine.rb +4 -1
- data/lib/formtastic/form_builder.rb +12 -24
- data/lib/formtastic/helpers/action_helper.rb +2 -48
- 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 +14 -9
- data/lib/formtastic/helpers/file_column_detection.rb +1 -0
- data/lib/formtastic/helpers/form_helper.rb +2 -1
- data/lib/formtastic/helpers/input_helper.rb +20 -76
- data/lib/formtastic/helpers/inputs_helper.rb +29 -23
- data/lib/formtastic/helpers/reflection.rb +1 -0
- data/lib/formtastic/helpers.rb +2 -2
- data/lib/formtastic/html_attributes.rb +1 -0
- data/lib/formtastic/i18n.rb +2 -1
- 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 +3 -2
- data/lib/formtastic/inputs/base/collections.rb +46 -10
- 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 +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 +9 -7
- 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 +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 +15 -6
- 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 +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 +21 -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 +30 -1
- 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 -29
- data/lib/formtastic/localized_string.rb +1 -0
- data/lib/formtastic/localizer.rb +21 -22
- data/lib/formtastic/namespaced_class_finder.rb +8 -9
- data/lib/formtastic/version.rb +2 -1
- data/lib/formtastic.rb +10 -11
- data/lib/generators/formtastic/form/form_generator.rb +2 -1
- data/lib/generators/formtastic/input/input_generator.rb +47 -0
- data/lib/generators/formtastic/install/install_generator.rb +1 -0
- data/lib/generators/templates/formtastic.rb +15 -13
- 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 +2 -1
- 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 +329 -10
- data/spec/helpers/actions_helper_spec.rb +43 -42
- data/spec/helpers/form_helper_spec.rb +45 -38
- data/spec/helpers/input_helper_spec.rb +976 -2
- 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 +2 -1
- 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 +169 -121
- 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 +3 -2
- 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 +26 -25
- 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 +18 -6
- data/spec/schema.rb +22 -0
- data/spec/spec_helper.rb +172 -260
- data/spec/support/custom_macros.rb +74 -76
- data/spec/support/deprecation.rb +2 -1
- data/spec/support/shared_examples.rb +2 -1233
- data/spec/support/specialized_class_finder_shared_example.rb +1 -0
- data/spec/support/test_environment.rb +24 -9
- metadata +78 -170
- data/.travis.yml +0 -29
- data/Appraisals +0 -29
- data/CHANGELOG +0 -39
- data/DEPRECATIONS +0 -49
- 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.2.gemfile +0 -7
- data/gemfiles/rails_4.gemfile +0 -7
- data/gemfiles/rails_edge.gemfile +0 -10
- data/lib/formtastic/util.rb +0 -57
- data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
- data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
- data/spec/support/deferred_garbage_collection.rb +0 -21
- data/spec/util_spec.rb +0 -66
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'Formtastic::FormBuilder#actions' do
|
|
5
|
+
RSpec.describe 'Formtastic::FormBuilder#actions' 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
|
|
|
@@ -21,123 +22,123 @@ describe 'Formtastic::FormBuilder#actions' do
|
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
it 'should render a fieldset inside the form, with a class of "actions"' do
|
|
24
|
-
output_buffer.
|
|
25
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.actions")
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
it 'should render an ol inside the fieldset' do
|
|
28
|
-
output_buffer.
|
|
29
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.actions ol")
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
it 'should render the contents of the block inside the ol' do
|
|
32
|
-
output_buffer.
|
|
33
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.actions ol", :text => /hello/)
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
it 'should not render a legend inside the fieldset' do
|
|
36
|
-
output_buffer.
|
|
37
|
+
expect(output_buffer.to_str).not_to have_tag("form fieldset.actions legend")
|
|
37
38
|
end
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
describe 'when a :name option is provided' do
|
|
41
42
|
before do
|
|
42
43
|
@legend_text = "Advanced options"
|
|
43
|
-
|
|
44
|
+
|
|
44
45
|
concat(semantic_form_for(@new_post) do |builder|
|
|
45
46
|
builder.actions :name => @legend_text do
|
|
46
47
|
end
|
|
47
48
|
end)
|
|
48
49
|
end
|
|
49
50
|
it 'should render a fieldset inside the form' do
|
|
50
|
-
output_buffer.
|
|
51
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.actions legend", :text => /#{@legend_text}/)
|
|
51
52
|
end
|
|
52
53
|
end
|
|
53
|
-
|
|
54
|
+
|
|
54
55
|
describe 'when other options are provided' do
|
|
55
56
|
before do
|
|
56
57
|
@id_option = 'advanced'
|
|
57
58
|
@class_option = 'wide'
|
|
58
|
-
|
|
59
|
+
|
|
59
60
|
concat(semantic_form_for(@new_post) do |builder|
|
|
60
61
|
builder.actions :id => @id_option, :class => @class_option do
|
|
61
62
|
end
|
|
62
63
|
end)
|
|
63
64
|
end
|
|
64
65
|
it 'should pass the options into the fieldset tag as attributes' do
|
|
65
|
-
output_buffer.
|
|
66
|
-
output_buffer.
|
|
66
|
+
expect(output_buffer.to_str).to have_tag("form fieldset##{@id_option}")
|
|
67
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.#{@class_option}")
|
|
67
68
|
end
|
|
68
69
|
end
|
|
69
|
-
|
|
70
|
+
|
|
70
71
|
end
|
|
71
72
|
|
|
72
73
|
describe 'without a block' do
|
|
73
|
-
|
|
74
|
+
|
|
74
75
|
describe 'with no args (default buttons)' do
|
|
75
|
-
|
|
76
|
+
|
|
76
77
|
before do
|
|
77
78
|
concat(semantic_form_for(@new_post) do |builder|
|
|
78
79
|
concat(builder.actions)
|
|
79
80
|
end)
|
|
80
81
|
end
|
|
81
|
-
|
|
82
|
+
|
|
82
83
|
it 'should render a form' do
|
|
83
|
-
output_buffer.
|
|
84
|
+
expect(output_buffer.to_str).to have_tag('form')
|
|
84
85
|
end
|
|
85
|
-
|
|
86
|
+
|
|
86
87
|
it 'should render an actions fieldset inside the form' do
|
|
87
|
-
output_buffer.
|
|
88
|
+
expect(output_buffer.to_str).to have_tag('form fieldset.actions')
|
|
88
89
|
end
|
|
89
|
-
|
|
90
|
+
|
|
90
91
|
it 'should not render a legend in the fieldset' do
|
|
91
|
-
output_buffer.
|
|
92
|
+
expect(output_buffer.to_str).not_to have_tag('form fieldset.actions legend')
|
|
92
93
|
end
|
|
93
|
-
|
|
94
|
+
|
|
94
95
|
it 'should render an ol in the fieldset' do
|
|
95
|
-
output_buffer.
|
|
96
|
+
expect(output_buffer.to_str).to have_tag('form fieldset.actions ol')
|
|
96
97
|
end
|
|
97
|
-
|
|
98
|
+
|
|
98
99
|
it 'should render a list item in the ol for each default action' do
|
|
99
|
-
output_buffer.
|
|
100
|
+
expect(output_buffer.to_str).to have_tag('form fieldset.actions ol li.action.input_action', :count => 1)
|
|
100
101
|
end
|
|
101
|
-
|
|
102
|
+
|
|
102
103
|
end
|
|
103
|
-
|
|
104
|
+
|
|
104
105
|
describe 'with button names as args' do
|
|
105
|
-
|
|
106
|
+
|
|
106
107
|
before do
|
|
107
108
|
concat(semantic_form_for(@new_post) do |builder|
|
|
108
109
|
concat(builder.actions(:submit, :cancel, :reset))
|
|
109
110
|
end)
|
|
110
111
|
end
|
|
111
|
-
|
|
112
|
+
|
|
112
113
|
it 'should render a form with a fieldset containing a list item for each button arg' do
|
|
113
|
-
output_buffer.
|
|
114
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.actions > ol > li.action', :count => 3)
|
|
114
115
|
end
|
|
115
|
-
|
|
116
|
+
|
|
116
117
|
end
|
|
117
|
-
|
|
118
|
+
|
|
118
119
|
describe 'with button names as args and an options hash' do
|
|
119
|
-
|
|
120
|
+
|
|
120
121
|
before do
|
|
121
122
|
concat(semantic_form_for(@new_post) do |builder|
|
|
122
123
|
concat(builder.actions(:submit, :cancel, :reset, :name => "Now click a button", :id => "my-id"))
|
|
123
124
|
end)
|
|
124
125
|
end
|
|
125
|
-
|
|
126
|
+
|
|
126
127
|
it 'should render a form with a fieldset containing a list item for each button arg' do
|
|
127
|
-
output_buffer.
|
|
128
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.actions > ol > li.action', :count => 3)
|
|
128
129
|
end
|
|
129
|
-
|
|
130
|
+
|
|
130
131
|
it 'should pass the options down to the fieldset' do
|
|
131
|
-
output_buffer.
|
|
132
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset#my-id.actions')
|
|
132
133
|
end
|
|
133
|
-
|
|
134
|
+
|
|
134
135
|
it 'should use the special :name option as a text for the legend tag' do
|
|
135
|
-
output_buffer.
|
|
136
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset#my-id.actions > legend', :text => /Now click a button/)
|
|
136
137
|
end
|
|
137
|
-
|
|
138
|
+
|
|
138
139
|
end
|
|
139
|
-
|
|
140
|
+
|
|
140
141
|
end
|
|
141
|
-
|
|
142
|
+
|
|
142
143
|
end
|
|
143
144
|
|
|
@@ -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
|
|
@@ -209,7 +216,7 @@ describe 'FormHelper' do
|
|
|
209
216
|
describe '#semantic_fields_for' do
|
|
210
217
|
it 'yields an instance of Formtastic::FormBuilder' do
|
|
211
218
|
semantic_fields_for(@new_post) do |builder|
|
|
212
|
-
builder.class.
|
|
219
|
+
expect(builder.class).to be(Formtastic::FormBuilder)
|
|
213
220
|
end
|
|
214
221
|
end
|
|
215
222
|
end
|