formtastic 2.0.2 → 2.1.0.beta1
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.
- 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
|
@@ -26,6 +26,7 @@ describe 'number input' do
|
|
|
26
26
|
|
|
27
27
|
it_should_have_input_wrapper_with_class(:number)
|
|
28
28
|
it_should_have_input_wrapper_with_class(:input)
|
|
29
|
+
it_should_have_input_wrapper_with_class(:numeric)
|
|
29
30
|
it_should_have_input_wrapper_with_class(:stringish)
|
|
30
31
|
it_should_have_input_wrapper_with_id("post_title_input")
|
|
31
32
|
it_should_have_label_with_text(/Title/)
|
|
@@ -33,10 +34,11 @@ describe 'number input' do
|
|
|
33
34
|
it_should_have_input_with_id("post_title")
|
|
34
35
|
it_should_have_input_with_type(:number)
|
|
35
36
|
it_should_have_input_with_name("post[title]")
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
# @todo this is not testing what it should be testing!
|
|
38
|
+
# it_should_use_default_text_field_size_when_not_nil(:string)
|
|
39
|
+
# it_should_not_use_default_text_field_size_when_nil(:string)
|
|
40
|
+
# it_should_apply_custom_input_attributes_when_input_html_provided(:string)
|
|
41
|
+
# it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
|
|
40
42
|
it_should_apply_error_logic_for_input_type(:number)
|
|
41
43
|
|
|
42
44
|
end
|
|
@@ -66,6 +68,34 @@ describe 'number input' do
|
|
|
66
68
|
it_should_have_label_and_input_with_id("context2_post_title")
|
|
67
69
|
end
|
|
68
70
|
|
|
71
|
+
describe "when index is provided" do
|
|
72
|
+
|
|
73
|
+
before do
|
|
74
|
+
@output_buffer = ''
|
|
75
|
+
mock_everything
|
|
76
|
+
|
|
77
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
78
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
|
79
|
+
concat(author.input(:name, :as => :number))
|
|
80
|
+
end)
|
|
81
|
+
end)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'should index the id of the wrapper' do
|
|
85
|
+
output_buffer.should have_tag("li#post_author_attributes_3_name_input")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'should index the id of the select tag' do
|
|
89
|
+
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'should index the name of the select tag' do
|
|
93
|
+
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
|
|
69
99
|
describe "when required" do
|
|
70
100
|
it "should add the required attribute to the input's html options" do
|
|
71
101
|
with_config :use_required_attribute, true do
|
|
@@ -57,6 +57,34 @@ describe 'password input' do
|
|
|
57
57
|
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
+
describe "when index is provided" do
|
|
61
|
+
|
|
62
|
+
before do
|
|
63
|
+
@output_buffer = ''
|
|
64
|
+
mock_everything
|
|
65
|
+
|
|
66
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
67
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
|
68
|
+
concat(author.input(:name, :as => :password))
|
|
69
|
+
end)
|
|
70
|
+
end)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'should index the id of the wrapper' do
|
|
74
|
+
output_buffer.should have_tag("li#post_author_attributes_3_name_input")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'should index the id of the select tag' do
|
|
78
|
+
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'should index the name of the select tag' do
|
|
82
|
+
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
|
|
60
88
|
describe "when required" do
|
|
61
89
|
it "should add the required attribute to the input's html options" do
|
|
62
90
|
with_config :use_required_attribute, true do
|
|
@@ -42,6 +42,34 @@ describe 'phone 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 => :phone))
|
|
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
|
|
@@ -16,18 +16,18 @@ describe 'string input' do
|
|
|
16
16
|
|
|
17
17
|
describe "placeholder text" do
|
|
18
18
|
|
|
19
|
-
[:email, :number, :password, :phone, :search, :string, :url].each do |type|
|
|
19
|
+
[:email, :number, :password, :phone, :search, :string, :url, :text].each do |type|
|
|
20
20
|
|
|
21
21
|
describe "for #{type} inputs" do
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
describe "when found in i18n" do
|
|
24
24
|
it "should have a placeholder containing i18n text" do
|
|
25
25
|
with_config :i18n_lookups_by_default, true do
|
|
26
26
|
::I18n.backend.store_translations :en, :formtastic => { :placeholders => { :title => 'War and Peace' }}
|
|
27
27
|
concat(semantic_form_for(@new_post) do |builder|
|
|
28
|
-
concat(builder.input(:title))
|
|
28
|
+
concat(builder.input(:title, :as => type))
|
|
29
29
|
end)
|
|
30
|
-
output_buffer.should have_tag('input[@placeholder="War and Peace"]')
|
|
30
|
+
output_buffer.should have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="War and Peace"]')
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
end
|
|
@@ -35,9 +35,9 @@ describe 'string input' do
|
|
|
35
35
|
describe "when not found in i18n" do
|
|
36
36
|
it "should not have placeholder" do
|
|
37
37
|
concat(semantic_form_for(@new_post) do |builder|
|
|
38
|
-
concat(builder.input(:title))
|
|
38
|
+
concat(builder.input(:title, :as => type))
|
|
39
39
|
end)
|
|
40
|
-
output_buffer.should_not have_tag('input[@placeholder]')
|
|
40
|
+
output_buffer.should_not have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder]')
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
|
@@ -46,9 +46,9 @@ describe 'string input' do
|
|
|
46
46
|
with_config :i18n_lookups_by_default, true do
|
|
47
47
|
::I18n.backend.store_translations :en, :formtastic => { :placeholders => { :title => 'War and Peace' }}
|
|
48
48
|
concat(semantic_form_for(@new_post) do |builder|
|
|
49
|
-
concat(builder.input(:title, :input_html => { :placeholder => "Foo" }))
|
|
49
|
+
concat(builder.input(:title, :as => type, :input_html => { :placeholder => "Foo" }))
|
|
50
50
|
end)
|
|
51
|
-
output_buffer.should have_tag('input[@placeholder="Foo"]')
|
|
51
|
+
output_buffer.should have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="Foo"]')
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
end
|
|
@@ -56,9 +56,9 @@ describe 'string input' do
|
|
|
56
56
|
describe "when found in :input_html" do
|
|
57
57
|
it "should use the :input_html placeholder" do
|
|
58
58
|
concat(semantic_form_for(@new_post) do |builder|
|
|
59
|
-
concat(builder.input(:title, :input_html => { :placeholder => "Untitled" }))
|
|
59
|
+
concat(builder.input(:title, :as => type, :input_html => { :placeholder => "Untitled" }))
|
|
60
60
|
end)
|
|
61
|
-
output_buffer.should have_tag('input[@placeholder="Untitled"]')
|
|
61
|
+
output_buffer.should have_tag((type == :text ? 'textarea' : 'input') + '[@placeholder="Untitled"]')
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
|
|
@@ -45,16 +45,16 @@ describe 'radio input' do
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
describe "each choice" do
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
it 'should not give the choice label the .label class' do
|
|
50
50
|
output_buffer.should_not have_tag('li.choice label.label')
|
|
51
51
|
end
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
it 'should not add the required attribute to each input' do
|
|
54
54
|
output_buffer.should_not have_tag('li.choice input[@required]')
|
|
55
55
|
end
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
|
|
57
|
+
|
|
58
58
|
it 'should contain a label for the radio input with a nested input and label text' do
|
|
59
59
|
::Author.all.each do |author|
|
|
60
60
|
output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
|
|
@@ -67,7 +67,7 @@ describe 'radio input' do
|
|
|
67
67
|
output_buffer.should have_tag("form li fieldset ol li.author_#{author.id} label")
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
it "should have a radio input" do
|
|
72
72
|
::Author.all.each do |author|
|
|
73
73
|
output_buffer.should have_tag("form li fieldset ol li label input#post_author_id_#{author.id}")
|
|
@@ -201,7 +201,7 @@ describe 'radio input' do
|
|
|
201
201
|
output_buffer.should_not have_tag("legend.label")
|
|
202
202
|
output_buffer.should_not include(">")
|
|
203
203
|
end
|
|
204
|
-
|
|
204
|
+
|
|
205
205
|
it "should not cause escaped HTML" do
|
|
206
206
|
output_buffer.should_not include(">")
|
|
207
207
|
end
|
|
@@ -234,4 +234,49 @@ describe 'radio input' do
|
|
|
234
234
|
it_should_have_input_wrapper_with_id("custom_prefix_post_authors_input")
|
|
235
235
|
end
|
|
236
236
|
|
|
237
|
+
describe "when index is provided" do
|
|
238
|
+
|
|
239
|
+
before do
|
|
240
|
+
@output_buffer = ''
|
|
241
|
+
mock_everything
|
|
242
|
+
|
|
243
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
244
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
|
245
|
+
concat(author.input(:name, :as => :radio))
|
|
246
|
+
end)
|
|
247
|
+
end)
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
it 'should index the id of the wrapper' do
|
|
251
|
+
output_buffer.should have_tag("li#post_author_attributes_3_name_input")
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
it 'should index the id of the select tag' do
|
|
255
|
+
output_buffer.should have_tag("input#post_author_attributes_3_name_true")
|
|
256
|
+
output_buffer.should have_tag("input#post_author_attributes_3_name_false")
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it 'should index the name of the select tag' do
|
|
260
|
+
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
describe "when collection contains integers" do
|
|
266
|
+
before do
|
|
267
|
+
@output_buffer = ''
|
|
268
|
+
mock_everything
|
|
269
|
+
|
|
270
|
+
concat(semantic_form_for(:project) do |builder|
|
|
271
|
+
concat(builder.input(:author_id, :as => :radio, :collection => [1, 2, 3]))
|
|
272
|
+
end)
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
it 'should output the correct labels' do
|
|
276
|
+
output_buffer.should have_tag("li.choice label", /1/)
|
|
277
|
+
output_buffer.should have_tag("li.choice label", /2/)
|
|
278
|
+
output_buffer.should have_tag("li.choice label", /3/)
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
|
|
237
282
|
end
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require 'spec_helper'
|
|
3
|
-
require 'active_record'
|
|
4
3
|
|
|
5
4
|
describe 'range input' do
|
|
6
5
|
|
|
@@ -20,7 +19,8 @@ describe 'range input' do
|
|
|
20
19
|
|
|
21
20
|
it_should_have_input_wrapper_with_class(:range)
|
|
22
21
|
it_should_have_input_wrapper_with_class(:input)
|
|
23
|
-
it_should_have_input_wrapper_with_class(:
|
|
22
|
+
it_should_have_input_wrapper_with_class(:numeric)
|
|
23
|
+
it_should_have_input_wrapper_with_class(:stringish)
|
|
24
24
|
it_should_have_input_wrapper_with_id("author_age_input")
|
|
25
25
|
it_should_have_label_with_text(/Age/)
|
|
26
26
|
it_should_have_label_for("author_age")
|
|
@@ -42,6 +42,34 @@ describe 'range input' do
|
|
|
42
42
|
it_should_have_label_and_input_with_id("context2_author_age")
|
|
43
43
|
|
|
44
44
|
end
|
|
45
|
+
|
|
46
|
+
describe "when index is provided" do
|
|
47
|
+
|
|
48
|
+
before do
|
|
49
|
+
@output_buffer = ''
|
|
50
|
+
mock_everything
|
|
51
|
+
|
|
52
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
53
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
|
54
|
+
concat(author.input(:name, :as => :range))
|
|
55
|
+
end)
|
|
56
|
+
end)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'should index the id of the wrapper' do
|
|
60
|
+
output_buffer.should have_tag("li#post_author_attributes_3_name_input")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'should index the id of the select tag' do
|
|
64
|
+
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'should index the name of the select tag' do
|
|
68
|
+
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
45
73
|
|
|
46
74
|
describe "when validations require a minimum value (:greater_than)" do
|
|
47
75
|
before do
|
|
@@ -42,6 +42,33 @@ describe 'search 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 => :search))
|
|
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
|
+
|
|
45
72
|
describe "when required" do
|
|
46
73
|
it "should add the required attribute to the input's html options" do
|
|
47
74
|
with_config :use_required_attribute, true do
|
|
@@ -75,6 +75,16 @@ describe 'select input' do
|
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
|
+
|
|
79
|
+
describe 'using a nil name' do
|
|
80
|
+
before do
|
|
81
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
82
|
+
concat(builder.input(:title, :as => :select, :collection => [], :input_html => {:name => nil}))
|
|
83
|
+
end)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it_should_have_select_with_name("post[title]")
|
|
87
|
+
end
|
|
78
88
|
end
|
|
79
89
|
|
|
80
90
|
describe 'for boolean columns' do
|
|
@@ -90,6 +100,7 @@ describe 'select input' do
|
|
|
90
100
|
end
|
|
91
101
|
|
|
92
102
|
after do
|
|
103
|
+
::I18n.load_path = []
|
|
93
104
|
::I18n.backend.store_translations :en, {}
|
|
94
105
|
end
|
|
95
106
|
|
|
@@ -152,6 +163,10 @@ describe 'select input' do
|
|
|
152
163
|
it 'should not create a multi-select' do
|
|
153
164
|
output_buffer.should_not have_tag('form li select[@multiple]')
|
|
154
165
|
end
|
|
166
|
+
|
|
167
|
+
it 'should not add a hidden input' do
|
|
168
|
+
output_buffer.should_not have_tag('form li input[@type="hidden"]')
|
|
169
|
+
end
|
|
155
170
|
|
|
156
171
|
it 'should create a select without size' do
|
|
157
172
|
output_buffer.should_not have_tag('form li select[@size]')
|
|
@@ -317,11 +332,15 @@ describe 'select input' do
|
|
|
317
332
|
it 'should have a multi-select select' do
|
|
318
333
|
output_buffer.should have_tag('form li select[@multiple="multiple"]')
|
|
319
334
|
end
|
|
320
|
-
|
|
335
|
+
|
|
321
336
|
it 'should append [] to the name attribute for multiple select' do
|
|
322
337
|
output_buffer.should have_tag('form li select[@multiple="multiple"][@name="author[post_ids][]"]')
|
|
323
338
|
end
|
|
324
339
|
|
|
340
|
+
it 'should have a hidden field' do
|
|
341
|
+
output_buffer.should have_tag('form li input[@type="hidden"][@name="author[post_ids][]"]')
|
|
342
|
+
end
|
|
343
|
+
|
|
325
344
|
it 'should have a select option for each Post' do
|
|
326
345
|
output_buffer.should have_tag('form li select option', :count => ::Post.all.size)
|
|
327
346
|
::Post.all.each do |post|
|
|
@@ -422,8 +441,8 @@ describe 'select input' do
|
|
|
422
441
|
output_buffer.should have_tag("form li select option[@value='']", /choose author/, :count => 1)
|
|
423
442
|
end
|
|
424
443
|
|
|
425
|
-
it 'should not have a blank select option' do
|
|
426
|
-
output_buffer.
|
|
444
|
+
it 'should not have a second blank select option' do
|
|
445
|
+
output_buffer.should have_tag("form li select option[@value='']", :count => 1)
|
|
427
446
|
end
|
|
428
447
|
end
|
|
429
448
|
|
|
@@ -459,7 +478,7 @@ describe 'select input' do
|
|
|
459
478
|
end)
|
|
460
479
|
output_buffer.should have_tag("form li select[@name='project[author_name]']")
|
|
461
480
|
end
|
|
462
|
-
|
|
481
|
+
|
|
463
482
|
describe 'and :multiple is set to true through :input_html' do
|
|
464
483
|
it "should make the select a multi-select" do
|
|
465
484
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
@@ -468,7 +487,7 @@ describe 'select input' do
|
|
|
468
487
|
output_buffer.should have_tag("form li select[@multiple]")
|
|
469
488
|
end
|
|
470
489
|
end
|
|
471
|
-
|
|
490
|
+
|
|
472
491
|
describe 'and :multiple is set to true' do
|
|
473
492
|
it "should make the select a multi-select" do
|
|
474
493
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
@@ -477,7 +496,7 @@ describe 'select input' do
|
|
|
477
496
|
output_buffer.should have_tag("form li select[@multiple]")
|
|
478
497
|
end
|
|
479
498
|
end
|
|
480
|
-
|
|
499
|
+
|
|
481
500
|
end
|
|
482
501
|
|
|
483
502
|
describe 'when a grouped collection collection is given' do
|
|
@@ -550,6 +569,33 @@ describe 'select input' do
|
|
|
550
569
|
it_should_have_select_with_id("context2_post_author_ids")
|
|
551
570
|
it_should_have_label_for("context2_post_author_ids")
|
|
552
571
|
end
|
|
572
|
+
|
|
573
|
+
describe "when index is provided" do
|
|
574
|
+
|
|
575
|
+
before do
|
|
576
|
+
@output_buffer = ''
|
|
577
|
+
mock_everything
|
|
578
|
+
|
|
579
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
580
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
|
581
|
+
concat(author.input(:name, :as => :select))
|
|
582
|
+
end)
|
|
583
|
+
end)
|
|
584
|
+
end
|
|
585
|
+
|
|
586
|
+
it 'should index the id of the wrapper' do
|
|
587
|
+
output_buffer.should have_tag("li#post_author_attributes_3_name_input")
|
|
588
|
+
end
|
|
589
|
+
|
|
590
|
+
it 'should index the id of the select tag' do
|
|
591
|
+
output_buffer.should have_tag("select#post_author_attributes_3_name")
|
|
592
|
+
end
|
|
593
|
+
|
|
594
|
+
it 'should index the name of the select' do
|
|
595
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][name]']")
|
|
596
|
+
end
|
|
597
|
+
|
|
598
|
+
end
|
|
553
599
|
|
|
554
600
|
context "when required" do
|
|
555
601
|
it "should add the required attribute to the select's html options" do
|