speedo-formstrap 1.2.2 → 1.2.3

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.
Files changed (44) hide show
  1. data/Gemfile +0 -1
  2. data/README.md +4 -4
  3. data/Rakefile +1 -1
  4. data/VERSION +1 -1
  5. data/lib/speedo-formstrap/form_builder.rb +7 -5
  6. data/lib/speedo-formstrap/helpers.rb +3 -1
  7. data/lib/speedo-formstrap/helpers/buttons_helper.rb +13 -9
  8. data/lib/speedo-formstrap/helpers/fieldset_wrapper.rb +11 -6
  9. data/lib/speedo-formstrap/helpers/inputs_helper.rb +4 -4
  10. data/lib/speedo-formstrap/inputs/base.rb +2 -1
  11. data/lib/speedo-formstrap/inputs/base/choices.rb +12 -23
  12. data/lib/speedo-formstrap/inputs/base/labelling.rb +16 -6
  13. data/lib/speedo-formstrap/inputs/base/timeish.rb +5 -12
  14. data/lib/speedo-formstrap/inputs/base/wrapping.rb +32 -14
  15. data/lib/speedo-formstrap/inputs/number_input.rb +2 -2
  16. data/lib/speedo-formstrap/inputs/radio_input.rb +13 -12
  17. data/lib/speedo-formstrap/inputs/range_input.rb +2 -2
  18. data/spec/builder/semantic_fields_for_spec.rb +16 -16
  19. data/spec/helpers/buttons_helper_spec.rb +56 -46
  20. data/spec/helpers/input_helper_spec.rb +209 -209
  21. data/spec/helpers/inputs_helper_spec.rb +117 -103
  22. data/spec/inputs/boolean_input_spec.rb +74 -46
  23. data/spec/inputs/check_boxes_input_spec.rb +110 -82
  24. data/spec/inputs/date_input_spec.rb +81 -15
  25. data/spec/inputs/datetime_input_spec.rb +13 -13
  26. data/spec/inputs/email_input_spec.rb +34 -6
  27. data/spec/inputs/file_input_spec.rb +34 -6
  28. data/spec/inputs/hidden_input_spec.rb +41 -13
  29. data/spec/inputs/number_input_spec.rb +127 -97
  30. data/spec/inputs/password_input_spec.rb +34 -6
  31. data/spec/inputs/phone_input_spec.rb +34 -6
  32. data/spec/inputs/radio_input_spec.rb +73 -45
  33. data/spec/inputs/range_input_spec.rb +94 -66
  34. data/spec/inputs/search_input_spec.rb +33 -6
  35. data/spec/inputs/select_input_spec.rb +124 -78
  36. data/spec/inputs/string_input_spec.rb +67 -22
  37. data/spec/inputs/text_input_spec.rb +42 -15
  38. data/spec/inputs/time_input_spec.rb +23 -23
  39. data/spec/inputs/time_zone_input_spec.rb +20 -20
  40. data/spec/inputs/url_input_spec.rb +34 -6
  41. data/spec/support/custom_macros.rb +67 -196
  42. data/spec/support/formtastic_spec_helper.rb +22 -6
  43. data/speedo-formstrap.gemspec +2 -2
  44. metadata +17 -17
@@ -8,50 +8,48 @@ describe 'boolean input' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = SpeedoFormstrap::FormBuilder
11
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
12
12
 
13
13
  concat(semantic_form_for(@new_post) do |builder|
14
14
  concat(builder.input(:allow_comments, :as => :boolean))
15
15
  end)
16
16
  end
17
17
 
18
- it_should_have_input_wrapper_with_class("boolean")
19
- it_should_have_input_wrapper_with_class(:clearfix)
18
+ it_should_have_input_wrapper_with_class("boolean-wrapper")
19
+ it_should_have_input_wrapper_with_class("control-group")
20
20
  it_should_have_input_class_in_the_right_place
21
21
  it_should_have_input_wrapper_with_id("post_allow_comments_input")
22
22
  it_should_apply_error_logic_for_input_type(:boolean, :block)
23
23
 
24
24
  it 'should generate a label containing the input' do
25
- output_buffer.should_not have_tag('label.label')
26
-
27
-
28
- output_buffer.should have_tag('form div.clearfix div.input ul li label', :count => 1)
29
- output_buffer.should have_tag('form div.clearfix div.input ul li label[@for="post_allow_comments"]')
30
- output_buffer.should have_tag('form div.clearfix div.input ul li label', /Allow comments/)
31
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"]', :count => 1)
32
- output_buffer.should have_tag('form div.clearfix input[@type="hidden"]', :count => 1)
33
- output_buffer.should_not have_tag('form div.clearfix label input[@type="hidden"]', :count => 1) # invalid HTML5
25
+ output_buffer.should have_tag('label.control-label')
26
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox', :count => 1)
27
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox[@for="post_allow_comments"]')
28
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox', /Allow comments/)
29
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@type="checkbox"]', :count => 1)
30
+ output_buffer.should have_tag('form div.control-group input[@type="hidden"]', :count => 1)
31
+ output_buffer.should_not have_tag('form div.control-group label input[@type="hidden"]', :count => 1) # invalid HTML5
34
32
  end
35
33
 
36
34
  it 'should generate a checkbox input' do
37
- output_buffer.should have_tag('form div.clearfix div.input ul li label input')
38
- output_buffer.should have_tag('form div.clearfix div.input ul li label input#post_allow_comments')
39
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"]')
40
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@name="post[allow_comments]"]')
41
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"][@value="1"]')
35
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input')
36
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input#post_allow_comments')
37
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@type="checkbox"]')
38
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@name="post[allow_comments]"]')
39
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@type="checkbox"][@value="1"]')
42
40
  end
43
41
 
44
42
  it 'should generate a checked input if object.method returns true' do
45
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@checked="checked"]')
46
- output_buffer.should have_tag('form div.clearfix input[@name="post[allow_comments]"]', :count => 2)
47
- output_buffer.should have_tag('form div.clearfix div.input ul li input#post_allow_comments', :count => 1)
43
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@checked="checked"]')
44
+ output_buffer.should have_tag('form div.control-group input[@name="post[allow_comments]"]', :count => 2)
45
+ output_buffer.should have_tag('form div.control-group div.controls input#post_allow_comments', :count => 1)
48
46
  end
49
47
 
50
48
  it 'should generate a checked input if :input_html is passed :checked => checked' do
51
49
  concat(semantic_form_for(@new_post) do |builder|
52
50
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => {:checked => 'checked'}))
53
51
  end)
54
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@checked="checked"]')
52
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@checked="checked"]')
55
53
  end
56
54
 
57
55
  it 'should name the hidden input with the :name html_option' do
@@ -59,8 +57,8 @@ describe 'boolean input' do
59
57
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
60
58
  end)
61
59
 
62
- output_buffer.should have_tag('form div.clearfix div.input ul li input[@type="checkbox"][@name="foo"]', :count => 1)
63
- output_buffer.should have_tag('form div.clearfix input[@type="hidden"][@name="foo"]', :count => 1)
60
+ output_buffer.should have_tag('form div.control-group div.controls input[@type="checkbox"][@name="foo"]', :count => 1)
61
+ output_buffer.should have_tag('form div.control-group input[@type="hidden"][@name="foo"]', :count => 1)
64
62
  end
65
63
 
66
64
  it 'should name the hidden input with the :name html_option' do
@@ -68,33 +66,33 @@ describe 'boolean input' do
68
66
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
69
67
  end)
70
68
 
71
- output_buffer.should have_tag('form div.clearfix div.input ul li input[@type="checkbox"][@name="foo"]', :count => 1)
72
- output_buffer.should have_tag('form div.clearfix input[@type="hidden"][@name="foo"]', :count => 1)
69
+ output_buffer.should have_tag('form div.control-group div.controls input[@type="checkbox"][@name="foo"]', :count => 1)
70
+ output_buffer.should have_tag('form div.control-group input[@type="hidden"][@name="foo"]', :count => 1)
73
71
  end
74
72
 
75
73
  it "should generate a disabled input and hidden input if :input_html is passed :disabled => 'disabled' " do
76
74
  concat(semantic_form_for(@new_post) do |builder|
77
75
  concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:disabled => 'disabled'}))
78
76
  end)
79
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@disabled="disabled"]', :count => 1)
80
- output_buffer.should have_tag('form div.clearfix input[@type="hidden"][@disabled="disabled"]', :count => 1)
77
+ output_buffer.should have_tag('form div.control-group div.controls label input[@disabled="disabled"]', :count => 1)
78
+ output_buffer.should have_tag('form div.control-group input[@type="hidden"][@disabled="disabled"]', :count => 1)
81
79
  end
82
80
 
83
81
  it 'should generate an input[id] with matching label[for] when id passed in :input_html' do
84
82
  concat(semantic_form_for(@new_post) do |builder|
85
83
  concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:id => 'custom_id'}))
86
84
  end)
87
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@id="custom_id"]')
88
- output_buffer.should have_tag('form div.clearfix div.input ul li label[@for="custom_id"]')
85
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@id="custom_id"]')
86
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox[@for="custom_id"]')
89
87
  end
90
88
 
91
89
  it 'should allow checked and unchecked values to be sent' do
92
90
  concat(semantic_form_for(@new_post) do |builder|
93
91
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'checked', :unchecked_value => 'unchecked'))
94
92
  end)
95
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
96
- output_buffer.should have_tag('form div.clearfix input[@type="hidden"][@value="unchecked"]')
97
- output_buffer.should_not have_tag('form div.clearfix label input[@type="hidden"]') # invalid HTML5
93
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
94
+ output_buffer.should have_tag('form div.control-group input[@type="hidden"][@value="unchecked"]')
95
+ output_buffer.should_not have_tag('form div.control-group label.checkbox input[@type="hidden"]') # invalid HTML5
98
96
  end
99
97
 
100
98
  it 'should generate a checked input if object.method returns checked value' do
@@ -104,7 +102,7 @@ describe 'boolean input' do
104
102
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
105
103
  end)
106
104
 
107
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
105
+ output_buffer.should have_tag('form label.checkbox input[@type="checkbox"][@value="yes"][@checked="checked"]')
108
106
  end
109
107
 
110
108
  it 'should not generate a checked input if object.method returns unchecked value' do
@@ -114,7 +112,7 @@ describe 'boolean input' do
114
112
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
115
113
  end)
116
114
 
117
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"][@value="yes"]:not([@checked])')
115
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@type="checkbox"][@value="yes"]:not([@checked])')
118
116
  end
119
117
 
120
118
  it 'should generate a checked input if object.method returns checked value' do
@@ -124,7 +122,7 @@ describe 'boolean input' do
124
122
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
125
123
  end)
126
124
 
127
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
125
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@type="checkbox"][@value="yes"][@checked="checked"]')
128
126
  end
129
127
 
130
128
  it 'should not generate a checked input if object.method returns unchecked value' do
@@ -134,7 +132,7 @@ describe 'boolean input' do
134
132
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
135
133
  end)
136
134
 
137
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"][@value="yes"]:not([@checked])')
135
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@type="checkbox"][@value="yes"]:not([@checked])')
138
136
  end
139
137
 
140
138
  it 'should generate a label and a checkbox even if no object is given' do
@@ -142,17 +140,17 @@ describe 'boolean input' do
142
140
  concat(builder.input(:allow_comments, :as => :boolean))
143
141
  end)
144
142
 
145
- output_buffer.should have_tag('form div.clearfix div.input ul li label[@for="project_allow_comments"]')
146
- output_buffer.should have_tag('form div.clearfix div.input ul li label', /Allow comments/)
147
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"]')
143
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox[@for="project_allow_comments"]')
144
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox', /Allow comments/)
145
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@type="checkbox"]')
148
146
 
149
- output_buffer.should have_tag('form div.clearfix div.input ul li label input#project_allow_comments')
150
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@type="checkbox"]')
151
- output_buffer.should have_tag('form div.clearfix div.input ul li label input[@name="project[allow_comments]"]')
147
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input#project_allow_comments')
148
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@type="checkbox"]')
149
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@name="project[allow_comments]"]')
152
150
  end
153
151
 
154
152
  context "when required" do
155
-
153
+
156
154
  it "should add the required attribute to the input's html options" do
157
155
  with_config :use_required_attribute, true do
158
156
  concat(semantic_form_for(@new_post) do |builder|
@@ -161,7 +159,7 @@ describe 'boolean input' do
161
159
  output_buffer.should have_tag("input[@required]")
162
160
  end
163
161
  end
164
-
162
+
165
163
  it "should not add the required attribute to the boolean fields input's html options" do
166
164
  with_config :use_required_attribute, true do
167
165
  concat(semantic_form_for(@new_post) do |builder|
@@ -170,7 +168,7 @@ describe 'boolean input' do
170
168
  output_buffer.should_not have_tag("input[@required]")
171
169
  end
172
170
  end
173
-
171
+
174
172
  end
175
173
 
176
174
  describe "when namespace is provided" do
@@ -178,7 +176,7 @@ describe 'boolean input' do
178
176
  before do
179
177
  @output_buffer = ''
180
178
  mock_everything
181
- Formtastic::Helpers::FormHelper.builder = SpeedoFormstrap::FormBuilder
179
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
182
180
 
183
181
  concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
184
182
  concat(builder.input(:allow_comments, :as => :boolean))
@@ -190,4 +188,34 @@ describe 'boolean input' do
190
188
 
191
189
  end
192
190
 
191
+ describe "when index is provided" do
192
+
193
+ before do
194
+ @output_bugger = ''
195
+ mock_everything
196
+
197
+ concat(semantic_form_for(@new_post) do |builder|
198
+ concat(builder.fields_for(:author, :index => 3) do |author|
199
+ concat(author.input(:name, :as => :boolean))
200
+ end)
201
+ end)
202
+ end
203
+
204
+ it 'should index the id of the wrapper' do
205
+ output_buffer.should have_tag("div#post_author_attributes_3_name_input")
206
+ end
207
+
208
+ it 'should index the id of the input tag' do
209
+ output_buffer.should have_tag("input#post_author_attributes_3_name")
210
+ end
211
+
212
+ it 'should index the name of the hidden input' do
213
+ output_buffer.should have_tag("input[@type='hidden'][@name='post[author_attributes][3][name]']")
214
+ end
215
+
216
+ it 'should index the name of the checkbox input' do
217
+ output_buffer.should have_tag("input[@type='checkbox'][@name='post[author_attributes][3][name]']")
218
+ end
219
+ end
220
+
193
221
  end
@@ -9,109 +9,109 @@ describe 'check_boxes input' do
9
9
  before do
10
10
  @output_buffer = ''
11
11
  mock_everything
12
- Formtastic::Helpers::FormHelper.builder = SpeedoFormstrap::FormBuilder
13
-
12
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
13
+
14
14
  concat(semantic_form_for(@fred) do |builder|
15
15
  concat(builder.input(:posts, :as => :check_boxes, :value_as_class => true, :required => true))
16
16
  end)
17
17
  end
18
18
 
19
- it_should_have_input_wrapper_with_class("check_boxes")
20
- it_should_have_input_wrapper_with_class(:clearfix)
19
+ it_should_have_input_wrapper_with_class("check_boxes-wrapper")
20
+ it_should_have_input_wrapper_with_class("control-group")
21
21
  it_should_have_input_class_in_the_right_place
22
22
  it_should_have_input_wrapper_with_id("author_posts_input")
23
23
  it_should_have_a_nested_div
24
- it_should_have_a_nested_div_with_class('choices.input')
25
- it_should_have_a_nested_unordered_list_with_class('choices-group.inputs-list')
24
+ it_should_have_a_nested_div_with_class('choices.controls')
25
+ #it_should_have_a_nested_unordered_list_with_class('choices-group.inputs-list')
26
26
  it_should_apply_error_logic_for_input_type(:check_boxes, :block)
27
27
  it_should_call_find_on_association_class_when_no_collection_is_provided(:check_boxes)
28
28
  it_should_use_the_collection_when_provided(:check_boxes, 'input[@type="checkbox"]')
29
29
 
30
30
  # TODO Refactor out the next three tests and their bretheren in radio_input_spec
31
31
  it 'should generate a \'legend\' containing a label with text for the input' do
32
- output_buffer.should have_tag('form div.clearfix label')
33
- output_buffer.should have_tag('form div.clearfix label', /Posts/)
32
+ output_buffer.should have_tag('form div.control-group label.control-label')
33
+ output_buffer.should have_tag('form div.control-group label.control-label', /Posts/)
34
34
  end
35
35
 
36
36
  it 'should not link the \'legend\' label to any input' do
37
- output_buffer.should_not have_tag('form div.clearfix > label[@for]')
37
+ output_buffer.should_not have_tag('form div.control-group > label.control-label[@for]')
38
38
  end
39
39
 
40
- it 'should generate an unordered list with a list item for each choice' do
41
- output_buffer.should have_tag('form div.clearfix div.input ul')
42
- output_buffer.should have_tag('form div.clearfix div.input ul li.choice', :count => ::Post.all.size)
43
- end
40
+ # it 'should generate an unordered list with a list item for each choice' do
41
+ # output_buffer.should have_tag('form div.control-group div.controls ul')
42
+ # output_buffer.should have_tag('form div.control-group div.controls ul li.choice', :count => ::Post.all.size)
43
+ # end
44
44
 
45
45
  # it 'should generate a legend containing a label with text for the input' do
46
46
  # output_buffer.should have_tag('form li fieldset legend.label label')
47
47
  # output_buffer.should have_tag('form li fieldset legend.label label', /Posts/)
48
48
  # end
49
- #
49
+ #
50
50
  # it 'should not link the label within the legend to any input' do
51
51
  # output_buffer.should_not have_tag('form li fieldset legend label[@for^="author_post_ids_"]')
52
52
  # end
53
- #
53
+ #
54
54
  # it 'should generate an ordered list with an li.choice for each choice' do
55
55
  # output_buffer.should have_tag('form li fieldset ol')
56
56
  # output_buffer.should have_tag('form li fieldset ol li.choice input[@type=checkbox]', :count => ::Post.all.size)
57
57
  # end
58
58
 
59
59
  it 'should have one option with a "checked" attribute' do
60
- output_buffer.should have_tag('form li input[@checked]', :count => 1)
60
+ output_buffer.should have_tag('form .controls input[@checked]', :count => 1)
61
61
  end
62
62
 
63
63
  it 'should not generate hidden inputs with default value blank' do
64
- output_buffer.should_not have_tag("form div div ul li label input[@type='hidden'][@value='']")
64
+ output_buffer.should_not have_tag("form div div label input[@type='hidden'][@value='']")
65
65
  end
66
66
 
67
- it 'should not render hidden inputs inside the ol' do
68
- output_buffer.should_not have_tag("form div div ul li input[@type='hidden']")
69
- end
67
+ # it 'should not render hidden inputs inside the ol' do
68
+ # output_buffer.should_not have_tag("form div div ul li input[@type='hidden']")
69
+ # end
70
70
 
71
71
  it 'should render one hidden input for each choice outside the ol' do
72
- output_buffer.should have_tag("form div.clearfix > input[@type='hidden']", :count => 1)
72
+ output_buffer.should have_tag("form div.control-group > input[@type='hidden']", :count => 1)
73
73
  end
74
74
 
75
75
  describe "each choice" do
76
-
77
- it 'should not give the choice label the .label class' do
78
- output_buffer.should_not have_tag('li.choice label.label')
76
+
77
+ it 'should not give the choice label the .control-label class' do
78
+ output_buffer.should_not have_tag('div.controls label.control-label')
79
79
  end
80
-
80
+
81
81
  it 'should not be marked as required' do
82
- output_buffer.should_not have_tag('li.choice input[@required]')
82
+ output_buffer.should_not have_tag('div.checkbox input[@required]')
83
83
  end
84
-
84
+
85
85
  it 'should contain a label for the radio input with a nested input and label text' do
86
86
  ::Post.all.each do |post|
87
- output_buffer.should have_tag('form div.clearfix div.input ul li label', /#{post.to_label}/)
88
- output_buffer.should have_tag("form div.clearfix div.input ul li label[@for='author_post_ids_#{post.id}']")
87
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox', /#{post.to_label}/)
88
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox[@for='author_post_ids_#{post.id}']")
89
89
  end
90
90
  end
91
91
 
92
92
  it 'should use values as li.class when value_as_class is true' do
93
93
  ::Post.all.each do |post|
94
- output_buffer.should have_tag("form div.clearfix div.input ul li.post_#{post.id} label")
94
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox.post_#{post.id}")
95
95
  end
96
96
  end
97
-
97
+
98
98
  it 'should have a checkbox input but no hidden field for each post' do
99
99
  ::Post.all.each do |post|
100
- output_buffer.should have_tag("form div.clearfix div.input ul li label input#author_post_ids_#{post.id}")
101
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@name='author[post_ids][]']", :count => 1)
100
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input#author_post_ids_#{post.id}")
101
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@name='author[post_ids][]']", :count => 1)
102
102
  end
103
103
  end
104
104
 
105
105
  it 'should have a hidden field with an empty array value for the collection to allow clearing of all checkboxes' do
106
- output_buffer.should have_tag("form div.clearfix > input[@type=hidden][@name='author[post_ids][]'][@value='']", :count => 1)
106
+ output_buffer.should have_tag("form div.control-group > input[@type=hidden][@name='author[post_ids][]'][@value='']", :count => 1)
107
107
  end
108
108
 
109
- it 'the hidden field with an empty array value should be followed by the div.input and the ul' do
110
- output_buffer.should have_tag("form div.clearfix > input[@type=hidden][@name='author[post_ids][]'][@value=''] + div.input ul", :count => 1)
109
+ it 'the hidden field with an empty array value should be followed by the div.controls and the ul' do
110
+ output_buffer.should have_tag("form div.control-group > input[@type=hidden][@name='author[post_ids][]'][@value=''] + div.controls", :count => 1)
111
111
  end
112
112
 
113
113
  it 'should not have a hidden field with an empty string value for the collection' do
114
- output_buffer.should_not have_tag("form div.clearfix > input[@type=hidden][@name='author[post_ids]'][@value='']", :count => 1)
114
+ output_buffer.should_not have_tag("form div.control-group > input[@type=hidden][@name='author[post_ids]'][@value='']", :count => 1)
115
115
  end
116
116
 
117
117
  it 'should have a checkbox and a hidden field for each post with :hidden_field => true' do
@@ -122,15 +122,15 @@ describe 'check_boxes input' do
122
122
  end)
123
123
 
124
124
  ::Post.all.each do |post|
125
- output_buffer.should have_tag("form div.clearfix div.input ul li label input#author_post_ids_#{post.id}")
126
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@name='author[post_ids][]']", :count => 2)
125
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input#author_post_ids_#{post.id}")
126
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@name='author[post_ids][]']", :count => 2)
127
127
  end
128
128
 
129
129
  end
130
130
 
131
131
  it "should mark input as checked if it's the the existing choice" do
132
132
  ::Post.all.include?(@fred.posts.first).should be_true
133
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@checked='checked']")
133
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@checked='checked']")
134
134
  end
135
135
  end
136
136
 
@@ -143,26 +143,26 @@ describe 'check_boxes input' do
143
143
  end
144
144
 
145
145
  it 'should generate a top-level div with \'legend\'' do
146
- output_buffer.should have_tag('form div.clearfix > label', /Author/)
146
+ output_buffer.should have_tag('form div.control-group > label.control-label', /Author/)
147
147
  end
148
148
 
149
149
  it 'shold generate an li tag for each item in the collection' do
150
- output_buffer.should have_tag('form div.clearfix div.input ul li input[@type=checkbox]', :count => ::Author.all.size)
150
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox input[@type=checkbox]', :count => ::Author.all.size)
151
151
  end
152
152
 
153
153
  it 'should generate labels for each item' do
154
154
  ::Author.all.each do |author|
155
- output_buffer.should have_tag('form div.clearfix div.input ul li label', /#{author.to_label}/)
156
- output_buffer.should have_tag("form div.clearfix div.input ul li label[@for='project_author_id_#{author.id}']")
155
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox', /#{author.to_label}/)
156
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox[@for='project_author_id_#{author.id}']")
157
157
  end
158
158
  end
159
159
 
160
160
  it 'should generate inputs for each item' do
161
161
  ::Author.all.each do |author|
162
- output_buffer.should have_tag("form div.clearfix div.input ul li label input#project_author_id_#{author.id}")
163
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@type='checkbox']")
164
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@value='#{author.id}']")
165
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@name='project[author_id][]']")
162
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input#project_author_id_#{author.id}")
163
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@type='checkbox']")
164
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@value='#{author.id}']")
165
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@name='project[author_id][]']")
166
166
  end
167
167
  end
168
168
 
@@ -171,7 +171,7 @@ describe 'check_boxes input' do
171
171
  concat(builder.input(:author_id, :as => :check_boxes, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
172
172
  end)
173
173
 
174
- output_buffer.should have_tag('form div.clearfix div.input ul li label') do |label|
174
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox') do |label|
175
175
  # label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;$/
176
176
  label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;/
177
177
  end
@@ -190,18 +190,18 @@ describe 'check_boxes input' do
190
190
 
191
191
  it 'should have a checkbox input for each post' do
192
192
  ::Post.all.each do |post|
193
- output_buffer.should have_tag("form div.clearfix div.input ul li label input#author_post_ids_#{post.id}")
194
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@name='author[post_ids][]']", :count => ::Post.all.length)
193
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input#author_post_ids_#{post.id}")
194
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@name='author[post_ids][]']", :count => ::Post.all.length)
195
195
  end
196
196
  end
197
197
 
198
198
  it "should mark input as checked if it's the the existing choice" do
199
199
  ::Post.all.include?(@fred.posts.first).should be_true
200
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@checked='checked']")
200
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@checked='checked']")
201
201
  end
202
202
 
203
203
  it 'should not generate empty hidden inputs' do
204
- output_buffer.should_not have_tag("form div.clearfix div.input ul li label input[@type='hidden'][@value='']", :count => ::Post.all.length)
204
+ output_buffer.should_not have_tag("form div.control-group div.controls label.checkbox input[@type='hidden'][@value='']", :count => ::Post.all.length)
205
205
  end
206
206
  end
207
207
 
@@ -220,7 +220,7 @@ describe 'check_boxes input' do
220
220
  end
221
221
 
222
222
  it 'should not have any disabled item(s)' do
223
- output_buffer.should_not have_tag("form div.clearfix div.input ul li label input[@disabled='disabled']")
223
+ output_buffer.should_not have_tag("form div.control-group div.controls label.checkbox input[@disabled='disabled']")
224
224
  end
225
225
  end
226
226
 
@@ -234,9 +234,9 @@ describe 'check_boxes input' do
234
234
  end
235
235
 
236
236
  it "should have one item disabled; the specified one" do
237
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@disabled='disabled']", :count => 1)
238
- output_buffer.should have_tag("form div.clearfix div.input ul li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
239
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@disabled='disabled'][@value='#{@fred.id}']")
237
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@disabled='disabled']", :count => 1)
238
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox[@for='post_author_ids_#{@fred.id}']", /fred/i)
239
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@disabled='disabled'][@value='#{@fred.id}']")
240
240
  end
241
241
  end
242
242
 
@@ -250,11 +250,11 @@ describe 'check_boxes input' do
250
250
  end
251
251
 
252
252
  it "should have multiple items disabled; the specified ones" do
253
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@disabled='disabled']", :count => 2)
254
- output_buffer.should have_tag("form div.clearfix div.input ul li label[@for='post_author_ids_#{@bob.id}']", /bob/i)
255
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@disabled='disabled'][@value='#{@bob.id}']")
256
- output_buffer.should have_tag("form div.clearfix div.input ul li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
257
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@disabled='disabled'][@value='#{@fred.id}']")
253
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@disabled='disabled']", :count => 2)
254
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox[@for='post_author_ids_#{@bob.id}']", /bob/i)
255
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@disabled='disabled'][@value='#{@bob.id}']")
256
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox[@for='post_author_ids_#{@fred.id}']", /fred/i)
257
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@disabled='disabled'][@value='#{@fred.id}']")
258
258
  end
259
259
  end
260
260
 
@@ -277,7 +277,7 @@ describe 'check_boxes input' do
277
277
  end
278
278
 
279
279
  it "should do foo" do
280
- output_buffer.should have_tag("div.clearfix > label", /Translated/)
280
+ output_buffer.should have_tag("div.control-group > label.control-label", /Translated/)
281
281
  end
282
282
 
283
283
  end
@@ -291,7 +291,7 @@ describe 'check_boxes input' do
291
291
  end
292
292
 
293
293
  it "should output the correct label title" do
294
- output_buffer.should have_tag("div.clearfix > label", /The authors/)
294
+ output_buffer.should have_tag("div.control-group > label.control-label", /The authors/)
295
295
  end
296
296
  end
297
297
 
@@ -305,13 +305,13 @@ describe 'check_boxes input' do
305
305
  end
306
306
 
307
307
  it "should output an empty \'legend\'" do
308
- output_buffer.should have_tag("div.clearfix > label", "")
308
+ output_buffer.should have_tag("div.control-group > label.control-label", "")
309
309
  end
310
-
310
+
311
311
  it "should not cause escaped HTML" do
312
312
  output_buffer.should_not include("&gt;")
313
313
  end
314
-
314
+
315
315
  end
316
316
 
317
317
  describe "when :required option is true" do
@@ -323,7 +323,7 @@ describe 'check_boxes input' do
323
323
  end
324
324
 
325
325
  it "should output the correct label title" do
326
- output_buffer.should have_tag("div.clearfix > label abbr")
326
+ output_buffer.should have_tag("div.control-group > label.control-label abbr")
327
327
  end
328
328
  end
329
329
 
@@ -366,7 +366,7 @@ describe 'check_boxes input' do
366
366
  item.should_not_receive(:id)
367
367
  item.stub!(:custom_value).and_return('custom_value')
368
368
  item.should_receive(:custom_value).exactly(3).times
369
- @new_post.author.should_receive(:custom_value).exactly(3).times
369
+ @new_post.author.should_receive(:custom_value).exactly(1).times
370
370
  concat(semantic_form_for(@new_post) do |builder|
371
371
  concat(builder.input(:author, :as => :check_boxes, :member_value => :custom_value, :collection => [item, item, item]))
372
372
  end)
@@ -374,21 +374,21 @@ describe 'check_boxes input' do
374
374
  end
375
375
  end
376
376
  end
377
-
377
+
378
378
  describe 'when :collection is provided as an array of arrays' do
379
379
  before do
380
380
  @output_buffer = ''
381
381
  mock_everything
382
382
  @fred.stub(:genres) { ['fiction', 'biography'] }
383
-
383
+
384
384
  concat(semantic_form_for(@fred) do |builder|
385
385
  concat(builder.input(:genres, :as => :check_boxes, :collection => [['Fiction', 'fiction'], ['Non-fiction', 'non_fiction'], ['Biography', 'biography']]))
386
386
  end)
387
387
  end
388
-
388
+
389
389
  it 'should check the correct checkboxes' do
390
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@value='fiction'][@checked='checked']")
391
- output_buffer.should have_tag("form div.clearfix div.input ul li label input[@value='biography'][@checked='checked']")
390
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@value='fiction'][@checked='checked']")
391
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox input[@value='biography'][@checked='checked']")
392
392
  end
393
393
  end
394
394
 
@@ -402,22 +402,50 @@ describe 'check_boxes input' do
402
402
  concat(builder.input(:posts, :as => :check_boxes))
403
403
  end)
404
404
  end
405
-
405
+
406
406
  it "should have a label for #context2_author_post_ids_19" do
407
- output_buffer.should have_tag("form li label[@for='context2_author_post_ids_19']")
407
+ output_buffer.should have_tag("form label.checkbox[@for='context2_author_post_ids_19']")
408
408
  end
409
409
 
410
410
  it_should_have_input_with_id('context2_author_post_ids_19')
411
411
  it_should_have_input_wrapper_with_id("context2_author_posts_input")
412
412
  end
413
413
 
414
+ describe "when index is provided" do
415
+
416
+ before do
417
+ @output_buffer = ''
418
+ mock_everything
419
+
420
+ concat(semantic_form_for(@fred) do |builder|
421
+ concat(builder.fields_for(@fred.posts.first, :index => 3) do |author|
422
+ concat(author.input(:authors, :as => :check_boxes))
423
+ end)
424
+ end)
425
+ end
426
+
427
+ it 'should index the id of the wrapper' do
428
+ output_buffer.should have_tag("div#author_post_3_authors_input")
429
+ end
430
+
431
+ it 'should index the id of the input tag' do
432
+ output_buffer.should have_tag("input#author_post_3_author_ids_42")
433
+ end
434
+
435
+ it 'should index the name of the checkbox input' do
436
+ output_buffer.should have_tag("input[@type='checkbox'][@name='author[post][3][author_ids][]']")
437
+ end
438
+
439
+ end
440
+
441
+
414
442
  describe "when collection is an array" do
415
443
  before do
416
444
  @output_buffer = ''
417
445
  @_collection = [["First", 1], ["Second", 2]]
418
446
  mock_everything
419
- Formtastic::Helpers::FormHelper.builder = SpeedoFormstrap::FormBuilder
420
-
447
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
448
+
421
449
  concat(semantic_form_for(@fred) do |builder|
422
450
  concat(builder.input(:posts, :as => :check_boxes, :collection => @_collection))
423
451
  end)
@@ -425,15 +453,15 @@ describe 'check_boxes input' do
425
453
 
426
454
  it "should use array items for labels and values" do
427
455
  @_collection.each do |post|
428
- output_buffer.should have_tag('form div.clearfix div.input ul li label', /#{post.first}/)
429
- output_buffer.should have_tag("form div.clearfix div.input ul li label[@for='author_post_ids_#{post.last}']")
456
+ output_buffer.should have_tag('form div.control-group div.controls label.checkbox', /#{post.first}/)
457
+ output_buffer.should have_tag("form div.control-group div.controls label.checkbox[@for='author_post_ids_#{post.last}']")
430
458
  end
431
459
  end
432
460
 
433
461
  it "should not check any items" do
434
462
  output_buffer.should have_tag('form li input[@checked]', :count => 0)
435
- end
463
+ end
436
464
  end
437
-
465
+
438
466
  end
439
467