formtastic 3.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 +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,95 +1,96 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
|
-
describe 'Formtastic::FormBuilder#inputs' do
|
|
5
|
+
RSpec.describe 'Formtastic::FormBuilder#inputs' 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
|
|
|
13
14
|
describe 'with a block (block forms syntax)' do
|
|
14
|
-
|
|
15
|
+
|
|
15
16
|
describe 'when no options are provided' do
|
|
16
17
|
before do
|
|
17
|
-
output_buffer.
|
|
18
|
+
@output_buffer = ActionView::OutputBuffer.new 'before_builder' # replace the output buffer and with one set to before_builder
|
|
18
19
|
concat(semantic_form_for(@new_post) do |builder|
|
|
19
20
|
@inputs_output = builder.inputs do
|
|
20
21
|
concat('hello')
|
|
21
22
|
end
|
|
22
23
|
end)
|
|
23
24
|
end
|
|
24
|
-
|
|
25
|
+
|
|
25
26
|
it 'should output just the content wrapped in inputs, not the whole template' do
|
|
26
|
-
output_buffer.
|
|
27
|
-
@inputs_output.
|
|
27
|
+
expect(output_buffer.to_str).to match(/before_builder/)
|
|
28
|
+
expect(@inputs_output).not_to match(/before_builder/)
|
|
28
29
|
end
|
|
29
|
-
|
|
30
|
+
|
|
30
31
|
it 'should render a fieldset inside the form, with a class of "inputs"' do
|
|
31
|
-
output_buffer.
|
|
32
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs")
|
|
32
33
|
end
|
|
33
|
-
|
|
34
|
+
|
|
34
35
|
it 'should render an ol inside the fieldset' do
|
|
35
|
-
output_buffer.
|
|
36
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs ol")
|
|
36
37
|
end
|
|
37
|
-
|
|
38
|
+
|
|
38
39
|
it 'should render the contents of the block inside the ol' do
|
|
39
|
-
output_buffer.
|
|
40
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs ol", :text => /hello/)
|
|
40
41
|
end
|
|
41
|
-
|
|
42
|
+
|
|
42
43
|
it 'should not render a legend inside the fieldset' do
|
|
43
|
-
output_buffer.
|
|
44
|
+
expect(output_buffer.to_str).not_to have_tag("form fieldset.inputs legend")
|
|
44
45
|
end
|
|
45
|
-
|
|
46
|
+
|
|
46
47
|
it 'should render a fieldset even if no object is given' do
|
|
47
48
|
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
|
48
49
|
@inputs_output = builder.inputs do
|
|
49
50
|
concat('bye')
|
|
50
51
|
end
|
|
51
52
|
end)
|
|
52
|
-
output_buffer.
|
|
53
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs ol", :text => /bye/)
|
|
53
54
|
end
|
|
54
55
|
end
|
|
55
|
-
|
|
56
|
+
|
|
56
57
|
describe 'when a :for option is provided' do
|
|
57
|
-
|
|
58
|
+
|
|
58
59
|
before do
|
|
59
|
-
@new_post.
|
|
60
|
-
@new_post.
|
|
61
|
-
@new_post.
|
|
60
|
+
allow(@new_post).to receive(:respond_to?).and_return(true, true)
|
|
61
|
+
allow(@new_post).to receive(:respond_to?).with(:empty?).and_return(false)
|
|
62
|
+
allow(@new_post).to receive(:author).and_return(@bob)
|
|
62
63
|
end
|
|
63
|
-
|
|
64
|
+
|
|
64
65
|
it 'should render nested inputs' do
|
|
65
|
-
@bob.
|
|
66
|
-
|
|
66
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
|
67
|
+
|
|
67
68
|
concat(semantic_form_for(@new_post) do |builder|
|
|
68
69
|
inputs = builder.inputs :for => [:author, @bob] do |bob_builder|
|
|
69
70
|
concat(bob_builder.input(:login))
|
|
70
71
|
end
|
|
71
72
|
concat(inputs)
|
|
72
73
|
end)
|
|
73
|
-
output_buffer.
|
|
74
|
-
output_buffer.
|
|
74
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs #post_author_attributes_login")
|
|
75
|
+
expect(output_buffer.to_str).not_to have_tag("form fieldset.inputs #author_login")
|
|
75
76
|
end
|
|
76
|
-
|
|
77
|
+
|
|
77
78
|
it 'should concat rendered nested inputs to the template' do
|
|
78
|
-
@bob.
|
|
79
|
-
|
|
79
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
|
80
|
+
|
|
80
81
|
concat(semantic_form_for(@new_post) do |builder|
|
|
81
82
|
builder.inputs :for => [:author, @bob] do |bob_builder|
|
|
82
83
|
concat(bob_builder.input(:login))
|
|
83
84
|
end
|
|
84
85
|
end)
|
|
85
|
-
|
|
86
|
-
output_buffer.
|
|
87
|
-
output_buffer.
|
|
88
|
-
|
|
86
|
+
|
|
87
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs #post_author_attributes_login")
|
|
88
|
+
expect(output_buffer.to_str).not_to have_tag("form fieldset.inputs #author_login")
|
|
89
|
+
|
|
89
90
|
end
|
|
90
|
-
|
|
91
|
+
|
|
91
92
|
describe "as a symbol representing the association name" do
|
|
92
|
-
|
|
93
|
+
|
|
93
94
|
it 'should nest the inputs with an _attributes suffix on the association name' do
|
|
94
95
|
concat(semantic_form_for(@new_post) do |post|
|
|
95
96
|
inputs = post.inputs :for => :author do |author|
|
|
@@ -97,48 +98,48 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
97
98
|
end
|
|
98
99
|
concat(inputs)
|
|
99
100
|
end)
|
|
100
|
-
output_buffer.
|
|
101
|
+
expect(output_buffer.to_str).to have_tag("form input[@name='post[author_attributes][login]']")
|
|
101
102
|
end
|
|
102
|
-
|
|
103
|
+
|
|
103
104
|
end
|
|
104
|
-
|
|
105
|
+
|
|
105
106
|
describe "as a symbol representing a has_many association name" do
|
|
106
107
|
before do
|
|
107
|
-
@new_post.
|
|
108
|
-
@new_post.
|
|
108
|
+
allow(@new_post).to receive(:authors).and_return([@bob, @fred])
|
|
109
|
+
allow(@new_post).to receive(:authors_attributes=)
|
|
109
110
|
end
|
|
110
|
-
|
|
111
|
+
|
|
111
112
|
it 'should nest the inputs with a fieldset, legend and :name input for each item' do
|
|
112
113
|
concat(semantic_form_for(@new_post) do |post|
|
|
113
114
|
post.inputs :for => :authors, :name => '%i' do |author|
|
|
114
115
|
concat(author.input(:login))
|
|
115
116
|
end
|
|
116
117
|
end)
|
|
117
|
-
|
|
118
|
-
output_buffer.
|
|
119
|
-
output_buffer.
|
|
120
|
-
output_buffer.
|
|
121
|
-
output_buffer.
|
|
122
|
-
output_buffer.
|
|
123
|
-
output_buffer.
|
|
124
|
-
output_buffer.
|
|
118
|
+
|
|
119
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs", :count => 2)
|
|
120
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs legend", :count => 2)
|
|
121
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs legend", :text => "1", :count => 1)
|
|
122
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs legend", :text => "2")
|
|
123
|
+
expect(output_buffer.to_str).to have_tag("form input[@name='post[authors_attributes][0][login]']")
|
|
124
|
+
expect(output_buffer.to_str).to have_tag("form input[@name='post[authors_attributes][1][login]']")
|
|
125
|
+
expect(output_buffer.to_str).not_to have_tag('form fieldset[@name]')
|
|
125
126
|
end
|
|
126
|
-
|
|
127
|
+
|
|
127
128
|
it 'should include an indexed :label input for each item' do
|
|
128
129
|
concat(semantic_form_for(@new_post) do |post|
|
|
129
130
|
post.inputs :for => :authors do |author, index|
|
|
130
131
|
concat(author.input(:login, :label => "#{index}", :required => false))
|
|
131
132
|
end
|
|
132
133
|
end)
|
|
133
|
-
|
|
134
|
-
output_buffer.
|
|
135
|
-
output_buffer.
|
|
136
|
-
output_buffer.
|
|
134
|
+
|
|
135
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs label", :text => "1", :count => 1)
|
|
136
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs label", :text => "2", :count => 1)
|
|
137
|
+
expect(output_buffer.to_str).not_to have_tag('form fieldset legend')
|
|
137
138
|
end
|
|
138
139
|
end
|
|
139
|
-
|
|
140
|
+
|
|
140
141
|
describe 'as an array containing the a symbole for the association name and the associated object' do
|
|
141
|
-
|
|
142
|
+
|
|
142
143
|
it 'should nest the inputs with an _attributes suffix on the association name' do
|
|
143
144
|
concat(semantic_form_for(@new_post) do |post|
|
|
144
145
|
inputs = post.inputs :for => [:author, @new_post.author] do |author|
|
|
@@ -146,13 +147,13 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
146
147
|
end
|
|
147
148
|
concat(inputs)
|
|
148
149
|
end)
|
|
149
|
-
output_buffer.
|
|
150
|
+
expect(output_buffer.to_str).to have_tag("form input[@name='post[author_attributes][login]']")
|
|
150
151
|
end
|
|
151
|
-
|
|
152
|
+
|
|
152
153
|
end
|
|
153
|
-
|
|
154
|
+
|
|
154
155
|
describe 'as an associated object' do
|
|
155
|
-
|
|
156
|
+
|
|
156
157
|
it 'should not nest the inputs with an _attributes suffix' do
|
|
157
158
|
concat(semantic_form_for(@new_post) do |post|
|
|
158
159
|
inputs = post.inputs :for => @new_post.author do |author|
|
|
@@ -160,35 +161,34 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
160
161
|
end
|
|
161
162
|
concat(inputs)
|
|
162
163
|
end)
|
|
163
|
-
output_buffer.
|
|
164
|
+
expect(output_buffer.to_str).to have_tag("form input[@name='post[author][login]']")
|
|
164
165
|
end
|
|
165
|
-
|
|
166
|
+
|
|
166
167
|
end
|
|
167
|
-
|
|
168
|
+
|
|
168
169
|
it 'should raise an error if :for and block with no argument is given' do
|
|
169
170
|
semantic_form_for(@new_post) do |builder|
|
|
170
|
-
|
|
171
|
+
expect {
|
|
171
172
|
builder.inputs(:for => [:author, @bob]) do
|
|
172
173
|
#
|
|
173
174
|
end
|
|
174
|
-
}.
|
|
175
|
-
'but the block does not accept any argument.')
|
|
175
|
+
}.to raise_error(ArgumentError, 'You gave :for option with a block to inputs method, but the block does not accept any argument.')
|
|
176
176
|
end
|
|
177
177
|
end
|
|
178
|
-
|
|
178
|
+
|
|
179
179
|
it 'should pass options down to semantic_fields_for' do
|
|
180
|
-
@bob.
|
|
181
|
-
|
|
180
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
|
181
|
+
|
|
182
182
|
concat(semantic_form_for(@new_post) do |builder|
|
|
183
183
|
inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
|
184
184
|
concat(bob_builder.input(:login))
|
|
185
185
|
end
|
|
186
186
|
concat(inputs)
|
|
187
187
|
end)
|
|
188
|
-
|
|
189
|
-
output_buffer.
|
|
188
|
+
|
|
189
|
+
expect(output_buffer.to_str).to have_tag('form fieldset ol li #post_author_attributes_10_login')
|
|
190
190
|
end
|
|
191
|
-
|
|
191
|
+
|
|
192
192
|
it 'should not add builder as a fieldset attribute tag' do
|
|
193
193
|
concat(semantic_form_for(@new_post) do |builder|
|
|
194
194
|
inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
|
@@ -196,10 +196,10 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
196
196
|
end
|
|
197
197
|
concat(inputs)
|
|
198
198
|
end)
|
|
199
|
-
|
|
200
|
-
output_buffer.
|
|
199
|
+
|
|
200
|
+
expect(output_buffer.to_str).not_to have_tag('fieldset[@builder="Formtastic::Helpers::FormHelper"]')
|
|
201
201
|
end
|
|
202
|
-
|
|
202
|
+
|
|
203
203
|
it 'should send parent_builder as an option to allow child index interpolation for legends' do
|
|
204
204
|
concat(semantic_form_for(@new_post) do |builder|
|
|
205
205
|
builder.instance_variable_set('@nested_child_index', 0)
|
|
@@ -208,10 +208,10 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
208
208
|
end
|
|
209
209
|
concat(inputs)
|
|
210
210
|
end)
|
|
211
|
-
|
|
212
|
-
output_buffer.
|
|
211
|
+
|
|
212
|
+
expect(output_buffer.to_str).to have_tag('fieldset legend', :text => 'Author #1')
|
|
213
213
|
end
|
|
214
|
-
|
|
214
|
+
|
|
215
215
|
it 'should also provide child index interpolation for legends when nested child index is a hash' do
|
|
216
216
|
concat(semantic_form_for(@new_post) do |builder|
|
|
217
217
|
builder.instance_variable_set('@nested_child_index', :author => 10)
|
|
@@ -220,10 +220,10 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
220
220
|
end
|
|
221
221
|
concat(inputs)
|
|
222
222
|
end)
|
|
223
|
-
|
|
224
|
-
output_buffer.
|
|
223
|
+
|
|
224
|
+
expect(output_buffer.to_str).to have_tag('fieldset legend', :text => 'Author #11')
|
|
225
225
|
end
|
|
226
|
-
|
|
226
|
+
|
|
227
227
|
it 'should send parent_builder as an option to allow child index interpolation for labels' do
|
|
228
228
|
concat(semantic_form_for(@new_post) do |builder|
|
|
229
229
|
builder.instance_variable_set('@nested_child_index', 'post[author_attributes]' => 0)
|
|
@@ -232,10 +232,10 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
232
232
|
end
|
|
233
233
|
concat(inputs)
|
|
234
234
|
end)
|
|
235
|
-
|
|
236
|
-
output_buffer.
|
|
235
|
+
|
|
236
|
+
expect(output_buffer.to_str).to have_tag('fieldset label', :text => 'Author #1')
|
|
237
237
|
end
|
|
238
|
-
|
|
238
|
+
|
|
239
239
|
it 'should also provide child index interpolation for labels when nested child index is a hash' do
|
|
240
240
|
concat(semantic_form_for(@new_post) do |builder|
|
|
241
241
|
builder.instance_variable_set('@nested_child_index', 'post[author_attributes]' => 10)
|
|
@@ -244,11 +244,11 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
244
244
|
end
|
|
245
245
|
concat(inputs)
|
|
246
246
|
end)
|
|
247
|
-
|
|
248
|
-
output_buffer.
|
|
247
|
+
|
|
248
|
+
expect(output_buffer.to_str).to have_tag('fieldset label', :text => 'Author #11')
|
|
249
249
|
end
|
|
250
250
|
end
|
|
251
|
-
|
|
251
|
+
|
|
252
252
|
describe 'when a :name or :title option is provided' do
|
|
253
253
|
describe 'and is a string' do
|
|
254
254
|
before do
|
|
@@ -271,16 +271,16 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
271
271
|
concat(inputs)
|
|
272
272
|
end)
|
|
273
273
|
end
|
|
274
|
-
|
|
274
|
+
|
|
275
275
|
# TODO: looks like the block isn't being called for the last assertion here
|
|
276
276
|
it 'should render a fieldset with a legend inside the form' do
|
|
277
|
-
output_buffer.
|
|
278
|
-
output_buffer.
|
|
279
|
-
output_buffer.
|
|
280
|
-
output_buffer.
|
|
277
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@legend_text}$/)
|
|
278
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@legend_text_using_name}$/)
|
|
279
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@legend_text_using_title}$/)
|
|
280
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@nested_forms_legend_text}$/)
|
|
281
281
|
end
|
|
282
282
|
end
|
|
283
|
-
|
|
283
|
+
|
|
284
284
|
describe 'and is a symbol' do
|
|
285
285
|
before do
|
|
286
286
|
@localized_legend_text = "Localized advanced options"
|
|
@@ -308,191 +308,206 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
308
308
|
end)
|
|
309
309
|
end)
|
|
310
310
|
end
|
|
311
|
-
|
|
311
|
+
|
|
312
312
|
# TODO: looks like the block isn't being called for the last assertion here
|
|
313
313
|
it 'should render a fieldset with a localized legend inside the form' do
|
|
314
|
-
output_buffer.
|
|
315
|
-
output_buffer.
|
|
316
|
-
output_buffer.
|
|
317
|
-
output_buffer.
|
|
314
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@localized_legend_text}$/)
|
|
315
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@localized_legend_text_using_name}$/)
|
|
316
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@localized_legend_text_using_title}$/)
|
|
317
|
+
expect(output_buffer.to_str).to have_tag("form fieldset legend", :text => /^#{@localized_nested_forms_legend_text}$/)
|
|
318
318
|
end
|
|
319
319
|
end
|
|
320
320
|
end
|
|
321
|
-
|
|
321
|
+
|
|
322
322
|
describe 'when other options are provided' do
|
|
323
323
|
before do
|
|
324
324
|
@id_option = 'advanced'
|
|
325
325
|
@class_option = 'wide'
|
|
326
|
-
|
|
326
|
+
|
|
327
327
|
concat(semantic_form_for(@new_post) do |builder|
|
|
328
328
|
builder.inputs :id => @id_option, :class => @class_option do
|
|
329
329
|
end
|
|
330
330
|
end)
|
|
331
331
|
end
|
|
332
|
-
|
|
332
|
+
|
|
333
333
|
it 'should pass the options into the fieldset tag as attributes' do
|
|
334
|
-
output_buffer.
|
|
335
|
-
output_buffer.
|
|
334
|
+
expect(output_buffer.to_str).to have_tag("form fieldset##{@id_option}")
|
|
335
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.#{@class_option}")
|
|
336
336
|
end
|
|
337
337
|
end
|
|
338
|
-
|
|
338
|
+
|
|
339
339
|
end
|
|
340
|
-
|
|
340
|
+
|
|
341
341
|
describe 'without a block' do
|
|
342
|
-
|
|
342
|
+
|
|
343
343
|
before do
|
|
344
|
-
::Post.
|
|
344
|
+
allow(::Post).to receive(:reflections).and_return({:author => double('reflection', :options => {}, :macro => :belongs_to),
|
|
345
345
|
:comments => double('reflection', :options => {}, :macro => :has_many) })
|
|
346
|
-
|
|
347
|
-
@new_post.
|
|
348
|
-
@new_post.
|
|
349
|
-
@new_post.
|
|
350
|
-
|
|
351
|
-
@new_post.
|
|
352
|
-
@new_post.
|
|
353
|
-
@new_post.
|
|
354
|
-
@new_post.
|
|
346
|
+
|
|
347
|
+
allow(@new_post).to receive(:title)
|
|
348
|
+
allow(@new_post).to receive(:body)
|
|
349
|
+
allow(@new_post).to receive(:author_id)
|
|
350
|
+
|
|
351
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :string, :limit => 255))
|
|
352
|
+
allow(@new_post).to receive(:column_for_attribute).with(:body).and_return(double('column', :type => :text))
|
|
353
|
+
allow(@new_post).to receive(:column_for_attribute).with(:created_at).and_return(double('column', :type => :datetime))
|
|
354
|
+
allow(@new_post).to receive(:column_for_attribute).with(:author).and_return(nil)
|
|
355
355
|
end
|
|
356
|
-
|
|
356
|
+
|
|
357
357
|
describe 'with no args (quick forms syntax)' do
|
|
358
358
|
before do
|
|
359
359
|
concat(semantic_form_for(@new_post) do |builder|
|
|
360
360
|
concat(builder.inputs)
|
|
361
361
|
end)
|
|
362
362
|
end
|
|
363
|
-
|
|
363
|
+
|
|
364
364
|
it 'should render a form' do
|
|
365
|
-
output_buffer.
|
|
365
|
+
expect(output_buffer.to_str).to have_tag('form')
|
|
366
366
|
end
|
|
367
|
-
|
|
367
|
+
|
|
368
368
|
it 'should render a fieldset inside the form' do
|
|
369
|
-
output_buffer.
|
|
369
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs')
|
|
370
370
|
end
|
|
371
|
-
|
|
371
|
+
|
|
372
372
|
it 'should not render a legend in the fieldset' do
|
|
373
|
-
output_buffer.
|
|
373
|
+
expect(output_buffer.to_str).not_to have_tag('form > fieldset.inputs > legend')
|
|
374
374
|
end
|
|
375
|
-
|
|
375
|
+
|
|
376
376
|
it 'should render an ol in the fieldset' do
|
|
377
|
-
output_buffer.
|
|
377
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol')
|
|
378
378
|
end
|
|
379
|
-
|
|
379
|
+
|
|
380
380
|
it 'should render a list item in the ol for each column and reflection' do
|
|
381
381
|
# Remove the :has_many macro and :created_at column
|
|
382
382
|
count = ::Post.content_columns.size + ::Post.reflections.size - 2
|
|
383
|
-
output_buffer.
|
|
383
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li', :count => count)
|
|
384
384
|
end
|
|
385
|
-
|
|
385
|
+
|
|
386
386
|
it 'should render a string list item for title' do
|
|
387
|
-
output_buffer.
|
|
387
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.string')
|
|
388
388
|
end
|
|
389
|
-
|
|
389
|
+
|
|
390
390
|
it 'should render a text list item for body' do
|
|
391
|
-
output_buffer.
|
|
391
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.text')
|
|
392
392
|
end
|
|
393
|
-
|
|
393
|
+
|
|
394
394
|
it 'should render a select list item for author_id' do
|
|
395
|
-
output_buffer.
|
|
395
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.select', :count => 1)
|
|
396
396
|
end
|
|
397
|
-
|
|
397
|
+
|
|
398
398
|
it 'should not render timestamps inputs by default' do
|
|
399
|
-
output_buffer.
|
|
399
|
+
expect(output_buffer.to_str).not_to have_tag('form > fieldset.inputs > ol > li.datetime')
|
|
400
400
|
end
|
|
401
|
-
|
|
401
|
+
|
|
402
|
+
context "with non-standard foregin keys" do
|
|
403
|
+
before do
|
|
404
|
+
@output_buffer = ActionView::OutputBuffer.new ''
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
it 'should respect foreign key while rendering select' do
|
|
408
|
+
concat(semantic_form_for(LegacyPost.new, {:url => '/'}) do |builder|
|
|
409
|
+
concat(builder.inputs)
|
|
410
|
+
end)
|
|
411
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.select select#legacy_post_post_author', :count => 1)
|
|
412
|
+
expect(output_buffer.to_str).not_to have_tag('input#legacy_post_post_author')
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
end
|
|
416
|
+
|
|
402
417
|
context "with a polymorphic association" do
|
|
403
|
-
|
|
404
|
-
before do
|
|
405
|
-
@new_post.
|
|
406
|
-
@new_post.class.
|
|
418
|
+
|
|
419
|
+
before do
|
|
420
|
+
allow(@new_post).to receive(:commentable)
|
|
421
|
+
allow(@new_post.class).to receive(:reflections).and_return({
|
|
407
422
|
:commentable => double('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
|
|
408
423
|
})
|
|
409
|
-
@new_post.
|
|
424
|
+
allow(@new_post).to receive(:column_for_attribute).with(:commentable).and_return(
|
|
410
425
|
double('column', :type => :integer)
|
|
411
426
|
)
|
|
412
427
|
end
|
|
413
|
-
|
|
428
|
+
|
|
414
429
|
it 'should not render an input for the polymorphic association (the collection class cannot be guessed)' do
|
|
415
430
|
concat(semantic_form_for(@new_post) do |builder|
|
|
416
431
|
concat(builder.inputs)
|
|
417
432
|
end)
|
|
418
|
-
output_buffer.
|
|
433
|
+
expect(output_buffer.to_str).not_to have_tag('li#post_commentable_input')
|
|
419
434
|
end
|
|
420
|
-
|
|
435
|
+
|
|
421
436
|
end
|
|
422
437
|
end
|
|
423
|
-
|
|
438
|
+
|
|
424
439
|
describe 'with column names as args (short hand forms syntax)' do
|
|
425
440
|
describe 'and an object is given' do
|
|
426
441
|
it 'should render a form with a fieldset containing two list items' do
|
|
427
442
|
concat(semantic_form_for(@new_post) do |builder|
|
|
428
443
|
concat(builder.inputs(:title, :body))
|
|
429
444
|
end)
|
|
430
|
-
|
|
431
|
-
output_buffer.
|
|
432
|
-
output_buffer.
|
|
433
|
-
output_buffer.
|
|
445
|
+
|
|
446
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li', :count => 2)
|
|
447
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.string')
|
|
448
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.text')
|
|
434
449
|
end
|
|
435
450
|
end
|
|
436
|
-
|
|
451
|
+
|
|
437
452
|
describe 'and no object is given' do
|
|
438
453
|
it 'should render a form with a fieldset containing two list items' do
|
|
439
454
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
440
455
|
concat(builder.inputs(:title, :body))
|
|
441
456
|
end)
|
|
442
|
-
|
|
443
|
-
output_buffer.
|
|
457
|
+
|
|
458
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.string', :count => 2)
|
|
444
459
|
end
|
|
445
460
|
end
|
|
446
|
-
|
|
461
|
+
|
|
447
462
|
context "with a polymorphic association" do
|
|
448
|
-
|
|
463
|
+
|
|
449
464
|
it 'should raise an error for polymorphic associations (the collection class cannot be guessed)' do
|
|
450
|
-
@new_post.
|
|
451
|
-
@new_post.class.
|
|
465
|
+
allow(@new_post).to receive(:commentable)
|
|
466
|
+
allow(@new_post.class).to receive(:reflections).and_return({
|
|
452
467
|
:commentable => double('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
|
|
453
468
|
})
|
|
454
|
-
@new_post.
|
|
469
|
+
allow(@new_post).to receive(:column_for_attribute).with(:commentable).and_return(
|
|
455
470
|
double('column', :type => :integer)
|
|
456
471
|
)
|
|
457
|
-
@new_post.class.
|
|
472
|
+
allow(@new_post.class).to receive(:reflect_on_association).with(:commentable).and_return(
|
|
458
473
|
double('reflection', :macro => :belongs_to, :options => { :polymorphic => true })
|
|
459
474
|
)
|
|
460
|
-
|
|
461
|
-
expect {
|
|
475
|
+
|
|
476
|
+
expect {
|
|
462
477
|
concat(semantic_form_for(@new_post) do |builder|
|
|
463
478
|
concat(builder.inputs :commentable)
|
|
464
479
|
end)
|
|
465
480
|
}.to raise_error(Formtastic::PolymorphicInputWithoutCollectionError)
|
|
466
481
|
end
|
|
467
|
-
|
|
482
|
+
|
|
468
483
|
end
|
|
469
|
-
|
|
484
|
+
|
|
470
485
|
end
|
|
471
|
-
|
|
486
|
+
|
|
472
487
|
describe 'when a :for option is provided' do
|
|
473
488
|
describe 'and an object is given' do
|
|
474
489
|
it 'should render nested inputs' do
|
|
475
|
-
@bob.
|
|
490
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
|
476
491
|
concat(semantic_form_for(@new_post) do |builder|
|
|
477
492
|
concat(builder.inputs(:login, :for => @bob))
|
|
478
493
|
end)
|
|
479
|
-
|
|
480
|
-
output_buffer.
|
|
481
|
-
output_buffer.
|
|
494
|
+
|
|
495
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs #post_author_login")
|
|
496
|
+
expect(output_buffer.to_str).not_to have_tag("form fieldset.inputs #author_login")
|
|
482
497
|
end
|
|
483
498
|
end
|
|
484
|
-
|
|
499
|
+
|
|
485
500
|
describe 'and no object is given' do
|
|
486
501
|
it 'should render nested inputs' do
|
|
487
502
|
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
|
488
503
|
concat(builder.inputs(:login, :for => @bob))
|
|
489
504
|
end)
|
|
490
|
-
output_buffer.
|
|
491
|
-
output_buffer.
|
|
505
|
+
expect(output_buffer.to_str).to have_tag("form fieldset.inputs #project_author_login")
|
|
506
|
+
expect(output_buffer.to_str).not_to have_tag("form fieldset.inputs #project_login")
|
|
492
507
|
end
|
|
493
508
|
end
|
|
494
509
|
end
|
|
495
|
-
|
|
510
|
+
|
|
496
511
|
describe 'with column names and an options hash as args' do
|
|
497
512
|
before do
|
|
498
513
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -502,18 +517,18 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
502
517
|
concat(builder.inputs(@legend_text_using_arg, :title, :body, :id => "my-id-2"))
|
|
503
518
|
end)
|
|
504
519
|
end
|
|
505
|
-
|
|
520
|
+
|
|
506
521
|
it 'should render a form with a fieldset containing two list items' do
|
|
507
|
-
output_buffer.
|
|
522
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li', :count => 4)
|
|
508
523
|
end
|
|
509
|
-
|
|
524
|
+
|
|
510
525
|
it 'should pass the options down to the fieldset' do
|
|
511
|
-
output_buffer.
|
|
526
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset#my-id.inputs')
|
|
512
527
|
end
|
|
513
|
-
|
|
528
|
+
|
|
514
529
|
it 'should use the special :name option as a text for the legend tag' do
|
|
515
|
-
output_buffer.
|
|
516
|
-
output_buffer.
|
|
530
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset#my-id.inputs > legend', :text => /^#{@legend_text_using_option}$/)
|
|
531
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset#my-id-2.inputs > legend', :text => /^#{@legend_text_using_arg}$/)
|
|
517
532
|
end
|
|
518
533
|
end
|
|
519
534
|
|
|
@@ -524,9 +539,9 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
524
539
|
concat(builder.inputs :except => :body)
|
|
525
540
|
end)
|
|
526
541
|
|
|
527
|
-
output_buffer.
|
|
528
|
-
output_buffer.
|
|
529
|
-
output_buffer.
|
|
542
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li', :count => 2)
|
|
543
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.string')
|
|
544
|
+
expect(output_buffer.to_str).not_to have_tag('form > fieldset.inputs > ol > li.text')
|
|
530
545
|
end
|
|
531
546
|
|
|
532
547
|
it 'should render a form with a fieldset containing only text item' do
|
|
@@ -534,9 +549,9 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
534
549
|
concat(builder.inputs :except => :title)
|
|
535
550
|
end)
|
|
536
551
|
|
|
537
|
-
output_buffer.
|
|
538
|
-
output_buffer.
|
|
539
|
-
output_buffer.
|
|
552
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li', :count => 2)
|
|
553
|
+
expect(output_buffer.to_str).not_to have_tag('form > fieldset.inputs > ol > li.string')
|
|
554
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.text')
|
|
540
555
|
end
|
|
541
556
|
end
|
|
542
557
|
|
|
@@ -546,24 +561,24 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
546
561
|
concat(builder.inputs(:title, :body))
|
|
547
562
|
end)
|
|
548
563
|
|
|
549
|
-
output_buffer.
|
|
564
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li.string', :count => 2)
|
|
550
565
|
end
|
|
551
566
|
end
|
|
552
567
|
end
|
|
553
568
|
end
|
|
554
|
-
|
|
569
|
+
|
|
555
570
|
describe 'nesting' do
|
|
556
|
-
|
|
571
|
+
|
|
557
572
|
context "when not nested" do
|
|
558
573
|
it "should not wrap the inputs in an li block" do
|
|
559
574
|
concat(semantic_form_for(@new_post) do |builder|
|
|
560
575
|
concat(builder.inputs do
|
|
561
576
|
end)
|
|
562
577
|
end)
|
|
563
|
-
output_buffer.
|
|
578
|
+
expect(output_buffer.to_str).not_to have_tag('form > li')
|
|
564
579
|
end
|
|
565
580
|
end
|
|
566
|
-
|
|
581
|
+
|
|
567
582
|
context "when nested (with block)" do
|
|
568
583
|
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
|
569
584
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -572,10 +587,10 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
572
587
|
end)
|
|
573
588
|
end)
|
|
574
589
|
end)
|
|
575
|
-
output_buffer.
|
|
590
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
|
576
591
|
end
|
|
577
592
|
end
|
|
578
|
-
|
|
593
|
+
|
|
579
594
|
context "when nested (with block and :for)" do
|
|
580
595
|
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
|
581
596
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -584,10 +599,10 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
584
599
|
end)
|
|
585
600
|
end)
|
|
586
601
|
end)
|
|
587
|
-
output_buffer.
|
|
602
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
|
588
603
|
end
|
|
589
604
|
end
|
|
590
|
-
|
|
605
|
+
|
|
591
606
|
context "when nested (without block)" do
|
|
592
607
|
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
|
593
608
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -595,10 +610,10 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
595
610
|
concat(builder.inputs(:title))
|
|
596
611
|
end)
|
|
597
612
|
end)
|
|
598
|
-
output_buffer.
|
|
613
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
|
599
614
|
end
|
|
600
615
|
end
|
|
601
|
-
|
|
616
|
+
|
|
602
617
|
context "when nested (without block, with :for)" do
|
|
603
618
|
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
|
604
619
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -606,10 +621,10 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
606
621
|
concat(builder.inputs(:name, :for => :author))
|
|
607
622
|
end)
|
|
608
623
|
end)
|
|
609
|
-
output_buffer.
|
|
624
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
|
610
625
|
end
|
|
611
626
|
end
|
|
612
|
-
|
|
627
|
+
|
|
613
628
|
context "when double nested" do
|
|
614
629
|
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
|
615
630
|
concat(semantic_form_for(@new_post) do |builder|
|
|
@@ -620,7 +635,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
620
635
|
end)
|
|
621
636
|
end)
|
|
622
637
|
end)
|
|
623
|
-
output_buffer.
|
|
638
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
|
624
639
|
end
|
|
625
640
|
end
|
|
626
641
|
|
|
@@ -634,10 +649,10 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
634
649
|
end)
|
|
635
650
|
end)
|
|
636
651
|
end)
|
|
637
|
-
output_buffer.
|
|
652
|
+
expect(output_buffer.to_str).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol', :count => 2)
|
|
638
653
|
end
|
|
639
654
|
end
|
|
640
|
-
|
|
655
|
+
|
|
641
656
|
end
|
|
642
657
|
|
|
643
658
|
describe 'when using MongoMapper associations ' do
|
|
@@ -647,7 +662,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
|
647
662
|
end
|
|
648
663
|
end
|
|
649
664
|
it "should throw PolymorphicInputWithoutCollectionError on sub_posts" do
|
|
650
|
-
::MongoPost.
|
|
665
|
+
expect(::MongoPost).to receive(:associations).at_least(3).times
|
|
651
666
|
expect { generate_form }.to raise_error(Formtastic::PolymorphicInputWithoutCollectionError)
|
|
652
667
|
end
|
|
653
668
|
end
|