formtastic 1.2.5 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. data/.gitignore +13 -0
  2. data/.rspec +2 -0
  3. data/.yardopts +1 -0
  4. data/CHANGELOG +279 -0
  5. data/Gemfile +3 -0
  6. data/README.textile +155 -172
  7. data/RELEASE_PROCESS +7 -0
  8. data/Rakefile +52 -0
  9. data/app/assets/stylesheets/formtastic.css +275 -0
  10. data/app/assets/stylesheets/formtastic_ie6.css +27 -0
  11. data/app/assets/stylesheets/formtastic_ie7.css +17 -0
  12. data/formtastic.gemspec +51 -0
  13. data/lib/formtastic.rb +21 -1960
  14. data/lib/formtastic/engine.rb +7 -0
  15. data/lib/formtastic/form_builder.rb +83 -0
  16. data/lib/formtastic/helpers.rb +16 -0
  17. data/lib/formtastic/helpers/buttons_helper.rb +277 -0
  18. data/lib/formtastic/helpers/errors_helper.rb +113 -0
  19. data/lib/formtastic/helpers/fieldset_wrapper.rb +75 -0
  20. data/lib/formtastic/helpers/file_column_detection.rb +16 -0
  21. data/lib/formtastic/helpers/form_helper.rb +198 -0
  22. data/lib/formtastic/helpers/input_helper.rb +366 -0
  23. data/lib/formtastic/helpers/inputs_helper.rb +392 -0
  24. data/lib/formtastic/helpers/reflection.rb +33 -0
  25. data/lib/formtastic/helpers/semantic_form_helper.rb +11 -0
  26. data/lib/formtastic/html_attributes.rb +21 -0
  27. data/lib/formtastic/i18n.rb +1 -0
  28. data/lib/formtastic/inputs.rb +31 -0
  29. data/lib/formtastic/inputs/base.rb +61 -0
  30. data/lib/formtastic/inputs/base/associations.rb +31 -0
  31. data/lib/formtastic/inputs/base/choices.rb +103 -0
  32. data/lib/formtastic/inputs/base/collections.rb +94 -0
  33. data/lib/formtastic/inputs/base/database.rb +17 -0
  34. data/lib/formtastic/inputs/base/errors.rb +58 -0
  35. data/lib/formtastic/inputs/base/fileish.rb +23 -0
  36. data/lib/formtastic/inputs/base/grouped_collections.rb +77 -0
  37. data/lib/formtastic/inputs/base/hints.rb +31 -0
  38. data/lib/formtastic/inputs/base/html.rb +52 -0
  39. data/lib/formtastic/inputs/base/labelling.rb +55 -0
  40. data/lib/formtastic/inputs/base/naming.rb +42 -0
  41. data/lib/formtastic/inputs/base/options.rb +18 -0
  42. data/lib/formtastic/inputs/base/stringish.rb +35 -0
  43. data/lib/formtastic/inputs/base/timeish.rb +128 -0
  44. data/lib/formtastic/inputs/base/validations.rb +166 -0
  45. data/lib/formtastic/inputs/base/wrapping.rb +40 -0
  46. data/lib/formtastic/inputs/boolean_input.rb +96 -0
  47. data/lib/formtastic/inputs/check_boxes_input.rb +179 -0
  48. data/lib/formtastic/inputs/country_input.rb +66 -0
  49. data/lib/formtastic/inputs/date_input.rb +14 -0
  50. data/lib/formtastic/inputs/datetime_input.rb +9 -0
  51. data/lib/formtastic/inputs/email_input.rb +40 -0
  52. data/lib/formtastic/inputs/file_input.rb +42 -0
  53. data/lib/formtastic/inputs/hidden_input.rb +66 -0
  54. data/lib/formtastic/inputs/number_input.rb +118 -0
  55. data/lib/formtastic/inputs/numeric_input.rb +21 -0
  56. data/lib/formtastic/inputs/password_input.rb +40 -0
  57. data/lib/formtastic/inputs/phone_input.rb +41 -0
  58. data/lib/formtastic/inputs/radio_input.rb +157 -0
  59. data/lib/formtastic/inputs/range_input.rb +119 -0
  60. data/lib/formtastic/inputs/search_input.rb +40 -0
  61. data/lib/formtastic/inputs/select_input.rb +210 -0
  62. data/lib/formtastic/inputs/string_input.rb +34 -0
  63. data/lib/formtastic/inputs/text_input.rb +47 -0
  64. data/lib/formtastic/inputs/time_input.rb +14 -0
  65. data/lib/formtastic/inputs/time_zone_input.rb +48 -0
  66. data/lib/formtastic/inputs/url_input.rb +40 -0
  67. data/lib/formtastic/localized_string.rb +105 -0
  68. data/lib/formtastic/railtie.rb +5 -7
  69. data/lib/formtastic/semantic_form_builder.rb +11 -0
  70. data/lib/formtastic/util.rb +6 -19
  71. data/lib/formtastic/version.rb +3 -0
  72. data/lib/generators/formtastic/install/install_generator.rb +28 -6
  73. data/lib/generators/templates/_form.html.erb +10 -4
  74. data/lib/generators/templates/_form.html.haml +8 -4
  75. data/lib/generators/templates/formtastic.rb +25 -32
  76. data/lib/locale/en.yml +1 -0
  77. data/lib/tasks/verify_rcov.rb +44 -0
  78. data/sample/basic_inputs.html +182 -0
  79. data/sample/config.ru +69 -0
  80. data/sample/index.html +14 -0
  81. data/spec/builder/custom_builder_spec.rb +109 -0
  82. data/spec/builder/error_proc_spec.rb +27 -0
  83. data/spec/builder/errors_spec.rb +193 -0
  84. data/spec/builder/semantic_fields_for_spec.rb +88 -0
  85. data/spec/helpers/buttons_helper_spec.rb +150 -0
  86. data/spec/helpers/commit_button_helper_spec.rb +470 -0
  87. data/spec/helpers/form_helper_spec.rb +135 -0
  88. data/spec/helpers/input_helper_spec.rb +837 -0
  89. data/spec/helpers/inputs_helper_spec.rb +562 -0
  90. data/spec/helpers/semantic_errors_helper_spec.rb +112 -0
  91. data/spec/i18n_spec.rb +199 -0
  92. data/spec/inputs/boolean_input_spec.rb +184 -0
  93. data/spec/inputs/check_boxes_input_spec.rb +375 -0
  94. data/spec/inputs/country_input_spec.rb +133 -0
  95. data/spec/inputs/custom_input_spec.rb +52 -0
  96. data/spec/inputs/date_input_spec.rb +110 -0
  97. data/spec/inputs/datetime_input_spec.rb +115 -0
  98. data/spec/inputs/email_input_spec.rb +55 -0
  99. data/spec/inputs/file_input_spec.rb +59 -0
  100. data/spec/inputs/hidden_input_spec.rb +120 -0
  101. data/spec/inputs/include_blank_spec.rb +70 -0
  102. data/spec/inputs/label_spec.rb +104 -0
  103. data/spec/inputs/number_input_spec.rb +487 -0
  104. data/spec/inputs/numeric_input_spec.rb +41 -0
  105. data/spec/inputs/password_input_spec.rb +69 -0
  106. data/spec/inputs/phone_input_spec.rb +55 -0
  107. data/spec/inputs/placeholder_spec.rb +71 -0
  108. data/spec/inputs/radio_input_spec.rb +234 -0
  109. data/spec/inputs/range_input_spec.rb +477 -0
  110. data/spec/inputs/search_input_spec.rb +55 -0
  111. data/spec/inputs/select_input_spec.rb +545 -0
  112. data/spec/inputs/string_input_spec.rb +163 -0
  113. data/spec/inputs/text_input_spec.rb +158 -0
  114. data/spec/inputs/time_input_spec.rb +155 -0
  115. data/spec/inputs/time_zone_input_spec.rb +87 -0
  116. data/spec/inputs/url_input_spec.rb +55 -0
  117. data/spec/spec.opts +2 -0
  118. data/spec/spec_helper.rb +361 -0
  119. data/spec/support/custom_macros.rb +656 -0
  120. data/spec/support/deferred_garbage_collection.rb +21 -0
  121. data/spec/support/deprecation.rb +6 -0
  122. data/spec/support/test_environment.rb +30 -0
  123. metadata +306 -88
  124. data/generators/form/USAGE +0 -16
  125. data/generators/form/form_generator.rb +0 -111
  126. data/generators/formtastic/formtastic_generator.rb +0 -26
  127. data/init.rb +0 -5
  128. data/lib/formtastic/layout_helper.rb +0 -12
  129. data/lib/generators/formtastic/form/form_generator.rb +0 -84
  130. data/lib/generators/templates/formtastic.css +0 -145
  131. data/lib/generators/templates/formtastic_changes.css +0 -14
  132. data/lib/generators/templates/rails2/_form.html.erb +0 -5
  133. data/lib/generators/templates/rails2/_form.html.haml +0 -4
  134. data/rails/init.rb +0 -2
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'numeric input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+ end
12
+
13
+ it "should call NumberInput.new" do
14
+ input = mock('input', :to_html => "HTML codez")
15
+ ::Formtastic::Inputs::NumericInput.should_receive(:new).and_return(input)
16
+ concat(semantic_form_for(@new_post) do |builder|
17
+ concat(builder.input(:title, :as => :numeric))
18
+ end)
19
+ end
20
+
21
+ it "should have an li.numeric" do
22
+ with_deprecation_silenced do
23
+ concat(semantic_form_for(@new_post) do |builder|
24
+ concat(builder.input(:title, :as => :numeric))
25
+ end)
26
+ end
27
+ output_buffer.should have_tag('li.numeric')
28
+ output_buffer.should have_tag('li.input')
29
+ end
30
+
31
+ it "should warn that :numeric is deprecated in favor of :number" do
32
+ ::ActiveSupport::Deprecation.should_receive(:warn)
33
+ with_deprecation_silenced do
34
+ concat(semantic_form_for(@new_post) do |builder|
35
+ concat(builder.input(:title, :as => :numeric))
36
+ end)
37
+ end
38
+ end
39
+
40
+ end
41
+
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'password input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+
12
+ concat(semantic_form_for(@new_post) do |builder|
13
+ concat(builder.input(:title, :as => :password))
14
+ end)
15
+ end
16
+
17
+ it_should_have_input_wrapper_with_class(:password)
18
+ it_should_have_input_wrapper_with_class(:input)
19
+ it_should_have_input_wrapper_with_class(:stringish)
20
+ it_should_have_input_wrapper_with_id("post_title_input")
21
+ it_should_have_label_with_text(/Title/)
22
+ it_should_have_label_for("post_title")
23
+ it_should_have_input_with_id("post_title")
24
+ it_should_have_input_with_type(:password)
25
+ it_should_have_input_with_name("post[title]")
26
+ it_should_have_maxlength_matching_column_limit
27
+ it_should_use_default_text_field_size_when_not_nil(:string)
28
+ it_should_not_use_default_text_field_size_when_nil(:string)
29
+ it_should_apply_custom_input_attributes_when_input_html_provided(:string)
30
+ it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
31
+ it_should_apply_error_logic_for_input_type(:password)
32
+
33
+ describe "when no object is provided" do
34
+ before do
35
+ concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
36
+ concat(builder.input(:title, :as => :password))
37
+ end)
38
+ end
39
+
40
+ it_should_have_label_with_text(/Title/)
41
+ it_should_have_label_for("project_title")
42
+ it_should_have_input_with_id("project_title")
43
+ it_should_have_input_with_type(:password)
44
+ it_should_have_input_with_name("project[title]")
45
+ end
46
+
47
+ describe "when namespace is provided" do
48
+
49
+ before do
50
+ concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
51
+ concat(builder.input(:title, :as => :password))
52
+ end)
53
+ end
54
+
55
+ it_should_have_input_wrapper_with_id("context2_post_title_input")
56
+ it_should_have_label_and_input_with_id("context2_post_title")
57
+
58
+ end
59
+
60
+ describe "when required" do
61
+ it "should add the required attribute to the input's html options" do
62
+ concat(semantic_form_for(@new_post) do |builder|
63
+ concat(builder.input(:title, :as => :password, :required => true))
64
+ end)
65
+ output_buffer.should have_tag("input[@required]")
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'phone input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+ end
12
+
13
+ describe "when object is provided" do
14
+ before do
15
+ concat(semantic_form_for(@new_post) do |builder|
16
+ concat(builder.input(:phone))
17
+ end)
18
+ end
19
+
20
+ it_should_have_input_wrapper_with_class(:phone)
21
+ it_should_have_input_wrapper_with_class(:input)
22
+ it_should_have_input_wrapper_with_class(:stringish)
23
+ it_should_have_input_wrapper_with_id("post_phone_input")
24
+ it_should_have_label_with_text(/Phone/)
25
+ it_should_have_label_for("post_phone")
26
+ it_should_have_input_with_id("post_phone")
27
+ it_should_have_input_with_type(:tel)
28
+ it_should_have_input_with_name("post[phone]")
29
+
30
+ end
31
+
32
+ describe "when namespace is provided" do
33
+
34
+ before do
35
+ concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
36
+ concat(builder.input(:phone))
37
+ end)
38
+ end
39
+
40
+ it_should_have_input_wrapper_with_id("context2_post_phone_input")
41
+ it_should_have_label_and_input_with_id("context2_post_phone")
42
+
43
+ end
44
+
45
+ describe "when required" do
46
+ it "should add the required attribute to the input's html options" do
47
+ concat(semantic_form_for(@new_post) do |builder|
48
+ concat(builder.input(:title, :as => :phone, :required => true))
49
+ end)
50
+ output_buffer.should have_tag("input[@required]")
51
+ end
52
+ end
53
+
54
+ end
55
+
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'string input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+ end
12
+
13
+ after do
14
+ ::I18n.backend.reload!
15
+ end
16
+
17
+ describe "placeholder text" do
18
+
19
+ [:email, :number, :password, :phone, :search, :string, :url].each do |type|
20
+
21
+ describe "for #{type} inputs" do
22
+
23
+ describe "when found in i18n" do
24
+ it "should have a placeholder containing i18n text" do
25
+ with_config :i18n_lookups_by_default, true do
26
+ ::I18n.backend.store_translations :en, :formtastic => { :placeholders => { :title => 'War and Peace' }}
27
+ concat(semantic_form_for(@new_post) do |builder|
28
+ concat(builder.input(:title))
29
+ end)
30
+ output_buffer.should have_tag('input[@placeholder="War and Peace"]')
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "when not found in i18n" do
36
+ it "should not have placeholder" do
37
+ concat(semantic_form_for(@new_post) do |builder|
38
+ concat(builder.input(:title))
39
+ end)
40
+ output_buffer.should_not have_tag('input[@placeholder]')
41
+ end
42
+ end
43
+
44
+ describe "when found in i18n and :input_html" do
45
+ it "should favor :input_html" do
46
+ with_config :i18n_lookups_by_default, true do
47
+ ::I18n.backend.store_translations :en, :formtastic => { :placeholders => { :title => 'War and Peace' }}
48
+ concat(semantic_form_for(@new_post) do |builder|
49
+ concat(builder.input(:title, :input_html => { :placeholder => "Foo" }))
50
+ end)
51
+ output_buffer.should have_tag('input[@placeholder="Foo"]')
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "when found in :input_html" do
57
+ it "should use the :input_html placeholder" do
58
+ concat(semantic_form_for(@new_post) do |builder|
59
+ concat(builder.input(:title, :input_html => { :placeholder => "Untitled" }))
60
+ end)
61
+ output_buffer.should have_tag('input[@placeholder="Untitled"]')
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -0,0 +1,234 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'radio input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+ end
12
+
13
+ describe 'for belongs_to association' do
14
+ before do
15
+ concat(semantic_form_for(@new_post) do |builder|
16
+ concat(builder.input(:author, :as => :radio, :value_as_class => true, :required => true))
17
+ end)
18
+ end
19
+
20
+ it_should_have_input_wrapper_with_class("radio")
21
+ it_should_have_input_wrapper_with_class(:input)
22
+ it_should_have_input_wrapper_with_id("post_author_input")
23
+ it_should_have_a_nested_fieldset
24
+ it_should_have_a_nested_fieldset_with_class('choices')
25
+ it_should_have_a_nested_ordered_list_with_class('choices-group')
26
+ it_should_apply_error_logic_for_input_type(:radio)
27
+ it_should_use_the_collection_when_provided(:radio, 'input')
28
+
29
+ it 'should generate a legend containing a label with text for the input' do
30
+ output_buffer.should have_tag('form li fieldset legend.label label')
31
+ output_buffer.should have_tag('form li fieldset legend.label label', /Author/)
32
+ end
33
+
34
+ it 'should not link the label within the legend to any input' do
35
+ output_buffer.should_not have_tag('form li fieldset legend label[@for]')
36
+ end
37
+
38
+ it 'should generate an ordered list with a list item for each choice' do
39
+ output_buffer.should have_tag('form li fieldset ol')
40
+ output_buffer.should have_tag('form li fieldset ol li.choice', :count => ::Author.all.size)
41
+ end
42
+
43
+ it 'should have one option with a "checked" attribute' do
44
+ output_buffer.should have_tag('form li input[@checked]', :count => 1)
45
+ end
46
+
47
+ describe "each choice" do
48
+
49
+ it 'should contain a label for the radio input with a nested input and label text' do
50
+ ::Author.all.each do |author|
51
+ output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
52
+ output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_id_#{author.id}']")
53
+ end
54
+ end
55
+
56
+ it 'should use values as li.class when value_as_class is true' do
57
+ ::Author.all.each do |author|
58
+ output_buffer.should have_tag("form li fieldset ol li.author_#{author.id} label")
59
+ end
60
+ end
61
+
62
+ it "should add the required attribute to the input's html options" do
63
+ ::Author.all.each do |post|
64
+ output_buffer.should have_tag("form li fieldset ol li.author_#{post.id} input[@required]")
65
+ end
66
+ end
67
+
68
+ it "should have a radio input" do
69
+ ::Author.all.each do |author|
70
+ output_buffer.should have_tag("form li fieldset ol li label input#post_author_id_#{author.id}")
71
+ output_buffer.should have_tag("form li fieldset ol li label input[@type='radio']")
72
+ output_buffer.should have_tag("form li fieldset ol li label input[@value='#{author.id}']")
73
+ output_buffer.should have_tag("form li fieldset ol li label input[@name='post[author_id]']")
74
+ end
75
+ end
76
+
77
+ it "should mark input as checked if it's the the existing choice" do
78
+ @new_post.author_id.should == @bob.id
79
+ @new_post.author.id.should == @bob.id
80
+ @new_post.author.should == @bob
81
+
82
+ concat(semantic_form_for(@new_post) do |builder|
83
+ concat(builder.input(:author, :as => :radio))
84
+ end)
85
+
86
+ output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']")
87
+ end
88
+
89
+ it "should mark the input as disabled if options attached for disabling" do
90
+ concat(semantic_form_for(@new_post) do |builder|
91
+ concat(builder.input(:author, :as => :radio, :collection => [["Test", 'test'], ["Try", "try", {:disabled => true}]]))
92
+ end)
93
+
94
+ output_buffer.should_not have_tag("form li fieldset ol li label input[@value='test'][@disabled='disabled']")
95
+ output_buffer.should have_tag("form li fieldset ol li label input[@value='try'][@disabled='disabled']")
96
+ end
97
+
98
+ it "should not contain invalid HTML attributes" do
99
+
100
+ concat(semantic_form_for(@new_post) do |builder|
101
+ concat(builder.input(:author, :as => :radio))
102
+ end)
103
+
104
+ output_buffer.should_not have_tag("form li fieldset ol li input[@find_options]")
105
+ end
106
+
107
+ end
108
+
109
+ describe 'and no object is given' do
110
+ before(:each) do
111
+ output_buffer.replace ''
112
+ concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
113
+ concat(builder.input(:author_id, :as => :radio, :collection => ::Author.all))
114
+ end)
115
+ end
116
+
117
+ it 'should generate a fieldset with legend' do
118
+ output_buffer.should have_tag('form li fieldset legend', /Author/)
119
+ end
120
+
121
+ it 'should generate an li tag for each item in the collection' do
122
+ output_buffer.should have_tag('form li fieldset ol li', :count => ::Author.all.size)
123
+ end
124
+
125
+ it 'should generate labels for each item' do
126
+ ::Author.all.each do |author|
127
+ output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
128
+ output_buffer.should have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
129
+ end
130
+ end
131
+
132
+ it 'should html escape the label string' do
133
+ concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
134
+ concat(builder.input(:author_id, :as => :radio, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
135
+ end)
136
+ output_buffer.should have_tag('form li fieldset ol li label') do |label|
137
+ label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;$/
138
+ end
139
+ end
140
+
141
+ it 'should generate inputs for each item' do
142
+ ::Author.all.each do |author|
143
+ output_buffer.should have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
144
+ output_buffer.should have_tag("form li fieldset ol li label input[@type='radio']")
145
+ output_buffer.should have_tag("form li fieldset ol li label input[@value='#{author.id}']")
146
+ output_buffer.should have_tag("form li fieldset ol li label input[@name='project[author_id]']")
147
+ end
148
+ end
149
+ end
150
+ end
151
+
152
+ describe "with i18n of the legend label" do
153
+
154
+ before do
155
+ ::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
156
+
157
+ with_config :i18n_lookups_by_default, true do
158
+ @new_post.stub!(:author_ids).and_return(nil)
159
+ concat(semantic_form_for(@new_post) do |builder|
160
+ concat(builder.input(:authors, :as => :radio))
161
+ end)
162
+ end
163
+ end
164
+
165
+ after do
166
+ ::I18n.backend.reload!
167
+ end
168
+
169
+ it "should do foo" do
170
+ output_buffer.should have_tag("legend.label label", /Translated/)
171
+ end
172
+
173
+ end
174
+
175
+ describe "when :label option is set" do
176
+ before do
177
+ @new_post.stub!(:author_ids).and_return(nil)
178
+ concat(semantic_form_for(@new_post) do |builder|
179
+ concat(builder.input(:authors, :as => :radio, :label => 'The authors'))
180
+ end)
181
+ end
182
+
183
+ it "should output the correct label title" do
184
+ output_buffer.should have_tag("legend.label label", /The authors/)
185
+ end
186
+ end
187
+
188
+ describe "when :label option is false" do
189
+ before do
190
+ @output_buffer = ''
191
+ @new_post.stub!(:author_ids).and_return(nil)
192
+ concat(semantic_form_for(@new_post) do |builder|
193
+ concat(builder.input(:authors, :as => :radio, :label => false))
194
+ end)
195
+ end
196
+
197
+ it "should not output the legend" do
198
+ output_buffer.should_not have_tag("legend.label")
199
+ output_buffer.should_not include("&gt;")
200
+ end
201
+
202
+ it "should not cause escaped HTML" do
203
+ output_buffer.should_not include("&gt;")
204
+ end
205
+ end
206
+
207
+ describe "when :required option is true" do
208
+ before do
209
+ @new_post.stub!(:author_ids).and_return(nil)
210
+ concat(semantic_form_for(@new_post) do |builder|
211
+ concat(builder.input(:authors, :as => :radio, :required => true))
212
+ end)
213
+ end
214
+
215
+ it "should output the correct label title" do
216
+ output_buffer.should have_tag("legend.label label abbr")
217
+ end
218
+ end
219
+
220
+ describe "when :namespace is given on form" do
221
+ before do
222
+ @output_buffer = ''
223
+ @new_post.stub!(:author_ids).and_return(nil)
224
+ concat(semantic_form_for(@new_post, :namespace => "custom_prefix") do |builder|
225
+ concat(builder.input(:authors, :as => :radio, :label => ''))
226
+ end)
227
+
228
+ output_buffer.should match(/for="custom_prefix_post_author_ids_(\d+)"/)
229
+ output_buffer.should match(/id="custom_prefix_post_author_ids_(\d+)"/)
230
+ end
231
+ it_should_have_input_wrapper_with_id("custom_prefix_post_authors_input")
232
+ end
233
+
234
+ end