formtastic-bootstrap 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +12 -0
  4. data/Gemfile.lock +123 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.md +159 -0
  7. data/Rakefile +49 -0
  8. data/VERSION +1 -0
  9. data/formtastic-bootstrap.gemspec +128 -0
  10. data/lib/action_view/helpers/text_field_date_helper.rb +166 -0
  11. data/lib/formtastic-bootstrap.rb +5 -0
  12. data/lib/formtastic-bootstrap/form_builder.rb +38 -0
  13. data/lib/formtastic-bootstrap/helpers.rb +19 -0
  14. data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +47 -0
  15. data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +37 -0
  16. data/lib/formtastic-bootstrap/helpers/input_helper.rb +12 -0
  17. data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +36 -0
  18. data/lib/formtastic-bootstrap/inputs.rb +28 -0
  19. data/lib/formtastic-bootstrap/inputs/base.rb +22 -0
  20. data/lib/formtastic-bootstrap/inputs/base/choices.rb +49 -0
  21. data/lib/formtastic-bootstrap/inputs/base/errors.rb +48 -0
  22. data/lib/formtastic-bootstrap/inputs/base/hints.rb +27 -0
  23. data/lib/formtastic-bootstrap/inputs/base/html.rb +21 -0
  24. data/lib/formtastic-bootstrap/inputs/base/labelling.rb +18 -0
  25. data/lib/formtastic-bootstrap/inputs/base/stringish.rb +18 -0
  26. data/lib/formtastic-bootstrap/inputs/base/timeish.rb +35 -0
  27. data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +56 -0
  28. data/lib/formtastic-bootstrap/inputs/boolean_input.rb +33 -0
  29. data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +35 -0
  30. data/lib/formtastic-bootstrap/inputs/date_input.rb +16 -0
  31. data/lib/formtastic-bootstrap/inputs/datetime_input.rb +19 -0
  32. data/lib/formtastic-bootstrap/inputs/email_input.rb +15 -0
  33. data/lib/formtastic-bootstrap/inputs/file_input.rb +14 -0
  34. data/lib/formtastic-bootstrap/inputs/hidden_input.rb +12 -0
  35. data/lib/formtastic-bootstrap/inputs/number_input.rb +15 -0
  36. data/lib/formtastic-bootstrap/inputs/password_input.rb +15 -0
  37. data/lib/formtastic-bootstrap/inputs/phone_input.rb +15 -0
  38. data/lib/formtastic-bootstrap/inputs/radio_input.rb +32 -0
  39. data/lib/formtastic-bootstrap/inputs/range_input.rb +15 -0
  40. data/lib/formtastic-bootstrap/inputs/search_input.rb +15 -0
  41. data/lib/formtastic-bootstrap/inputs/select_input.rb +14 -0
  42. data/lib/formtastic-bootstrap/inputs/string_input.rb +15 -0
  43. data/lib/formtastic-bootstrap/inputs/text_input.rb +14 -0
  44. data/lib/formtastic-bootstrap/inputs/time_input.rb +16 -0
  45. data/lib/formtastic-bootstrap/inputs/url_input.rb +14 -0
  46. data/spec/builder/errors_spec.rb +214 -0
  47. data/spec/builder/semantic_fields_for_spec.rb +130 -0
  48. data/spec/helpers/input_helper_spec.rb +956 -0
  49. data/spec/helpers/inputs_helper_spec.rb +577 -0
  50. data/spec/inputs/boolean_input_spec.rb +193 -0
  51. data/spec/inputs/check_boxes_input_spec.rb +439 -0
  52. data/spec/inputs/date_input_spec.rb +147 -0
  53. data/spec/inputs/datetime_input_spec.rb +101 -0
  54. data/spec/inputs/email_input_spec.rb +59 -0
  55. data/spec/inputs/file_input_spec.rb +63 -0
  56. data/spec/inputs/hidden_input_spec.rb +122 -0
  57. data/spec/inputs/number_input_spec.rb +787 -0
  58. data/spec/inputs/password_input_spec.rb +73 -0
  59. data/spec/inputs/phone_input_spec.rb +59 -0
  60. data/spec/inputs/radio_input_spec.rb +240 -0
  61. data/spec/inputs/range_input_spec.rb +479 -0
  62. data/spec/inputs/search_input_spec.rb +59 -0
  63. data/spec/inputs/select_input_spec.rb +567 -0
  64. data/spec/inputs/string_input_spec.rb +182 -0
  65. data/spec/inputs/text_input_spec.rb +163 -0
  66. data/spec/inputs/time_input_spec.rb +206 -0
  67. data/spec/inputs/url_input_spec.rb +59 -0
  68. data/spec/spec_helper.rb +24 -0
  69. data/spec/support/custom_macros.rb +704 -0
  70. data/spec/support/depracation.rb +6 -0
  71. data/spec/support/formtastic_spec_helper.rb +382 -0
  72. metadata +204 -0
@@ -0,0 +1,182 @@
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
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
+ end
13
+
14
+ describe "when object is provided" do
15
+ before do
16
+ concat(semantic_form_for(@new_post) do |builder|
17
+ concat(builder.input(:title, :as => :string))
18
+ end)
19
+ end
20
+
21
+ it_should_have_input_wrapper_with_class(:string)
22
+ it_should_have_input_wrapper_with_class(:clearfix)
23
+ it_should_have_input_wrapper_with_class(:stringish)
24
+ it_should_have_input_class_in_the_right_place
25
+ it_should_have_input_wrapper_with_id("post_title_input")
26
+ it_should_have_label_with_text(/Title/)
27
+ it_should_have_label_for("post_title")
28
+ it_should_have_input_with_id("post_title")
29
+ it_should_have_input_with_type(:text)
30
+ it_should_have_input_with_name("post[title]")
31
+ it_should_have_maxlength_matching_column_limit
32
+ it_should_use_default_text_field_size_when_not_nil(:string)
33
+ it_should_not_use_default_text_field_size_when_nil(:string)
34
+ it_should_apply_custom_input_attributes_when_input_html_provided(:string)
35
+ it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
36
+ it_should_apply_error_logic_for_input_type(:string)
37
+
38
+ def input_field_for_method_should_have_maxlength(method, maxlength)
39
+ concat(semantic_form_for(@new_post) do |builder|
40
+ concat(builder.input(method))
41
+ end)
42
+ output_buffer.should have_tag("form li input[@maxlength='#{maxlength}']")
43
+ end
44
+
45
+ describe 'and its a ActiveModel' do
46
+ let(:default_maxlength) { 50 }
47
+
48
+ before do
49
+ @new_post.stub!(:class).and_return(::PostModel)
50
+ end
51
+
52
+ after do
53
+ @new_post.stub!(:class).and_return(::Post)
54
+ end
55
+
56
+ describe 'and validates_length_of was called for the method' do
57
+ def should_have_maxlength(maxlength, options)
58
+ @new_post.class.should_receive(:validators_on).with(:title).at_least(1).and_return([
59
+ active_model_length_validator([:title], options[:options])
60
+ ])
61
+
62
+ concat(semantic_form_for(@new_post) do |builder|
63
+ concat(builder.input(:title))
64
+ end)
65
+
66
+ output_buffer.should have_tag("form div.clearfix div.input input##{@new_post.class.name.underscore}_title[@maxlength='#{maxlength}']")
67
+ end
68
+
69
+ it 'should have maxlength if the optional :if or :unless options are not supplied' do
70
+ should_have_maxlength(42, :options => {:maximum => 42})
71
+ end
72
+
73
+ it 'should have default maxlength if the optional :if condition is not satisifed' do
74
+ should_have_maxlength(default_maxlength, :options => {:maximum => 42, :if => false})
75
+ end
76
+
77
+ it 'should have default_maxlength if the optional :if proc evaluates to false' do
78
+ should_have_maxlength(default_maxlength, :options => {:maximum => 42, :if => proc { |record| false }})
79
+ end
80
+
81
+ it 'should have maxlength if the optional :if proc evaluates to true' do
82
+ should_have_maxlength(42, :options => { :maximum => 42, :if => proc { |record| true } })
83
+ end
84
+
85
+ it 'should have default maxlength if the optional :if with a method name evaluates to false' do
86
+ @new_post.should_receive(:specify_maxlength).at_least(1).and_return(false)
87
+ should_have_maxlength(default_maxlength, :options => { :maximum => 42, :if => :specify_maxlength })
88
+ end
89
+
90
+ it 'should have maxlength if the optional :if with a method name evaluates to true' do
91
+ @new_post.should_receive(:specify_maxlength).at_least(1).and_return(true)
92
+ should_have_maxlength(42, :options => { :maximum => 42, :if => :specify_maxlength })
93
+ end
94
+
95
+ it 'should have default maxlength if the optional :unless proc evaluates to true' do
96
+ should_have_maxlength(default_maxlength, :options => { :maximum => 42, :unless => proc { |record| true } })
97
+ end
98
+
99
+ it 'should have maxlength if the optional :unless proc evaluates to false' do
100
+ should_have_maxlength(42, :options => { :maximum => 42, :unless => proc { |record| false } })
101
+ end
102
+
103
+ it 'should have default maxlength if the optional :unless with a method name evaluates to true' do
104
+ @new_post.should_receive(:specify_maxlength).at_least(1).and_return(true)
105
+ should_have_maxlength(default_maxlength, :options => { :maximum => 42, :unless => :specify_maxlength })
106
+ end
107
+
108
+ it 'should have maxlength if the optional :unless with a method name evaluates to false' do
109
+ @new_post.should_receive(:specify_maxlength).at_least(1).and_return(false)
110
+ should_have_maxlength(42, :options => { :maximum => 42, :unless => :specify_maxlength })
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ describe "when namespace is provided" do
117
+
118
+ before do
119
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
120
+ concat(builder.input(:title, :as => :string))
121
+ end)
122
+ end
123
+
124
+ it_should_have_input_wrapper_with_id("context2_post_title_input")
125
+ it_should_have_label_and_input_with_id("context2_post_title")
126
+
127
+ end
128
+
129
+ describe "when no object is provided" do
130
+ before do
131
+ concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
132
+ concat(builder.input(:title, :as => :string))
133
+ end)
134
+ end
135
+
136
+ it_should_have_label_with_text(/Title/)
137
+ it_should_have_label_for("project_title")
138
+ it_should_have_input_with_id("project_title")
139
+ it_should_have_input_with_type(:text)
140
+ it_should_have_input_with_name("project[title]")
141
+ end
142
+
143
+ describe "when size is nil" do
144
+ before do
145
+ concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
146
+ concat(builder.input(:title, :as => :string, :input_html => {:size => nil}))
147
+ end)
148
+ end
149
+
150
+ it "should have no size attribute" do
151
+ output_buffer.should_not have_tag("input[@size]")
152
+ end
153
+ end
154
+
155
+ describe "when required" do
156
+
157
+ context "and configured to use HTML5 attribute" do
158
+ it "should add the required attribute to the input's html options" do
159
+ with_config :use_required_attribute, true do
160
+ concat(semantic_form_for(@new_post) do |builder|
161
+ concat(builder.input(:title, :as => :string, :required => true))
162
+ end)
163
+ output_buffer.should have_tag("input[@required]")
164
+ end
165
+ end
166
+ end
167
+
168
+ context "and configured to not use HTML5 attribute" do
169
+ it "should add the required attribute to the input's html options" do
170
+ with_config :use_required_attribute, false do
171
+ concat(semantic_form_for(@new_post) do |builder|
172
+ concat(builder.input(:title, :as => :string, :required => true))
173
+ end)
174
+ output_buffer.should_not have_tag("input[@required]")
175
+ end
176
+ end
177
+ end
178
+
179
+ end
180
+
181
+ end
182
+
@@ -0,0 +1,163 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'text input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
+
13
+ concat(semantic_form_for(@new_post) do |builder|
14
+ concat(builder.input(:body, :as => :text))
15
+ end)
16
+ end
17
+
18
+ it_should_have_input_wrapper_with_class("text")
19
+ it_should_have_input_wrapper_with_class(:clearfix)
20
+ it_should_have_input_class_in_the_right_place
21
+ it_should_have_input_wrapper_with_id("post_body_input")
22
+ it_should_have_label_with_text(/Body/)
23
+ it_should_have_label_for("post_body")
24
+ it_should_have_textarea_with_id("post_body")
25
+ it_should_have_textarea_with_name("post[body]")
26
+ it_should_apply_error_logic_for_input_type(:text)
27
+
28
+ it 'should use input_html to style inputs' do
29
+ output_buffer.replace ''
30
+ concat(semantic_form_for(@new_post) do |builder|
31
+ concat(builder.input(:title, :as => :text, :input_html => { :class => 'myclass' }))
32
+ end)
33
+ output_buffer.should have_tag("form div.clearfix div.input textarea.myclass")
34
+ end
35
+
36
+ it "should have a cols attribute when :cols is a number in :input_html" do
37
+ output_buffer.replace ''
38
+ concat(semantic_form_for(@new_post) do |builder|
39
+ concat(builder.input(:title, :as => :text, :input_html => { :cols => 42 }))
40
+ end)
41
+ output_buffer.should have_tag("form div.clearfix div.input textarea[@cols='42']")
42
+ end
43
+
44
+ it "should not have a cols attribute when :cols is nil in :input_html" do
45
+ output_buffer.replace ''
46
+ concat(semantic_form_for(@new_post) do |builder|
47
+ concat(builder.input(:title, :as => :text, :input_html => { :cols => nil }))
48
+ end)
49
+ output_buffer.should_not have_tag("form div.clearfix div.input textarea[@cols]")
50
+ end
51
+
52
+ it "should have a rows attribute when :rows is a number in :input_html" do
53
+ output_buffer.replace ''
54
+ concat(semantic_form_for(@new_post) do |builder|
55
+ concat(builder.input(:title, :as => :text, :input_html => { :rows => 42 }))
56
+ end)
57
+ output_buffer.should have_tag("form div.clearfix div.input textarea[@rows='42']")
58
+
59
+ end
60
+
61
+ it "should not have a rows attribute when :rows is nil in :input_html" do
62
+ output_buffer.replace ''
63
+ concat(semantic_form_for(@new_post) do |builder|
64
+ concat(builder.input(:title, :as => :text, :input_html => { :rows => nil }))
65
+ end)
66
+ output_buffer.should_not have_tag("form div.clearfix div.input textarea[@rows]")
67
+ end
68
+
69
+ describe "when namespace is provided" do
70
+
71
+ before do
72
+ @output_buffer = ''
73
+ mock_everything
74
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
75
+
76
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
77
+ concat(builder.input(:body, :as => :text))
78
+ end)
79
+ end
80
+
81
+ it_should_have_input_wrapper_with_id("context2_post_body_input")
82
+ it_should_have_textarea_with_id("context2_post_body")
83
+ it_should_have_label_for("context2_post_body")
84
+
85
+ end
86
+
87
+ context "when required" do
88
+ it "should add the required attribute to the input's html options" do
89
+ with_config :use_required_attribute, true do
90
+ concat(semantic_form_for(@new_post) do |builder|
91
+ concat(builder.input(:title, :as => :text, :required => true))
92
+ end)
93
+ output_buffer.should have_tag("textarea[@required]")
94
+ end
95
+ end
96
+ end
97
+
98
+ context "when :autofocus is provided in :input_html" do
99
+ before(:each) do
100
+ concat(semantic_form_for(@new_post) do |builder|
101
+ concat(builder.input(:title, :input_html => {:autofocus => true}))
102
+ end)
103
+ end
104
+
105
+ it_should_have_input_wrapper_with_class("autofocus")
106
+
107
+ it "should add the autofocus attribute to the input's html options" do
108
+ output_buffer.should have_tag("input[@autofocus]")
109
+ end
110
+ end
111
+
112
+ context "when :rows is missing in :input_html" do
113
+ before do
114
+ output_buffer.replace ''
115
+ end
116
+
117
+ it "should have a rows attribute matching default_text_area_height if numeric" do
118
+ with_config :default_text_area_height, 12 do
119
+ concat(semantic_form_for(@new_post) do |builder|
120
+ concat(builder.input(:title, :as => :text))
121
+ end)
122
+ output_buffer.should have_tag("form div.clearfix div.input textarea[@rows='12']")
123
+ end
124
+ end
125
+
126
+ it "should not have a rows attribute if default_text_area_height is nil" do
127
+ with_config :default_text_area_height, nil do
128
+ concat(semantic_form_for(@new_post) do |builder|
129
+ concat(builder.input(:title, :as => :text))
130
+ end)
131
+ output_buffer.should_not have_tag("form div.clearfix div.input textarea[@rows]")
132
+ end
133
+
134
+ end
135
+ end
136
+
137
+ context "when :cols is missing in :input_html" do
138
+ before do
139
+ output_buffer.replace ''
140
+ end
141
+
142
+ it "should have a cols attribute matching default_text_area_width if numeric" do
143
+ with_config :default_text_area_width, 10 do
144
+ concat(semantic_form_for(@new_post) do |builder|
145
+ concat(builder.input(:title, :as => :text))
146
+ end)
147
+ output_buffer.should have_tag("form div.clearfix div.input textarea[@cols='10']")
148
+ end
149
+ end
150
+
151
+ it "should not have a cols attribute if default_text_area_width is nil" do
152
+ with_config :default_text_area_width, nil do
153
+ concat(semantic_form_for(@new_post) do |builder|
154
+ concat(builder.input(:title, :as => :text))
155
+ end)
156
+ output_buffer.should_not have_tag("form div.clearfix div.input textarea[@cols]")
157
+ end
158
+
159
+ end
160
+ end
161
+
162
+ end
163
+
@@ -0,0 +1,206 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'time input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
+ end
13
+
14
+ describe "general" do
15
+ before do
16
+ ::I18n.backend.reload!
17
+ output_buffer.replace ''
18
+ end
19
+
20
+ # describe "with :ignore_date => true" do
21
+ # before do
22
+ # concat(semantic_form_for(@new_post) do |builder|
23
+ # concat(builder.input(:publish_at, :as => :time, :ignore_date => true))
24
+ # end)
25
+ # end
26
+ #
27
+ # it 'should not have hidden inputs for day, month and year' do
28
+ # output_buffer.should_not have_tag('input#post_publish_at_1i')
29
+ # output_buffer.should_not have_tag('input#post_publish_at_2i')
30
+ # output_buffer.should_not have_tag('input#post_publish_at_3i')
31
+ # end
32
+ #
33
+ # it 'should have an input for hour and minute' do
34
+ # output_buffer.should have_tag('select#post_publish_at_4i')
35
+ # output_buffer.should have_tag('select#post_publish_at_5i')
36
+ # end
37
+ #
38
+ # end
39
+ #
40
+ # describe "with :ignore_date => false" do
41
+ # before do
42
+ # @new_post.stub(:publish_at).and_return(Time.parse('2010-11-07'))
43
+ # concat(semantic_form_for(@new_post) do |builder|
44
+ # concat(builder.input(:publish_at, :as => :time, :ignore_date => false))
45
+ # end)
46
+ # end
47
+ #
48
+ # it 'should have a hidden input for day, month and year' do
49
+ # output_buffer.should have_tag('input#post_publish_at_1i')
50
+ # output_buffer.should have_tag('input#post_publish_at_2i')
51
+ # output_buffer.should have_tag('input#post_publish_at_3i')
52
+ # output_buffer.should have_tag('input#post_publish_at_1i[@value="2010"]')
53
+ # output_buffer.should have_tag('input#post_publish_at_2i[@value="11"]')
54
+ # output_buffer.should have_tag('input#post_publish_at_3i[@value="7"]')
55
+ # end
56
+ #
57
+ # it 'should have an select for hour and minute' do
58
+ # output_buffer.should have_tag('select#post_publish_at_4i')
59
+ # output_buffer.should have_tag('select#post_publish_at_5i')
60
+ # end
61
+ #
62
+ # end
63
+
64
+ describe "without seconds" do
65
+ before do
66
+ concat(semantic_form_for(@new_post) do |builder|
67
+ concat(builder.input(:publish_at, :as => :time))
68
+ end)
69
+ end
70
+
71
+ it_should_have_input_wrapper_with_class("time")
72
+ it_should_have_input_wrapper_with_class(:clearfix)
73
+ it_should_have_input_wrapper_with_class(:stringish)
74
+ it_should_have_input_class_in_the_right_place
75
+ it_should_have_input_wrapper_with_id("post_publish_at_input")
76
+ it_should_have_a_nested_div
77
+ it_should_apply_error_logic_for_input_type(:time)
78
+
79
+ it 'should have a legend and label with the label text inside the fieldset' do
80
+ output_buffer.should have_tag('form div.clearfix.time label', /Publish at/)
81
+ end
82
+
83
+ # TODO Is this right?
84
+ it 'should (sort of) associate the label with the input' do
85
+ output_buffer.should have_tag('form div.clearfix.time label[@for="post_publish_at"]')
86
+ output_buffer.should have_tag('form div.clearfix.time div.input input[@id="post_publish_at[time]"]')
87
+ end
88
+
89
+ it 'should have an text input inside the div' do
90
+ output_buffer.should have_tag('form div.clearfix.time div.input input[@type="text"]')
91
+ end
92
+
93
+ # it 'should have five labels for hour and minute' do
94
+ # output_buffer.should have_tag('form li.time fieldset ol li label', :count => 2)
95
+ # output_buffer.should have_tag('form li.time fieldset ol li label', /hour/i)
96
+ # output_buffer.should have_tag('form li.time fieldset ol li label', /minute/i)
97
+ # end
98
+ #
99
+ # it 'should have two selects for hour and minute' do
100
+ # output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
101
+ # end
102
+ end
103
+
104
+ describe "with seconds" do
105
+ before do
106
+ concat(semantic_form_for(@new_post) do |builder|
107
+ concat(builder.input(:publish_at, :as => :time, :include_seconds => true))
108
+ end)
109
+ end
110
+
111
+ # it 'should have five labels for hour and minute' do
112
+ # output_buffer.should have_tag('form li.time fieldset ol li label', :count => 3)
113
+ # output_buffer.should have_tag('form li.time fieldset ol li label', /hour/i)
114
+ # output_buffer.should have_tag('form li.time fieldset ol li label', /minute/i)
115
+ # output_buffer.should have_tag('form li.time fieldset ol li label', /second/i)
116
+ # end
117
+
118
+ it 'should not have three selects for hour, minute and seconds' do
119
+ output_buffer.should_not have_tag('form li.time fieldset ol li', :count => 3)
120
+ end
121
+
122
+ # it 'should generate a sanitized label and matching ids for attribute' do
123
+ # 4.upto(6) do |i|
124
+ # output_buffer.should have_tag("form li fieldset ol li label[@for='post_publish_at_#{i}i']")
125
+ # output_buffer.should have_tag("form li fieldset ol li #post_publish_at_#{i}i")
126
+ # end
127
+ # end
128
+ end
129
+ end
130
+
131
+ # Ignore these since we only create the main label.
132
+
133
+ # describe ':labels option' do
134
+ # fields = [:hour, :minute, :second]
135
+ # fields.each do |field|
136
+ # it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
137
+ # output_buffer.replace ''
138
+ # concat(semantic_form_for(@new_post) do |builder|
139
+ # concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => "another #{field} label" }))
140
+ # end)
141
+ # output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length)
142
+ # fields.each do |f|
143
+ # output_buffer.should have_tag('form li.time fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
144
+ # end
145
+ # end
146
+ #
147
+ # it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
148
+ # output_buffer.replace ''
149
+ # concat(semantic_form_for(@new_post) do |builder|
150
+ # concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => "" }))
151
+ # end)
152
+ # output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length-1)
153
+ # fields.each do |f|
154
+ # output_buffer.should have_tag('form li.time fieldset ol li label', /#{f}/i) unless field == f
155
+ # end
156
+ # end
157
+ #
158
+ # it "should not render the label when :labels[:#{field}] is false" do
159
+ # output_buffer.replace ''
160
+ # concat(semantic_form_for(@new_post) do |builder|
161
+ # concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => false }))
162
+ # end)
163
+ # output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length-1)
164
+ # fields.each do |f|
165
+ # output_buffer.should have_tag('form li.time fieldset ol li label', /#{f}/i) unless field == f
166
+ # end
167
+ # end
168
+ #
169
+ # it "should not render unsafe HTML when :labels[:#{field}] is false" do
170
+ # output_buffer.replace ''
171
+ # concat(semantic_form_for(@new_post) do |builder|
172
+ # concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => false }))
173
+ # end)
174
+ # output_buffer.should_not include(">")
175
+ # end
176
+ #
177
+ # end
178
+ # end
179
+
180
+ describe ':namespace option' do
181
+ before do
182
+ concat(semantic_form_for(@new_post, :namespace => 'form2') do |builder|
183
+ concat(builder.input(:publish_at, :as => :time))
184
+ end)
185
+ end
186
+
187
+ it 'should have a tag matching the namespace' do
188
+ output_buffer.should have_tag('#form2_post_publish_at_input')
189
+ output_buffer.should have_tag('input[@id="form2_post_publish_at[time]"]')
190
+ end
191
+ end
192
+
193
+ describe "when required" do
194
+ it "should add the required attribute to the input's html options" do
195
+ with_config :use_required_attribute, true do
196
+ concat(semantic_form_for(@new_post) do |builder|
197
+ concat(builder.input(:title, :as => :time, :required => true))
198
+ end)
199
+ # output_buffer.should have_tag("select[@required]", :count => 2)
200
+ # We only have one field.
201
+ output_buffer.should have_tag("input[@required]", :count => 1)
202
+ end
203
+ end
204
+ end
205
+
206
+ end