formtastic-bootstrap 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/README.md +11 -2
  2. data/VERSION +1 -1
  3. data/vendor/assets/stylesheets/formtastic-bootstrap.css +4 -0
  4. metadata +51 -154
  5. data/.rspec +0 -1
  6. data/Gemfile +0 -14
  7. data/Gemfile.lock +0 -131
  8. data/Rakefile +0 -49
  9. data/formtastic-bootstrap.gemspec +0 -166
  10. data/lib/action_view/helpers/text_field_date_helper.rb +0 -166
  11. data/lib/formtastic-bootstrap/actions.rb +0 -10
  12. data/lib/formtastic-bootstrap/actions/base.rb +0 -22
  13. data/lib/formtastic-bootstrap/actions/button_action.rb +0 -13
  14. data/lib/formtastic-bootstrap/actions/input_action.rb +0 -13
  15. data/lib/formtastic-bootstrap/actions/link_action.rb +0 -12
  16. data/lib/formtastic-bootstrap/engine.rb +0 -4
  17. data/lib/formtastic-bootstrap/form_builder.rb +0 -40
  18. data/lib/formtastic-bootstrap/helpers.rb +0 -17
  19. data/lib/formtastic-bootstrap/helpers/action_helper.rb +0 -12
  20. data/lib/formtastic-bootstrap/helpers/actions_helper.rb +0 -24
  21. data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +0 -35
  22. data/lib/formtastic-bootstrap/helpers/input_helper.rb +0 -12
  23. data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +0 -34
  24. data/lib/formtastic-bootstrap/inputs.rb +0 -36
  25. data/lib/formtastic-bootstrap/inputs/base.rb +0 -45
  26. data/lib/formtastic-bootstrap/inputs/base/choices.rb +0 -20
  27. data/lib/formtastic-bootstrap/inputs/base/collections.rb +0 -9
  28. data/lib/formtastic-bootstrap/inputs/base/errors.rb +0 -48
  29. data/lib/formtastic-bootstrap/inputs/base/grouped_collections.rb +0 -9
  30. data/lib/formtastic-bootstrap/inputs/base/hints.rb +0 -27
  31. data/lib/formtastic-bootstrap/inputs/base/html.rb +0 -21
  32. data/lib/formtastic-bootstrap/inputs/base/labelling.rb +0 -29
  33. data/lib/formtastic-bootstrap/inputs/base/numeric.rb +0 -9
  34. data/lib/formtastic-bootstrap/inputs/base/stringish.rb +0 -17
  35. data/lib/formtastic-bootstrap/inputs/base/timeish.rb +0 -55
  36. data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +0 -55
  37. data/lib/formtastic-bootstrap/inputs/boolean_input.rb +0 -29
  38. data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +0 -40
  39. data/lib/formtastic-bootstrap/inputs/date_input.rb +0 -10
  40. data/lib/formtastic-bootstrap/inputs/date_select_input.rb +0 -8
  41. data/lib/formtastic-bootstrap/inputs/datetime_input.rb +0 -10
  42. data/lib/formtastic-bootstrap/inputs/datetime_select_input.rb +0 -8
  43. data/lib/formtastic-bootstrap/inputs/email_input.rb +0 -15
  44. data/lib/formtastic-bootstrap/inputs/file_input.rb +0 -14
  45. data/lib/formtastic-bootstrap/inputs/hidden_input.rb +0 -12
  46. data/lib/formtastic-bootstrap/inputs/number_input.rb +0 -15
  47. data/lib/formtastic-bootstrap/inputs/password_input.rb +0 -15
  48. data/lib/formtastic-bootstrap/inputs/phone_input.rb +0 -15
  49. data/lib/formtastic-bootstrap/inputs/radio_input.rb +0 -46
  50. data/lib/formtastic-bootstrap/inputs/range_input.rb +0 -15
  51. data/lib/formtastic-bootstrap/inputs/search_input.rb +0 -15
  52. data/lib/formtastic-bootstrap/inputs/select_input.rb +0 -16
  53. data/lib/formtastic-bootstrap/inputs/string_input.rb +0 -8
  54. data/lib/formtastic-bootstrap/inputs/text_input.rb +0 -14
  55. data/lib/formtastic-bootstrap/inputs/time_input.rb +0 -10
  56. data/lib/formtastic-bootstrap/inputs/time_select_input.rb +0 -8
  57. data/lib/formtastic-bootstrap/inputs/time_zone_input.rb +0 -14
  58. data/lib/formtastic-bootstrap/inputs/url_input.rb +0 -14
  59. data/spec/actions/button_action_spec.rb +0 -63
  60. data/spec/actions/input_action_spec.rb +0 -59
  61. data/spec/actions/link_action_spec.rb +0 -92
  62. data/spec/builder/semantic_fields_for_spec.rb +0 -130
  63. data/spec/helpers/action_helper_spec.rb +0 -368
  64. data/spec/helpers/actions_helper_spec.rb +0 -147
  65. data/spec/helpers/input_helper_spec.rb +0 -935
  66. data/spec/helpers/inputs_helper_spec.rb +0 -636
  67. data/spec/inputs/boolean_input_spec.rb +0 -226
  68. data/spec/inputs/check_boxes_input_spec.rb +0 -454
  69. data/spec/inputs/date_select_input_spec.rb +0 -164
  70. data/spec/inputs/datetime_select_input_spec.rb +0 -112
  71. data/spec/inputs/deprecated_time_date_datetime_inputs_spec.rb +0 -48
  72. data/spec/inputs/email_input_spec.rb +0 -86
  73. data/spec/inputs/file_input_spec.rb +0 -90
  74. data/spec/inputs/hidden_input_spec.rb +0 -153
  75. data/spec/inputs/number_input_spec.rb +0 -816
  76. data/spec/inputs/password_input_spec.rb +0 -100
  77. data/spec/inputs/phone_input_spec.rb +0 -86
  78. data/spec/inputs/radio_input_spec.rb +0 -267
  79. data/spec/inputs/range_input_spec.rb +0 -506
  80. data/spec/inputs/search_input_spec.rb +0 -85
  81. data/spec/inputs/select_input_spec.rb +0 -624
  82. data/spec/inputs/string_input_spec.rb +0 -210
  83. data/spec/inputs/text_input_spec.rb +0 -188
  84. data/spec/inputs/time_select_input_spec.rb +0 -191
  85. data/spec/inputs/time_zone_input_spec.rb +0 -118
  86. data/spec/inputs/url_input_spec.rb +0 -86
  87. data/spec/spec_helper.rb +0 -30
  88. data/spec/support/custom_macros.rb +0 -537
  89. data/spec/support/fb_custom_macros.rb +0 -23
@@ -1,226 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe 'boolean 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(:allow_comments, :as => :boolean))
14
- end)
15
- end
16
-
17
- it_should_have_bootstrap_horizontal_wrapping
18
- it_should_have_bootstrap_controls_label_with("checkbox")
19
- it_should_have_input_wrapper_with_class("boolean")
20
- it_should_have_input_wrapper_with_class(:input)
21
- it_should_have_input_wrapper_with_id("post_allow_comments_input")
22
- it_should_apply_error_logic_for_input_type(:boolean)
23
-
24
- it 'should generate a label containing the input' do
25
- output_buffer.should_not have_tag('label.label')
26
- output_buffer.should have_tag('form div.control-group div.controls label', :count => 1)
27
- output_buffer.should have_tag('form div.control-group div.controls label.checkbox', :count => 1)
28
- output_buffer.should have_tag('form div.control-group div.controls label[@for="post_allow_comments"]')
29
- output_buffer.should have_tag('form div.control-group div.controls label', /Allow comments/)
30
- output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"]', :count => 1)
31
- output_buffer.should have_tag('form div.control-group input[@type="hidden"]', :count => 1)
32
- output_buffer.should_not have_tag('form div.control-group div.controls label input[@type="hidden"]', :count => 1) # invalid HTML5
33
- end
34
-
35
- it 'should not add a "name" attribute to the label' do
36
- output_buffer.should_not have_tag('form div.control-group div.controls label[@name]')
37
- end
38
-
39
- it 'should generate a checkbox input' do
40
- output_buffer.should have_tag('form div.control-group div.controls label input')
41
- output_buffer.should have_tag('form div.control-group div.controls label input#post_allow_comments')
42
- output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"]')
43
- output_buffer.should have_tag('form div.control-group div.controls label input[@name="post[allow_comments]"]')
44
- output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"][@value="1"]')
45
- end
46
-
47
- it 'should generate a checked input if object.method returns true' do
48
- output_buffer.should have_tag('form div.control-group div.controls label input[@checked="checked"]')
49
- output_buffer.should have_tag('form div.control-group input[@name="post[allow_comments]"]', :count => 2)
50
- output_buffer.should have_tag('form div.control-group div.controls input#post_allow_comments', :count => 1)
51
- end
52
-
53
- it 'should generate a checked input if :input_html is passed :checked => checked' do
54
- concat(semantic_form_for(@new_post) do |builder|
55
- concat(builder.input(:answer_comments, :as => :boolean, :input_html => {:checked => 'checked'}))
56
- end)
57
- output_buffer.should have_tag('form div.control-group div.controls label input[@checked="checked"]')
58
- end
59
-
60
- it 'should name the hidden input with the :name html_option' do
61
- concat(semantic_form_for(@new_post) do |builder|
62
- concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
63
- end)
64
-
65
- output_buffer.should have_tag('form div.control-group input[@type="checkbox"][@name="foo"]', :count => 1)
66
- output_buffer.should have_tag('form div.control-group input[@type="hidden"][@name="foo"]', :count => 1)
67
- end
68
-
69
- it 'should name the hidden input with the :name html_option' do
70
- concat(semantic_form_for(@new_post) do |builder|
71
- concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
72
- end)
73
-
74
- output_buffer.should have_tag('form div.control-group input[@type="checkbox"][@name="foo"]', :count => 1)
75
- output_buffer.should have_tag('form div.control-group input[@type="hidden"][@name="foo"]', :count => 1)
76
- end
77
-
78
- it "should generate a disabled input and hidden input if :input_html is passed :disabled => 'disabled' " do
79
- concat(semantic_form_for(@new_post) do |builder|
80
- concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:disabled => 'disabled'}))
81
- end)
82
- output_buffer.should have_tag('form div.control-group label.checkbox input[@disabled="disabled"]', :count => 1)
83
- output_buffer.should have_tag('form div.control-group input[@type="hidden"][@disabled="disabled"]', :count => 1)
84
- end
85
-
86
- it 'should generate an input[id] with matching label[for] when id passed in :input_html' do
87
- concat(semantic_form_for(@new_post) do |builder|
88
- concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:id => 'custom_id'}))
89
- end)
90
- output_buffer.should have_tag('form div.control-group div.controls label input[@id="custom_id"]')
91
- output_buffer.should have_tag('form div.control-group div.controls label[@for="custom_id"]')
92
- end
93
-
94
- it 'should allow checked and unchecked values to be sent' do
95
- concat(semantic_form_for(@new_post) do |builder|
96
- concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'checked', :unchecked_value => 'unchecked'))
97
- end)
98
- output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
99
- output_buffer.should have_tag('form div.control-group input[@type="hidden"][@value="unchecked"]')
100
- output_buffer.should_not have_tag('form div.control-group div.controls label input[@type="hidden"]') # invalid HTML5
101
- end
102
-
103
- it 'should generate a checked input if object.method returns checked value' do
104
- @new_post.stub!(:allow_comments).and_return('yes')
105
-
106
- concat(semantic_form_for(@new_post) do |builder|
107
- concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
108
- end)
109
-
110
- output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"][@value="yes"][@checked="checked"]')
111
- end
112
-
113
- it 'should not generate a checked input if object.method returns unchecked value' do
114
- @new_post.stub!(:allow_comments).and_return('no')
115
-
116
- concat(semantic_form_for(@new_post) do |builder|
117
- concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
118
- end)
119
-
120
- output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"][@value="yes"]:not([@checked])')
121
- end
122
-
123
- it 'should generate a checked input if object.method returns checked value' do
124
- @new_post.stub!(:allow_comments).and_return('yes')
125
-
126
- concat(semantic_form_for(@new_post) do |builder|
127
- concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
128
- end)
129
-
130
- output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"][@value="yes"][@checked="checked"]')
131
- end
132
-
133
- it 'should not generate a checked input if object.method returns unchecked value' do
134
- @new_post.stub!(:allow_comments).and_return('no')
135
-
136
- concat(semantic_form_for(@new_post) do |builder|
137
- concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
138
- end)
139
-
140
- output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"][@value="yes"]:not([@checked])')
141
- end
142
-
143
- it 'should generate a label and a checkbox even if no object is given' do
144
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
145
- concat(builder.input(:allow_comments, :as => :boolean))
146
- end)
147
-
148
- output_buffer.should have_tag('form div.control-group div.controls label[@for="project_allow_comments"]')
149
- output_buffer.should have_tag('form div.control-group div.controls label', /Allow comments/)
150
- output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"]')
151
-
152
- output_buffer.should have_tag('form div.control-group div.controls label input#project_allow_comments')
153
- output_buffer.should have_tag('form div.control-group div.controls label input[@type="checkbox"]')
154
- output_buffer.should have_tag('form div.control-group div.controls label input[@name="project[allow_comments]"]')
155
- end
156
-
157
- context "when required" do
158
-
159
- it "should add the required attribute to the input's html options" do
160
- with_config :use_required_attribute, true do
161
- concat(semantic_form_for(@new_post) do |builder|
162
- concat(builder.input(:title, :as => :boolean, :required => true))
163
- end)
164
- output_buffer.should have_tag("input[@required]")
165
- end
166
- end
167
-
168
- it "should not add the required attribute to the boolean fields input's html options" do
169
- with_config :use_required_attribute, true do
170
- concat(semantic_form_for(@new_post) do |builder|
171
- concat(builder.input(:title, :as => :boolean))
172
- end)
173
- output_buffer.should_not have_tag("input[@required]")
174
- end
175
- end
176
-
177
- end
178
-
179
- describe "when namespace is provided" do
180
-
181
- before do
182
- @output_buffer = ''
183
- mock_everything
184
-
185
- concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
186
- concat(builder.input(:allow_comments, :as => :boolean))
187
- end)
188
- end
189
-
190
- it_should_have_input_wrapper_with_id("context2_post_allow_comments_input")
191
- it_should_have_an_inline_label_for("context2_post_allow_comments")
192
-
193
- end
194
-
195
- describe "when index is provided" do
196
-
197
- before do
198
- @output_buffer = ''
199
- mock_everything
200
-
201
- concat(semantic_form_for(@new_post) do |builder|
202
- concat(builder.fields_for(:author, :index => 3) do |author|
203
- concat(author.input(:name, :as => :boolean))
204
- end)
205
- end)
206
- end
207
-
208
- it 'should index the id of the wrapper' do
209
- output_buffer.should have_tag("div#post_author_attributes_3_name_input")
210
- end
211
-
212
- it 'should index the id of the input tag' do
213
- output_buffer.should have_tag("input#post_author_attributes_3_name")
214
- end
215
-
216
- it 'should index the name of the hidden input' do
217
- output_buffer.should have_tag("input[@type='hidden'][@name='post[author_attributes][3][name]']")
218
- end
219
-
220
- it 'should index the name of the checkbox input' do
221
- output_buffer.should have_tag("input[@type='checkbox'][@name='post[author_attributes][3][name]']")
222
- end
223
-
224
- end
225
-
226
- end
@@ -1,454 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe 'check_boxes input' do
5
-
6
- include FormtasticSpecHelper
7
-
8
- describe 'for a has_many association' do
9
- before do
10
- @output_buffer = ''
11
- mock_everything
12
-
13
- concat(semantic_form_for(@fred) do |builder|
14
- concat(builder.input(:posts, :as => :check_boxes, :value_as_class => true, :required => true))
15
- end)
16
- end
17
-
18
- it_should_have_bootstrap_horizontal_wrapping
19
- it_should_have_input_wrapper_with_class("check_boxes")
20
- it_should_have_input_wrapper_with_class(:input)
21
- it_should_have_input_wrapper_with_id("author_posts_input")
22
- # it_should_have_a_nested_fieldset
23
- # it_should_have_a_nested_fieldset_with_class('choices')
24
- # it_should_have_a_nested_ordered_list_with_class('choices-group')
25
- it_should_have_bootstrap_controls_label_with("checkbox")
26
- it_should_apply_error_logic_for_input_type(:check_boxes)
27
- it_should_call_find_on_association_class_when_no_collection_is_provided(:check_boxes)
28
- it_should_use_the_collection_when_provided(:check_boxes, 'input[@type="checkbox"]')
29
-
30
- it 'should generate a control label with text for the input' do
31
- output_buffer.should have_tag('form div.control-group > label.control-label')
32
- output_buffer.should have_tag('form div.control-group > label.control-label', /Posts/)
33
- end
34
-
35
- it 'should not link the label within the legend to any input' do
36
- output_buffer.should_not have_tag('form div.control-group > label[@for^="author_post_ids_"]')
37
- end
38
-
39
- it 'should not generate an ordered list with an li.choice for each choice' do
40
- output_buffer.should_not have_tag('form li fieldset ol')
41
- output_buffer.should_not have_tag('form li fieldset ol li.choice input[@type=checkbox]', :count => ::Post.all.size)
42
- end
43
-
44
- it 'should have one option with a "checked" attribute' do
45
- output_buffer.should have_tag('form div.control-group div.controls input[@checked]', :count => 1)
46
- end
47
-
48
- it 'should not generate hidden inputs with default value blank' do
49
- output_buffer.should_not have_tag("form div.control-group div.controls label input[@type='hidden'][@value='']")
50
- end
51
-
52
- it 'should not render hidden inputs inside div.controls' do
53
- output_buffer.should_not have_tag("form div.controls input[@type='hidden']")
54
- end
55
-
56
- it 'should render one hidden input for each choice outside the ol' do
57
- output_buffer.should have_tag("form div.control-group > input[@type='hidden']", :count => 1)
58
- end
59
-
60
- describe "each choice" do
61
-
62
- it 'should not give the choice label the label class' do
63
- output_buffer.should_not have_tag('div.controls label.label')
64
- end
65
-
66
- it 'should not be marked as required' do
67
- output_buffer.should_not have_tag('div.controls input[@required]')
68
- end
69
-
70
- it 'should contain a label for the radio input with a nested input and label text' do
71
- ::Post.all.each do |post|
72
- output_buffer.should have_tag('form div.control-group div.controls label', /#{post.to_label}/)
73
- output_buffer.should have_tag("form div.control-group div.controls label[@for='author_post_ids_#{post.id}']")
74
- end
75
- end
76
-
77
- it 'should use values as label.class when value_as_class is true' do
78
- ::Post.all.each do |post|
79
- output_buffer.should have_tag("form div.control-group div.controls label.post_#{post.id}")
80
- end
81
- end
82
-
83
- it 'should have a checkbox input but no hidden field for each post' do
84
- ::Post.all.each do |post|
85
- output_buffer.should have_tag("form div.control-group div.controls label input#author_post_ids_#{post.id}")
86
- output_buffer.should have_tag("form div.control-group div.controls label input[@name='author[post_ids][]']", :count => 1)
87
- end
88
- end
89
-
90
- it 'should have a hidden field with an empty array value for the collection to allow clearing of all checkboxes' do
91
- output_buffer.should have_tag("form div.control-group > input[@type=hidden][@name='author[post_ids][]'][@value='']", :count => 1)
92
- end
93
-
94
- it 'the hidden field with an empty array value should be followed by the div.controls' do
95
- output_buffer.should have_tag("form div.control-group > input[@type=hidden][@name='author[post_ids][]'][@value=''] + div.controls", :count => 1)
96
- end
97
-
98
- it 'should not have a hidden field with an empty string value for the collection' do
99
- output_buffer.should_not have_tag("form div.control-group > input[@type=hidden][@name='author[post_ids]'][@value='']", :count => 1)
100
- end
101
-
102
- it 'should have a checkbox and a hidden field for each post with :hidden_field => true' do
103
- output_buffer.replace ''
104
-
105
- concat(semantic_form_for(@fred) do |builder|
106
- concat(builder.input(:posts, :as => :check_boxes, :hidden_fields => true, :value_as_class => true))
107
- end)
108
-
109
- ::Post.all.each do |post|
110
- output_buffer.should have_tag("form div.control-group div.controls label input#author_post_ids_#{post.id}")
111
- output_buffer.should have_tag("form div.control-group div.controls label input[@name='author[post_ids][]']", :count => 2)
112
- end
113
-
114
- end
115
-
116
- it "should mark input as checked if it's the the existing choice" do
117
- ::Post.all.include?(@fred.posts.first).should be_true
118
- output_buffer.should have_tag("form div.control-group div.controls label input[@checked='checked']")
119
- end
120
- end
121
-
122
- describe 'and no object is given' do
123
- before(:each) do
124
- output_buffer.replace ''
125
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
126
- concat(builder.input(:author_id, :as => :check_boxes, :collection => ::Author.all))
127
- end)
128
- end
129
-
130
- it 'should not generate a fieldset with legend' do
131
- output_buffer.should_not have_tag('form li fieldset legend', /Author/)
132
- end
133
-
134
- it 'should generate a div.control-group with a label' do
135
- output_buffer.should have_tag('form div.control-group label.control-label', /Author/)
136
- end
137
-
138
- it 'should not generate an li tag for each item in the collection' do
139
- output_buffer.should_not have_tag('form li fieldset ol li input[@type=checkbox]', :count => ::Author.all.size)
140
- end
141
-
142
- it 'should generate labels for each item' do
143
- ::Author.all.each do |author|
144
- output_buffer.should have_tag('form div.control-group div.controls label', /#{author.to_label}/)
145
- output_buffer.should have_tag("form div.control-group div.controls label[@for='project_author_id_#{author.id}']")
146
- end
147
- end
148
-
149
- it 'should generate inputs for each item' do
150
- ::Author.all.each do |author|
151
- output_buffer.should have_tag("form div.control-group div.controls label input#project_author_id_#{author.id}")
152
- output_buffer.should have_tag("form div.control-group div.controls label input[@type='checkbox']")
153
- output_buffer.should have_tag("form div.control-group div.controls label input[@value='#{author.id}']")
154
- output_buffer.should have_tag("form div.control-group div.controls label input[@name='project[author_id][]']")
155
- end
156
- end
157
-
158
- it 'should html escape the label string' do
159
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
160
- concat(builder.input(:author_id, :as => :check_boxes, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
161
- end)
162
-
163
- output_buffer.should have_tag('form div.control-group div.controls label') do |label|
164
- label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;$/
165
- end
166
- end
167
- end
168
-
169
- describe 'when :hidden_fields is set to false' do
170
- before do
171
- @output_buffer = ''
172
- mock_everything
173
-
174
- concat(semantic_form_for(@fred) do |builder|
175
- concat(builder.input(:posts, :as => :check_boxes, :value_as_class => true, :hidden_fields => false))
176
- end)
177
- end
178
-
179
- it 'should have a checkbox input for each post' do
180
- ::Post.all.each do |post|
181
- output_buffer.should have_tag("form div.control-group div.controls label input#author_post_ids_#{post.id}")
182
- output_buffer.should have_tag("form div.control-group div.controls label input[@name='author[post_ids][]']", :count => ::Post.all.length)
183
- end
184
- end
185
-
186
- it "should mark input as checked if it's the the existing choice" do
187
- ::Post.all.include?(@fred.posts.first).should be_true
188
- output_buffer.should have_tag("form div.control-group div.controls label input[@checked='checked']")
189
- end
190
-
191
- it 'should not generate empty hidden inputs' do
192
- output_buffer.should_not have_tag("form div.control-group div.controls label input[@type='hidden'][@value='']", :count => ::Post.all.length)
193
- end
194
- end
195
-
196
- describe 'when :disabled is set' do
197
- before do
198
- @output_buffer = ''
199
- end
200
-
201
- describe "no disabled items" do
202
- before do
203
- @new_post.stub!(:author_ids).and_return(nil)
204
-
205
- concat(semantic_form_for(@new_post) do |builder|
206
- concat(builder.input(:authors, :as => :check_boxes, :disabled => nil))
207
- end)
208
- end
209
-
210
- it 'should not have any disabled item(s)' do
211
- output_buffer.should_not have_tag("form div.control-group div.controls label input[@disabled='disabled']")
212
- end
213
- end
214
-
215
- describe "single disabled item" do
216
- before do
217
- @new_post.stub!(:author_ids).and_return(nil)
218
-
219
- concat(semantic_form_for(@new_post) do |builder|
220
- concat(builder.input(:authors, :as => :check_boxes, :disabled => @fred.id))
221
- end)
222
- end
223
-
224
- it "should have one item disabled; the specified one" do
225
- output_buffer.should have_tag("form div.control-group div.controls label input[@disabled='disabled']", :count => 1)
226
- output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_ids_#{@fred.id}']", /fred/i)
227
- output_buffer.should have_tag("form div.control-group div.controls label input[@disabled='disabled'][@value='#{@fred.id}']")
228
- end
229
- end
230
-
231
- describe "multiple disabled items" do
232
- before do
233
- @new_post.stub!(:author_ids).and_return(nil)
234
-
235
- concat(semantic_form_for(@new_post) do |builder|
236
- concat(builder.input(:authors, :as => :check_boxes, :disabled => [@bob.id, @fred.id]))
237
- end)
238
- end
239
-
240
- it "should have multiple items disabled; the specified ones" do
241
- output_buffer.should have_tag("form div.control-group div.controls label input[@disabled='disabled']", :count => 2)
242
- output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_ids_#{@bob.id}']", /bob/i)
243
- output_buffer.should have_tag("form div.control-group div.controls label input[@disabled='disabled'][@value='#{@bob.id}']")
244
- output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_ids_#{@fred.id}']", /fred/i)
245
- output_buffer.should have_tag("form div.control-group div.controls label input[@disabled='disabled'][@value='#{@fred.id}']")
246
- end
247
- end
248
-
249
- end
250
-
251
- describe "with i18n of the legend label" do
252
-
253
- before do
254
- ::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
255
- with_config :i18n_lookups_by_default, true do
256
- @new_post.stub!(:author_ids).and_return(nil)
257
- concat(semantic_form_for(@new_post) do |builder|
258
- concat(builder.input(:authors, :as => :check_boxes))
259
- end)
260
- end
261
- end
262
-
263
- after do
264
- ::I18n.backend.reload!
265
- end
266
-
267
- it "should do foo" do
268
- output_buffer.should have_tag("label.control-label", /Translated/)
269
- end
270
-
271
- end
272
-
273
- describe "when :label option is set" do
274
- before do
275
- @new_post.stub!(:author_ids).and_return(nil)
276
- concat(semantic_form_for(@new_post) do |builder|
277
- concat(builder.input(:authors, :as => :check_boxes, :label => 'The authors'))
278
- end)
279
- end
280
-
281
- it "should output the correct label title" do
282
- output_buffer.should have_tag("label.control-label", /The authors/)
283
- end
284
- end
285
-
286
- describe "when :label option is false" do
287
- before do
288
- @output_buffer = ''
289
- @new_post.stub!(:author_ids).and_return(nil)
290
- concat(semantic_form_for(@new_post) do |builder|
291
- concat(builder.input(:authors, :as => :check_boxes, :label => false))
292
- end)
293
- end
294
-
295
- it "should not output the legend" do
296
- output_buffer.should_not have_tag("label.control-label")
297
- end
298
-
299
- it "should not cause escaped HTML" do
300
- output_buffer.should_not include("&gt;")
301
- end
302
-
303
- end
304
-
305
- describe "when :required option is true" do
306
- before do
307
- @new_post.stub!(:author_ids).and_return(nil)
308
- concat(semantic_form_for(@new_post) do |builder|
309
- concat(builder.input(:authors, :as => :check_boxes, :required => true))
310
- end)
311
- end
312
-
313
- it "should output the correct label title" do
314
- output_buffer.should have_tag("label.control-label abbr")
315
- end
316
- end
317
-
318
- end
319
-
320
- describe 'for a has_and_belongs_to_many association' do
321
-
322
- before do
323
- @output_buffer = ''
324
- mock_everything
325
-
326
- concat(semantic_form_for(@freds_post) do |builder|
327
- concat(builder.input(:authors, :as => :check_boxes))
328
- end)
329
- end
330
-
331
- it 'should render checkboxes' do
332
- # I'm aware these two lines test the same thing
333
- output_buffer.should have_tag('input[type="checkbox"]', :count => 2)
334
- output_buffer.should have_tag('input[type="checkbox"]', :count => ::Author.all.size)
335
- end
336
-
337
- it 'should only select checkboxes that are present in the association' do
338
- # I'm aware these two lines test the same thing
339
- output_buffer.should have_tag('input[checked="checked"]', :count => 1)
340
- output_buffer.should have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
341
- end
342
-
343
- end
344
-
345
- describe 'for an association when a :collection is provided' do
346
- describe 'it should use the specified :member_value option' do
347
- before do
348
- @output_buffer = ''
349
- mock_everything
350
- end
351
-
352
- it 'to set the right input value' do
353
- item = mock('item')
354
- item.should_not_receive(:id)
355
- item.stub!(:custom_value).and_return('custom_value')
356
- item.should_receive(:custom_value).exactly(3).times
357
- @new_post.author.should_receive(:custom_value).exactly(1).times
358
- concat(semantic_form_for(@new_post) do |builder|
359
- concat(builder.input(:author, :as => :check_boxes, :member_value => :custom_value, :collection => [item, item, item]))
360
- end)
361
- output_buffer.should have_tag('input[@type=checkbox][@value="custom_value"]', :count => 3)
362
- end
363
- end
364
- end
365
-
366
- describe 'when :collection is provided as an array of arrays' do
367
- before do
368
- @output_buffer = ''
369
- mock_everything
370
- @fred.stub(:genres) { ['fiction', 'biography'] }
371
-
372
- concat(semantic_form_for(@fred) do |builder|
373
- concat(builder.input(:genres, :as => :check_boxes, :collection => [['Fiction', 'fiction'], ['Non-fiction', 'non_fiction'], ['Biography', 'biography']]))
374
- end)
375
- end
376
-
377
- it 'should check the correct checkboxes' do
378
- output_buffer.should have_tag("form div.control-group div.controls label input[@value='fiction'][@checked='checked']")
379
- output_buffer.should have_tag("form div.control-group div.controls label input[@value='biography'][@checked='checked']")
380
- end
381
- end
382
-
383
- describe "when namespace is provided" do
384
-
385
- before do
386
- @output_buffer = ''
387
- mock_everything
388
-
389
- concat(semantic_form_for(@fred, :namespace => "context2") do |builder|
390
- concat(builder.input(:posts, :as => :check_boxes))
391
- end)
392
- end
393
-
394
- it "should have a label for #context2_author_post_ids_19" do
395
- output_buffer.should have_tag("form div.control-group div.controls label[@for='context2_author_post_ids_19']")
396
- end
397
-
398
- it_should_have_input_with_id('context2_author_post_ids_19')
399
- it_should_have_input_wrapper_with_id("context2_author_posts_input")
400
- end
401
-
402
- describe "when index is provided" do
403
-
404
- before do
405
- @output_buffer = ''
406
- mock_everything
407
-
408
- concat(semantic_form_for(@fred) do |builder|
409
- concat(builder.fields_for(@fred.posts.first, :index => 3) do |author|
410
- concat(author.input(:authors, :as => :check_boxes))
411
- end)
412
- end)
413
- end
414
-
415
- it 'should index the id of the control-group wrapper' do
416
- output_buffer.should have_tag("div.control-group#author_post_3_authors_input")
417
- end
418
-
419
- it 'should index the id of the input tag' do
420
- output_buffer.should have_tag("input#author_post_3_author_ids_42")
421
- end
422
-
423
- it 'should index the name of the checkbox input' do
424
- output_buffer.should have_tag("input[@type='checkbox'][@name='author[post][3][author_ids][]']")
425
- end
426
-
427
- end
428
-
429
-
430
- describe "when collection is an array" do
431
- before do
432
- @output_buffer = ''
433
- @_collection = [["First", 1], ["Second", 2]]
434
- mock_everything
435
-
436
- concat(semantic_form_for(@fred) do |builder|
437
- concat(builder.input(:posts, :as => :check_boxes, :collection => @_collection))
438
- end)
439
- end
440
-
441
- it "should use array items for labels and values" do
442
- @_collection.each do |post|
443
- output_buffer.should have_tag('form div.control-group div.controls label', /#{post.first}/)
444
- output_buffer.should have_tag("form div.control-group div.controls label[@for='author_post_ids_#{post.last}']")
445
- end
446
- end
447
-
448
- it "should not check any items" do
449
- output_buffer.should have_tag('form li input[@checked]', :count => 0)
450
- end
451
- end
452
-
453
- end
454
-