formtastic 2.0.2 → 2.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/Appraisals +11 -0
- data/CHANGELOG +2 -2
- data/Gemfile +0 -2
- data/README.textile +183 -151
- data/Rakefile +9 -5
- data/app/assets/stylesheets/formtastic.css +16 -3
- data/formtastic.gemspec +6 -2
- data/gemfiles/rails-3.0.gemfile +7 -0
- data/gemfiles/rails-3.1.gemfile +7 -0
- data/gemfiles/rails-3.2.gemfile +7 -0
- data/lib/formtastic.rb +10 -2
- data/lib/formtastic/actions.rb +11 -0
- data/lib/formtastic/actions/base.rb +156 -0
- data/lib/formtastic/actions/button_action.rb +72 -0
- data/lib/formtastic/actions/buttonish.rb +17 -0
- data/lib/formtastic/actions/input_action.rb +68 -0
- data/lib/formtastic/actions/link_action.rb +87 -0
- data/lib/formtastic/engine.rb +5 -1
- data/lib/formtastic/form_builder.rb +3 -0
- data/lib/formtastic/helpers.rb +2 -1
- data/lib/formtastic/helpers/action_helper.rb +109 -0
- data/lib/formtastic/helpers/actions_helper.rb +168 -0
- data/lib/formtastic/helpers/buttons_helper.rb +22 -9
- data/lib/formtastic/helpers/errors_helper.rb +0 -54
- data/lib/formtastic/helpers/fieldset_wrapper.rb +10 -5
- data/lib/formtastic/helpers/form_helper.rb +2 -2
- data/lib/formtastic/helpers/input_helper.rb +1 -10
- data/lib/formtastic/helpers/inputs_helper.rb +6 -3
- data/lib/formtastic/i18n.rb +3 -2
- data/lib/formtastic/inputs/base.rb +11 -3
- data/lib/formtastic/inputs/base/choices.rb +6 -1
- data/lib/formtastic/inputs/base/collections.rb +36 -13
- data/lib/formtastic/inputs/base/grouped_collections.rb +1 -1
- data/lib/formtastic/inputs/base/numeric.rb +50 -0
- data/lib/formtastic/inputs/base/options.rb +1 -1
- data/lib/formtastic/inputs/base/placeholder.rb +17 -0
- data/lib/formtastic/inputs/base/stringish.rb +2 -7
- data/lib/formtastic/inputs/base/timeish.rb +21 -5
- data/lib/formtastic/inputs/base/validations.rb +1 -1
- data/lib/formtastic/inputs/base/wrapping.rb +10 -3
- data/lib/formtastic/inputs/boolean_input.rb +10 -2
- data/lib/formtastic/inputs/check_boxes_input.rb +18 -9
- data/lib/formtastic/inputs/country_input.rb +2 -2
- data/lib/formtastic/inputs/date_input.rb +19 -1
- data/lib/formtastic/inputs/datetime_input.rb +1 -1
- data/lib/formtastic/inputs/email_input.rb +2 -1
- data/lib/formtastic/inputs/file_input.rb +1 -1
- data/lib/formtastic/inputs/hidden_input.rb +1 -1
- data/lib/formtastic/inputs/number_input.rb +6 -36
- data/lib/formtastic/inputs/password_input.rb +2 -1
- data/lib/formtastic/inputs/phone_input.rb +3 -2
- data/lib/formtastic/inputs/radio_input.rb +1 -1
- data/lib/formtastic/inputs/range_input.rb +8 -32
- data/lib/formtastic/inputs/search_input.rb +2 -1
- data/lib/formtastic/inputs/select_input.rb +56 -28
- data/lib/formtastic/inputs/string_input.rb +3 -1
- data/lib/formtastic/inputs/text_input.rb +5 -4
- data/lib/formtastic/inputs/time_input.rb +4 -8
- data/lib/formtastic/inputs/time_zone_input.rb +1 -1
- data/lib/formtastic/inputs/url_input.rb +2 -1
- data/lib/formtastic/localized_string.rb +6 -94
- data/lib/formtastic/localizer.rb +110 -0
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/formtastic/form/form_generator.rb +105 -0
- data/lib/generators/templates/_form.html.erb +2 -2
- data/lib/generators/templates/_form.html.haml +4 -4
- data/lib/generators/templates/_form.html.slim +2 -2
- data/lib/generators/templates/formtastic.rb +4 -0
- data/lib/locale/en.yml +2 -0
- data/sample/basic_inputs.html +22 -0
- data/spec/actions/button_action_spec.rb +63 -0
- data/spec/actions/generic_action_spec.rb +484 -0
- data/spec/actions/input_action_spec.rb +59 -0
- data/spec/actions/link_action_spec.rb +92 -0
- data/spec/builder/semantic_fields_for_spec.rb +14 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +118 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +47 -0
- data/spec/helpers/action_helper_spec.rb +365 -0
- data/spec/helpers/actions_helper_spec.rb +143 -0
- data/spec/helpers/buttons_helper_spec.rb +39 -23
- data/spec/helpers/commit_button_helper_spec.rb +153 -93
- data/spec/helpers/inputs_helper_spec.rb +14 -0
- data/spec/i18n_spec.rb +11 -0
- data/spec/inputs/boolean_input_spec.rb +31 -2
- data/spec/inputs/check_boxes_input_spec.rb +29 -1
- data/spec/inputs/date_input_spec.rb +95 -0
- data/spec/inputs/datetime_input_spec.rb +49 -0
- data/spec/inputs/email_input_spec.rb +28 -0
- data/spec/inputs/file_input_spec.rb +28 -0
- data/spec/inputs/hidden_input_spec.rb +28 -0
- data/spec/inputs/include_blank_spec.rb +53 -45
- data/spec/inputs/number_input_spec.rb +34 -4
- data/spec/inputs/password_input_spec.rb +28 -0
- data/spec/inputs/phone_input_spec.rb +28 -0
- data/spec/inputs/placeholder_spec.rb +10 -10
- data/spec/inputs/radio_input_spec.rb +51 -6
- data/spec/inputs/range_input_spec.rb +30 -2
- data/spec/inputs/search_input_spec.rb +27 -0
- data/spec/inputs/select_input_spec.rb +52 -6
- data/spec/inputs/string_input_spec.rb +28 -0
- data/spec/inputs/text_input_spec.rb +27 -0
- data/spec/inputs/time_input_spec.rb +67 -1
- data/spec/inputs/time_zone_input_spec.rb +28 -0
- data/spec/inputs/url_input_spec.rb +28 -0
- data/spec/inputs/with_options_spec.rb +43 -0
- data/spec/spec_helper.rb +22 -6
- data/spec/support/custom_macros.rb +6 -134
- data/spec/support/test_environment.rb +0 -1
- metadata +104 -17
- data/lib/formtastic/helpers/semantic_form_helper.rb +0 -11
- data/lib/formtastic/inputs/numeric_input.rb +0 -21
- data/lib/formtastic/railtie.rb +0 -12
- data/lib/formtastic/semantic_form_builder.rb +0 -11
- data/spec/builder/errors_spec.rb +0 -203
- data/spec/inputs/numeric_input_spec.rb +0 -41
@@ -556,6 +556,20 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
556
556
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
557
557
|
end
|
558
558
|
end
|
559
|
+
|
560
|
+
context "when several are nested" do
|
561
|
+
it "should wrap each of the nested inputs in an li block to maintain HTML validity" do
|
562
|
+
concat(semantic_form_for(@new_post) do |builder|
|
563
|
+
concat(builder.inputs do
|
564
|
+
concat(builder.inputs do
|
565
|
+
end)
|
566
|
+
concat(builder.inputs do
|
567
|
+
end)
|
568
|
+
end)
|
569
|
+
end)
|
570
|
+
output_buffer.should have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol', :count => 2)
|
571
|
+
end
|
572
|
+
end
|
559
573
|
|
560
574
|
end
|
561
575
|
|
data/spec/i18n_spec.rb
CHANGED
@@ -160,6 +160,17 @@ describe 'Formtastic::I18n' do
|
|
160
160
|
output_buffer.should have_tag("form label", /Hello author name!/)
|
161
161
|
end
|
162
162
|
end
|
163
|
+
|
164
|
+
it 'should be able to translate nested objects with nested object translations' do
|
165
|
+
with_config :i18n_lookups_by_default, true do
|
166
|
+
concat(semantic_form_for(@new_post) do |builder|
|
167
|
+
builder.semantic_fields_for(:project) do |f|
|
168
|
+
concat(f.input(:title))
|
169
|
+
end
|
170
|
+
end)
|
171
|
+
output_buffer.should have_tag("form label", /Hello project!/)
|
172
|
+
end
|
173
|
+
end
|
163
174
|
|
164
175
|
it 'should be able to translate nested forms with top level translations' do
|
165
176
|
with_config :i18n_lookups_by_default, true do
|
@@ -21,8 +21,6 @@ describe 'boolean input' do
|
|
21
21
|
|
22
22
|
it 'should generate a label containing the input' do
|
23
23
|
output_buffer.should_not have_tag('label.label')
|
24
|
-
|
25
|
-
|
26
24
|
output_buffer.should have_tag('form li label', :count => 1)
|
27
25
|
output_buffer.should have_tag('form li label[@for="post_allow_comments"]')
|
28
26
|
output_buffer.should have_tag('form li label', /Allow comments/)
|
@@ -186,5 +184,36 @@ describe 'boolean input' do
|
|
186
184
|
it_should_have_an_inline_label_for("context2_post_allow_comments")
|
187
185
|
|
188
186
|
end
|
187
|
+
|
188
|
+
describe "when index is provided" do
|
189
|
+
|
190
|
+
before do
|
191
|
+
@output_buffer = ''
|
192
|
+
mock_everything
|
193
|
+
|
194
|
+
concat(semantic_form_for(@new_post) do |builder|
|
195
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
196
|
+
concat(author.input(:name, :as => :boolean))
|
197
|
+
end)
|
198
|
+
end)
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should index the id of the wrapper' do
|
202
|
+
output_buffer.should have_tag("li#post_author_attributes_3_name_input")
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should index the id of the input tag' do
|
206
|
+
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'should index the name of the hidden input' do
|
210
|
+
output_buffer.should have_tag("input[@type='hidden'][@name='post[author_attributes][3][name]']")
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'should index the name of the checkbox input' do
|
214
|
+
output_buffer.should have_tag("input[@type='checkbox'][@name='post[author_attributes][3][name]']")
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
189
218
|
|
190
219
|
end
|
@@ -348,7 +348,7 @@ describe 'check_boxes input' do
|
|
348
348
|
item.should_not_receive(:id)
|
349
349
|
item.stub!(:custom_value).and_return('custom_value')
|
350
350
|
item.should_receive(:custom_value).exactly(3).times
|
351
|
-
@new_post.author.should_receive(:custom_value).exactly(
|
351
|
+
@new_post.author.should_receive(:custom_value).exactly(1).times
|
352
352
|
concat(semantic_form_for(@new_post) do |builder|
|
353
353
|
concat(builder.input(:author, :as => :check_boxes, :member_value => :custom_value, :collection => [item, item, item]))
|
354
354
|
end)
|
@@ -392,6 +392,34 @@ describe 'check_boxes input' do
|
|
392
392
|
it_should_have_input_with_id('context2_author_post_ids_19')
|
393
393
|
it_should_have_input_wrapper_with_id("context2_author_posts_input")
|
394
394
|
end
|
395
|
+
|
396
|
+
describe "when index is provided" do
|
397
|
+
|
398
|
+
before do
|
399
|
+
@output_buffer = ''
|
400
|
+
mock_everything
|
401
|
+
|
402
|
+
concat(semantic_form_for(@fred) do |builder|
|
403
|
+
concat(builder.fields_for(@fred.posts.first, :index => 3) do |author|
|
404
|
+
concat(author.input(:authors, :as => :check_boxes))
|
405
|
+
end)
|
406
|
+
end)
|
407
|
+
end
|
408
|
+
|
409
|
+
it 'should index the id of the wrapper' do
|
410
|
+
output_buffer.should have_tag("li#author_post_3_authors_input")
|
411
|
+
end
|
412
|
+
|
413
|
+
it 'should index the id of the input tag' do
|
414
|
+
output_buffer.should have_tag("input#author_post_3_author_ids_42")
|
415
|
+
end
|
416
|
+
|
417
|
+
it 'should index the name of the checkbox input' do
|
418
|
+
output_buffer.should have_tag("input[@type='checkbox'][@name='author[post][3][author_ids][]']")
|
419
|
+
end
|
420
|
+
|
421
|
+
end
|
422
|
+
|
395
423
|
|
396
424
|
describe "when collection is an array" do
|
397
425
|
before do
|
@@ -70,6 +70,37 @@ describe 'date input' do
|
|
70
70
|
it_should_have_select_with_id("context2_post_publish_at_3i")
|
71
71
|
|
72
72
|
end
|
73
|
+
|
74
|
+
describe "when index is provided" do
|
75
|
+
|
76
|
+
before do
|
77
|
+
@output_buffer = ''
|
78
|
+
mock_everything
|
79
|
+
|
80
|
+
concat(semantic_form_for(@new_post) do |builder|
|
81
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
82
|
+
concat(author.input(:created_at, :as => :date))
|
83
|
+
end)
|
84
|
+
end)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should index the id of the wrapper' do
|
88
|
+
output_buffer.should have_tag("li#post_author_attributes_3_created_at_input")
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should index the id of the select tag' do
|
92
|
+
output_buffer.should have_tag("select#post_author_attributes_3_created_at_1i")
|
93
|
+
output_buffer.should have_tag("select#post_author_attributes_3_created_at_2i")
|
94
|
+
output_buffer.should have_tag("select#post_author_attributes_3_created_at_3i")
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should index the name of the select tag' do
|
98
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(1i)]']")
|
99
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(2i)]']")
|
100
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(3i)]']")
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
73
104
|
|
74
105
|
describe ':labels option' do
|
75
106
|
fields = [:year, :month, :day]
|
@@ -129,4 +160,68 @@ describe 'date input' do
|
|
129
160
|
end
|
130
161
|
end
|
131
162
|
|
163
|
+
describe "when order does not include day" do
|
164
|
+
before do
|
165
|
+
output_buffer.replace ''
|
166
|
+
concat(semantic_form_for(@new_post) do |builder|
|
167
|
+
concat(builder.input(:publish_at, :as => :date, :order => [:year, :month]))
|
168
|
+
end)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should include a hidden input for day" do
|
172
|
+
output_buffer.should have_tag('input[@type="hidden"][@name="post[publish_at(3i)]"][@value="1"]')
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should not include a select for day" do
|
176
|
+
output_buffer.should_not have_tag('select[@name="post[publish_at(3i)]"]')
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe "when order does not include month" do
|
181
|
+
before do
|
182
|
+
output_buffer.replace ''
|
183
|
+
concat(semantic_form_for(@new_post) do |builder|
|
184
|
+
concat(builder.input(:publish_at, :as => :date, :order => [:year, :day]))
|
185
|
+
end)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should include a hidden input for month" do
|
189
|
+
output_buffer.should have_tag('input[@type="hidden"][@name="post[publish_at(2i)]"][@value="1"]')
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should not include a select for month" do
|
193
|
+
output_buffer.should_not have_tag('select[@name="post[publish_at(2i)]"]')
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe "when order does not include year" do
|
198
|
+
before do
|
199
|
+
output_buffer.replace ''
|
200
|
+
concat(semantic_form_for(@new_post) do |builder|
|
201
|
+
concat(builder.input(:publish_at, :as => :date, :order => [:month, :day]))
|
202
|
+
end)
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should include a hidden input for month" do
|
206
|
+
output_buffer.should have_tag("input[@type=\"hidden\"][@name=\"post[publish_at(1i)]\"][@value=\"#{Time.now.year}\"]")
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should not include a select for month" do
|
210
|
+
output_buffer.should_not have_tag('select[@name="post[publish_at(1i)]"]')
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe "when order does not have year first" do
|
215
|
+
before do
|
216
|
+
output_buffer.replace ''
|
217
|
+
concat(semantic_form_for(@new_post) do |builder|
|
218
|
+
concat(builder.input(:publish_at, :as => :date, :order => [:day, :month, :year]))
|
219
|
+
end)
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'should associate the legend label with the new first select' do
|
223
|
+
output_buffer.should have_tag('form li.date fieldset legend.label label[@for="post_publish_at_3i"]')
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
132
227
|
end
|
@@ -76,6 +76,42 @@ describe 'datetime input' do
|
|
76
76
|
|
77
77
|
end
|
78
78
|
|
79
|
+
describe "when index is provided" do
|
80
|
+
|
81
|
+
before do
|
82
|
+
@output_buffer = ''
|
83
|
+
mock_everything
|
84
|
+
|
85
|
+
concat(semantic_form_for(@new_post) do |builder|
|
86
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
87
|
+
concat(author.input(:created_at, :as => :datetime))
|
88
|
+
end)
|
89
|
+
end)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should index the id of the wrapper' do
|
93
|
+
output_buffer.should have_tag("li#post_author_attributes_3_created_at_input")
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should index the id of the select tag' do
|
97
|
+
output_buffer.should have_tag("select#post_author_attributes_3_created_at_1i")
|
98
|
+
output_buffer.should have_tag("select#post_author_attributes_3_created_at_2i")
|
99
|
+
output_buffer.should have_tag("select#post_author_attributes_3_created_at_3i")
|
100
|
+
output_buffer.should have_tag("select#post_author_attributes_3_created_at_4i")
|
101
|
+
output_buffer.should have_tag("select#post_author_attributes_3_created_at_5i")
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should index the name of the select tag' do
|
105
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(1i)]']")
|
106
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(2i)]']")
|
107
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(3i)]']")
|
108
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(4i)]']")
|
109
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(5i)]']")
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
|
79
115
|
describe ':labels option' do
|
80
116
|
fields = [:year, :month, :day, :hour, :minute]
|
81
117
|
fields.each do |field|
|
@@ -132,5 +168,18 @@ describe 'datetime input' do
|
|
132
168
|
end
|
133
169
|
end
|
134
170
|
end
|
171
|
+
|
172
|
+
describe "when order does not have year first" do
|
173
|
+
before do
|
174
|
+
output_buffer.replace ''
|
175
|
+
concat(semantic_form_for(@new_post) do |builder|
|
176
|
+
concat(builder.input(:publish_at, :as => :datetime, :order => [:day, :month, :year]))
|
177
|
+
end)
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'should associate the legend label with the new first select' do
|
181
|
+
output_buffer.should have_tag('form li.datetime fieldset legend.label label[@for="post_publish_at_3i"]')
|
182
|
+
end
|
183
|
+
end
|
135
184
|
|
136
185
|
end
|
@@ -42,6 +42,34 @@ describe 'email input' do
|
|
42
42
|
|
43
43
|
end
|
44
44
|
|
45
|
+
describe "when index is provided" do
|
46
|
+
|
47
|
+
before do
|
48
|
+
@output_buffer = ''
|
49
|
+
mock_everything
|
50
|
+
|
51
|
+
concat(semantic_form_for(@new_post) do |builder|
|
52
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
53
|
+
concat(author.input(:name, :as => :email))
|
54
|
+
end)
|
55
|
+
end)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should index the id of the wrapper' do
|
59
|
+
output_buffer.should have_tag("li#post_author_attributes_3_name_input")
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should index the id of the select tag' do
|
63
|
+
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should index the name of the select tag' do
|
67
|
+
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
|
45
73
|
describe "when required" do
|
46
74
|
it "should add the required attribute to the input's html options" do
|
47
75
|
with_config :use_required_attribute, true do
|
@@ -46,6 +46,34 @@ describe 'file input' do
|
|
46
46
|
|
47
47
|
end
|
48
48
|
|
49
|
+
describe "when index is provided" do
|
50
|
+
|
51
|
+
before do
|
52
|
+
@output_buffer = ''
|
53
|
+
mock_everything
|
54
|
+
|
55
|
+
concat(semantic_form_for(@new_post) do |builder|
|
56
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
57
|
+
concat(author.input(:name, :as => :file))
|
58
|
+
end)
|
59
|
+
end)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should index the id of the wrapper' do
|
63
|
+
output_buffer.should have_tag("li#post_author_attributes_3_name_input")
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should index the id of the select tag' do
|
67
|
+
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should index the name of the select tag' do
|
71
|
+
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
|
49
77
|
context "when required" do
|
50
78
|
it "should add the required attribute to the input's html options" do
|
51
79
|
with_config :use_required_attribute, true do
|
@@ -98,6 +98,34 @@ describe 'hidden input' do
|
|
98
98
|
|
99
99
|
end
|
100
100
|
|
101
|
+
describe "when index is provided" do
|
102
|
+
|
103
|
+
before do
|
104
|
+
@output_buffer = ''
|
105
|
+
mock_everything
|
106
|
+
|
107
|
+
concat(semantic_form_for(@new_post) do |builder|
|
108
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
109
|
+
concat(author.input(:name, :as => :hidden))
|
110
|
+
end)
|
111
|
+
end)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should index the id of the wrapper' do
|
115
|
+
output_buffer.should have_tag("li#post_author_attributes_3_name_input")
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should index the id of the select tag' do
|
119
|
+
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should index the name of the select tag' do
|
123
|
+
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
|
101
129
|
context "when required" do
|
102
130
|
it "should not add the required attribute to the input's html options" do
|
103
131
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -11,59 +11,67 @@ describe "*select: options[:include_blank]" do
|
|
11
11
|
|
12
12
|
@new_post.stub!(:author_id).and_return(nil)
|
13
13
|
@new_post.stub!(:publish_at).and_return(nil)
|
14
|
-
|
15
|
-
@select_input_types = {
|
16
|
-
:select => :author,
|
17
|
-
:datetime => :publish_at,
|
18
|
-
:date => :publish_at,
|
19
|
-
:time => :publish_at
|
20
|
-
}
|
21
14
|
end
|
22
15
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
16
|
+
SELECT_INPUT_TYPES = {
|
17
|
+
:select => :author,
|
18
|
+
:datetime => :publish_at,
|
19
|
+
:date => :publish_at,
|
20
|
+
:time => :publish_at
|
21
|
+
}
|
22
|
+
|
23
|
+
SELECT_INPUT_TYPES.each do |as, attribute|
|
24
|
+
describe "for #{as} input" do
|
25
|
+
|
26
|
+
describe 'when :include_blank is not set' do
|
27
|
+
it 'blank value should be included if the default value specified in config is true' do
|
28
|
+
Formtastic::FormBuilder.include_blank_for_select_by_default = true
|
29
|
+
concat(semantic_form_for(@new_post) do |builder|
|
30
|
+
concat(builder.input(attribute, :as => as))
|
31
|
+
end)
|
32
|
+
output_buffer.should have_tag("form li select option[@value='']", "")
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'blank value should not be included if the default value specified in config is false' do
|
36
|
+
Formtastic::FormBuilder.include_blank_for_select_by_default = false
|
37
|
+
concat(semantic_form_for(@new_post) do |builder|
|
38
|
+
concat(builder.input(attribute, :as => as))
|
39
|
+
end)
|
40
|
+
output_buffer.should_not have_tag("form li select option[@value='']", "")
|
41
|
+
end
|
33
42
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
concat(semantic_form_for(@new_post) do |builder|
|
38
|
-
concat(builder.input(attribute, :as => as))
|
39
|
-
end)
|
40
|
-
output_buffer.should_not have_tag("form li select option[@value='']", "")
|
43
|
+
after do
|
44
|
+
Formtastic::FormBuilder.include_blank_for_select_by_default = true
|
45
|
+
end
|
41
46
|
end
|
42
|
-
end
|
43
47
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
+
describe 'when :include_blank is set to false' do
|
49
|
+
it 'should not have a blank option' do
|
50
|
+
concat(semantic_form_for(@new_post) do |builder|
|
51
|
+
concat(builder.input(attribute, :as => as, :include_blank => false))
|
52
|
+
end)
|
53
|
+
output_buffer.should_not have_tag("form li select option[@value='']", "")
|
54
|
+
end
|
55
|
+
end
|
48
56
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
57
|
+
describe 'when :include_blank is set to true' do
|
58
|
+
it 'should have a blank select option' do
|
59
|
+
concat(semantic_form_for(@new_post) do |builder|
|
60
|
+
concat(builder.input(attribute, :as => as, :include_blank => true))
|
61
|
+
end)
|
62
|
+
output_buffer.should have_tag("form li select option[@value='']", "")
|
63
|
+
end
|
56
64
|
end
|
57
|
-
end
|
58
|
-
end
|
59
65
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
66
|
+
if as == :select
|
67
|
+
describe 'when :include_blank is set to a string' do
|
68
|
+
it 'should have a select option with blank value but that string as text' do
|
69
|
+
concat(semantic_form_for(@new_post) do |builder|
|
70
|
+
concat(builder.input(attribute, :as => as, :include_blank => 'string'))
|
71
|
+
end)
|
72
|
+
output_buffer.should have_tag("form li select option[@value='']", "string")
|
73
|
+
end
|
74
|
+
end
|
67
75
|
end
|
68
76
|
end
|
69
77
|
end
|