Skip to content
Newer
Older
100644 463 lines (366 sloc) 17 KB
0a59e0c @yabawock Always use # encoding: utf-8 declaration
yabawock authored
1 # encoding: utf-8
480e559 @yabawock Make tests use require 'spec_helper'
yabawock authored
2 require 'spec_helper'
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
3
4 describe 'check_boxes input' do
433dae2 @yabawock Whitespace Cleanup
yabawock authored
5
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
6 include FormtasticSpecHelper
433dae2 @yabawock Whitespace Cleanup
yabawock authored
7
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
8 describe 'for a has_many association' do
9 before do
f9c1a8a @yabawock Revert all the changes introduced in commits 8d17ca4..8d8c50
yabawock authored
10 @output_buffer = ''
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
11 mock_everything
a8489e9 @justinfrench whitepace
authored
12
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
13 concat(semantic_form_for(@fred) do |builder|
260674b @justinfrench Add the HTML5 required attribute to all inputs except HiddenInput, re…
authored
14 concat(builder.input(:posts, :as => :check_boxes, :value_as_class => true, :required => true))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
15 end)
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
16 end
a8489e9 @justinfrench whitepace
authored
17
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
18 it_should_have_input_wrapper_with_class("check_boxes")
3535c5f @justinfrench add an .input class to all inputs to allow easy styling of all of them
authored
19 it_should_have_input_wrapper_with_class(:input)
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
20 it_should_have_input_wrapper_with_id("author_posts_input")
21 it_should_have_a_nested_fieldset
105386d @justinfrench Heaps of new HTML classes (and using them in the CSS).
authored
22 it_should_have_a_nested_fieldset_with_class('choices')
23 it_should_have_a_nested_ordered_list_with_class('choices-group')
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
24 it_should_apply_error_logic_for_input_type(:check_boxes)
25 it_should_call_find_on_association_class_when_no_collection_is_provided(:check_boxes)
26 it_should_use_the_collection_when_provided(:check_boxes, 'input[@type="checkbox"]')
a8489e9 @justinfrench whitepace
authored
27
6f92fa4 @justinfrench Radio and checkbox inputs no longer have the legend label associated …
authored
28 it 'should generate a legend containing a label with text for the input' do
29 output_buffer.should have_tag('form li fieldset legend.label label')
30 output_buffer.should have_tag('form li fieldset legend.label label', /Posts/)
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
31 end
a8489e9 @justinfrench whitepace
authored
32
6f92fa4 @justinfrench Radio and checkbox inputs no longer have the legend label associated …
authored
33 it 'should not link the label within the legend to any input' do
34 output_buffer.should_not have_tag('form li fieldset legend label[@for^="author_post_ids_"]')
35 end
a8489e9 @justinfrench whitepace
authored
36
105386d @justinfrench Heaps of new HTML classes (and using them in the CSS).
authored
37 it 'should generate an ordered list with an li.choice for each choice' do
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
38 output_buffer.should have_tag('form li fieldset ol')
105386d @justinfrench Heaps of new HTML classes (and using them in the CSS).
authored
39 output_buffer.should have_tag('form li fieldset ol li.choice input[@type=checkbox]', :count => ::Post.all.size)
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
40 end
a8489e9 @justinfrench whitepace
authored
41
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
42 it 'should have one option with a "checked" attribute' do
43 output_buffer.should have_tag('form li input[@checked]', :count => 1)
44 end
a8489e9 @justinfrench whitepace
authored
45
beeb949 @yabawock Changing the default behaviour of check_boxes to suppress the rails
yabawock authored
46 it 'should not generate hidden inputs with default value blank' do
c6ad17f @justinfrench bulking up coverage for check_boxes input to ensure no hidden inputs …
authored
47 output_buffer.should_not have_tag("form li fieldset ol li label input[@type='hidden'][@value='']")
48 end
a8489e9 @justinfrench whitepace
authored
49
c6ad17f @justinfrench bulking up coverage for check_boxes input to ensure no hidden inputs …
authored
50 it 'should not render hidden inputs inside the ol' do
51 output_buffer.should_not have_tag("form li fieldset ol li input[@type='hidden']")
52 end
a8489e9 @justinfrench whitepace
authored
53
c6ad17f @justinfrench bulking up coverage for check_boxes input to ensure no hidden inputs …
authored
54 it 'should render one hidden input for each choice outside the ol' do
55 output_buffer.should have_tag("form li fieldset > input[@type='hidden']", :count => 1)
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
56 end
a8489e9 @justinfrench whitepace
authored
57
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
58 describe "each choice" do
14aef5f @justinfrench don't apply a .label class to <label> tags inside a .choice on radio …
authored
59
60 it 'should not give the choice label the .label class' do
61 output_buffer.should_not have_tag('li.choice label.label')
62 end
63
4eb72a8 @justinfrench don't add the required attribute to the choices in a :radio or :check…
authored
64 it 'should not be marked as required' do
65 output_buffer.should_not have_tag('li.choice input[@required]')
66 end
67
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
68 it 'should contain a label for the radio input with a nested input and label text' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
69 ::Post.all.each do |post|
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
70 output_buffer.should have_tag('form li fieldset ol li label', /#{post.to_label}/)
71 output_buffer.should have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.id}']")
72 end
73 end
a8489e9 @justinfrench whitepace
authored
74
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
75 it 'should use values as li.class when value_as_class is true' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
76 ::Post.all.each do |post|
ca12563 @grimen Replacing dependency rspec_hpricot_matchers (Hpricot) with rspec_tag_…
grimen authored
77 output_buffer.should have_tag("form li fieldset ol li.post_#{post.id} label")
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
78 end
79 end
260674b @justinfrench Add the HTML5 required attribute to all inputs except HiddenInput, re…
authored
80
beeb949 @yabawock Changing the default behaviour of check_boxes to suppress the rails
yabawock authored
81 it 'should have a checkbox input but no hidden field for each post' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
82 ::Post.all.each do |post|
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
83 output_buffer.should have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
beeb949 @yabawock Changing the default behaviour of check_boxes to suppress the rails
yabawock authored
84 output_buffer.should have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 1)
85 end
86 end
a8489e9 @justinfrench whitepace
authored
87
7a5120e @yabawock Make sure that the empty default value for check_boxes collections is…
yabawock authored
88 it 'should have a hidden field with an empty array value for the collection to allow clearing of all checkboxes' do
7b5ed06 @yabawock Output the hidden field for the check_boxes collection before the
yabawock authored
89 output_buffer.should have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value='']", :count => 1)
90 end
a8489e9 @justinfrench whitepace
authored
91
7b5ed06 @yabawock Output the hidden field for the check_boxes collection before the
yabawock authored
92 it 'the hidden field with an empty array value should be followed by the ol' do
93 output_buffer.should have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value=''] + ol", :count => 1)
7a5120e @yabawock Make sure that the empty default value for check_boxes collections is…
yabawock authored
94 end
a8489e9 @justinfrench whitepace
authored
95
7a5120e @yabawock Make sure that the empty default value for check_boxes collections is…
yabawock authored
96 it 'should not have a hidden field with an empty string value for the collection' do
7b5ed06 @yabawock Output the hidden field for the check_boxes collection before the
yabawock authored
97 output_buffer.should_not have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids]'][@value='']", :count => 1)
96a2e54 @yabawock Provide an empty default value for the form variable that's going to
yabawock authored
98 end
a8489e9 @justinfrench whitepace
authored
99
beeb949 @yabawock Changing the default behaviour of check_boxes to suppress the rails
yabawock authored
100 it 'should have a checkbox and a hidden field for each post with :hidden_field => true' do
101 output_buffer.replace ''
a8489e9 @justinfrench whitepace
authored
102
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
103 concat(semantic_form_for(@fred) do |builder|
beeb949 @yabawock Changing the default behaviour of check_boxes to suppress the rails
yabawock authored
104 concat(builder.input(:posts, :as => :check_boxes, :hidden_fields => true, :value_as_class => true))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
105 end)
a8489e9 @justinfrench whitepace
authored
106
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
107 ::Post.all.each do |post|
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
108 output_buffer.should have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
109 output_buffer.should have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 2)
110 end
a8489e9 @justinfrench whitepace
authored
111
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
112 end
a8489e9 @justinfrench whitepace
authored
113
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
114 it "should mark input as checked if it's the the existing choice" do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
115 ::Post.all.include?(@fred.posts.first).should be_true
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
116 output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']")
117 end
118 end
a8489e9 @justinfrench whitepace
authored
119
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
120 describe 'and no object is given' do
121 before(:each) do
122 output_buffer.replace ''
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
123 concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
124 concat(builder.input(:author_id, :as => :check_boxes, :collection => ::Author.all))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
125 end)
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
126 end
a8489e9 @justinfrench whitepace
authored
127
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
128 it 'should generate a fieldset with legend' do
129 output_buffer.should have_tag('form li fieldset legend', /Author/)
130 end
a8489e9 @justinfrench whitepace
authored
131
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
132 it 'shold generate an li tag for each item in the collection' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
133 output_buffer.should have_tag('form li fieldset ol li input[@type=checkbox]', :count => ::Author.all.size)
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
134 end
a8489e9 @justinfrench whitepace
authored
135
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
136 it 'should generate labels for each item' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
137 ::Author.all.each do |author|
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
138 output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
139 output_buffer.should have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
140 end
141 end
a8489e9 @justinfrench whitepace
authored
142
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
143 it 'should generate inputs for each item' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
144 ::Author.all.each do |author|
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
145 output_buffer.should have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
146 output_buffer.should have_tag("form li fieldset ol li label input[@type='checkbox']")
147 output_buffer.should have_tag("form li fieldset ol li label input[@value='#{author.id}']")
148 output_buffer.should have_tag("form li fieldset ol li label input[@name='project[author_id][]']")
149 end
150 end
a8489e9 @justinfrench whitepace
authored
151
364ae5c @yabawock HTML-escape the label strings (GH-292)
yabawock authored
152 it 'should html escape the label string' do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
153 concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
364ae5c @yabawock HTML-escape the label strings (GH-292)
yabawock authored
154 concat(builder.input(:author_id, :as => :check_boxes, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
155 end)
a8489e9 @justinfrench whitepace
authored
156
6441bf0 @justinfrench uncomment a test that was failing under rails 2
authored
157 output_buffer.should have_tag('form li fieldset ol li label') do |label|
158 label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;$/
159 end
364ae5c @yabawock HTML-escape the label strings (GH-292)
yabawock authored
160 end
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
161 end
a8489e9 @justinfrench whitepace
authored
162
235bc6e @yabawock Make tests reflect renamed option
yabawock authored
163 describe 'when :hidden_fields is set to false' do
f741375 @yabawock This commit introduces a new option to be passed to inputs rendered
yabawock authored
164 before do
165 @output_buffer = ''
166 mock_everything
a8489e9 @justinfrench whitepace
authored
167
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
168 concat(semantic_form_for(@fred) do |builder|
235bc6e @yabawock Make tests reflect renamed option
yabawock authored
169 concat(builder.input(:posts, :as => :check_boxes, :value_as_class => true, :hidden_fields => false))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
170 end)
f741375 @yabawock This commit introduces a new option to be passed to inputs rendered
yabawock authored
171 end
a8489e9 @justinfrench whitepace
authored
172
f741375 @yabawock This commit introduces a new option to be passed to inputs rendered
yabawock authored
173 it 'should have a checkbox input for each post' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
174 ::Post.all.each do |post|
f741375 @yabawock This commit introduces a new option to be passed to inputs rendered
yabawock authored
175 output_buffer.should have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
176 output_buffer.should have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => ::Post.all.length)
f741375 @yabawock This commit introduces a new option to be passed to inputs rendered
yabawock authored
177 end
178 end
a8489e9 @justinfrench whitepace
authored
179
f741375 @yabawock This commit introduces a new option to be passed to inputs rendered
yabawock authored
180 it "should mark input as checked if it's the the existing choice" do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
181 ::Post.all.include?(@fred.posts.first).should be_true
f741375 @yabawock This commit introduces a new option to be passed to inputs rendered
yabawock authored
182 output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']")
183 end
a8489e9 @justinfrench whitepace
authored
184
f741375 @yabawock This commit introduces a new option to be passed to inputs rendered
yabawock authored
185 it 'should not generate empty hidden inputs' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
186 output_buffer.should_not have_tag("form li fieldset ol li label input[@type='hidden'][@value='']", :count => ::Post.all.length)
f741375 @yabawock This commit introduces a new option to be passed to inputs rendered
yabawock authored
187 end
188 end
a8489e9 @justinfrench whitepace
authored
189
89dca89 @dallas added the :disabled option to #check_boxes_input
dallas authored
190 describe 'when :disabled is set' do
191 before do
192 @output_buffer = ''
193 end
a8489e9 @justinfrench whitepace
authored
194
89dca89 @dallas added the :disabled option to #check_boxes_input
dallas authored
195 describe "no disabled items" do
196 before do
197 @new_post.stub!(:author_ids).and_return(nil)
a8489e9 @justinfrench whitepace
authored
198
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
199 concat(semantic_form_for(@new_post) do |builder|
89dca89 @dallas added the :disabled option to #check_boxes_input
dallas authored
200 concat(builder.input(:authors, :as => :check_boxes, :disabled => nil))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
201 end)
89dca89 @dallas added the :disabled option to #check_boxes_input
dallas authored
202 end
a8489e9 @justinfrench whitepace
authored
203
89dca89 @dallas added the :disabled option to #check_boxes_input
dallas authored
204 it 'should not have any disabled item(s)' do
205 output_buffer.should_not have_tag("form li fieldset ol li label input[@disabled='disabled']")
206 end
207 end
a8489e9 @justinfrench whitepace
authored
208
89dca89 @dallas added the :disabled option to #check_boxes_input
dallas authored
209 describe "single disabled item" do
210 before do
211 @new_post.stub!(:author_ids).and_return(nil)
a8489e9 @justinfrench whitepace
authored
212
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
213 concat(semantic_form_for(@new_post) do |builder|
89dca89 @dallas added the :disabled option to #check_boxes_input
dallas authored
214 concat(builder.input(:authors, :as => :check_boxes, :disabled => @fred.id))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
215 end)
89dca89 @dallas added the :disabled option to #check_boxes_input
dallas authored
216 end
a8489e9 @justinfrench whitepace
authored
217
89dca89 @dallas added the :disabled option to #check_boxes_input
dallas authored
218 it "should have one item disabled; the specified one" do
219 output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 1)
220 output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
221 output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
222 end
223 end
a8489e9 @justinfrench whitepace
authored
224
89dca89 @dallas added the :disabled option to #check_boxes_input
dallas authored
225 describe "multiple disabled items" do
226 before do
227 @new_post.stub!(:author_ids).and_return(nil)
a8489e9 @justinfrench whitepace
authored
228
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
229 concat(semantic_form_for(@new_post) do |builder|
89dca89 @dallas added the :disabled option to #check_boxes_input
dallas authored
230 concat(builder.input(:authors, :as => :check_boxes, :disabled => [@bob.id, @fred.id]))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
231 end)
89dca89 @dallas added the :disabled option to #check_boxes_input
dallas authored
232 end
a8489e9 @justinfrench whitepace
authored
233
89dca89 @dallas added the :disabled option to #check_boxes_input
dallas authored
234 it "should have multiple items disabled; the specified ones" do
235 output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 2)
236 output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@bob.id}']", /bob/i)
237 output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@bob.id}']")
238 output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
239 output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
240 end
241 end
a8489e9 @justinfrench whitepace
authored
242
89dca89 @dallas added the :disabled option to #check_boxes_input
dallas authored
243 end
a8489e9 @justinfrench whitepace
authored
244
9593e4b @justinfrench Changed radio_input and check_boxes_input to no longer uses field_set…
authored
245 describe "with i18n of the legend label" do
a8489e9 @justinfrench whitepace
authored
246
9593e4b @justinfrench Changed radio_input and check_boxes_input to no longer uses field_set…
authored
247 before do
248 ::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
df22871 @justinfrench use with_config to ensure there's no confusion about the i18n config …
authored
249 with_config :i18n_lookups_by_default, true do
250 @new_post.stub!(:author_ids).and_return(nil)
251 concat(semantic_form_for(@new_post) do |builder|
252 concat(builder.input(:authors, :as => :check_boxes))
253 end)
254 end
9593e4b @justinfrench Changed radio_input and check_boxes_input to no longer uses field_set…
authored
255 end
a8489e9 @justinfrench whitepace
authored
256
9593e4b @justinfrench Changed radio_input and check_boxes_input to no longer uses field_set…
authored
257 after do
258 ::I18n.backend.reload!
259 end
a8489e9 @justinfrench whitepace
authored
260
9593e4b @justinfrench Changed radio_input and check_boxes_input to no longer uses field_set…
authored
261 it "should do foo" do
262 output_buffer.should have_tag("legend.label label", /Translated/)
263 end
a8489e9 @justinfrench whitepace
authored
264
9593e4b @justinfrench Changed radio_input and check_boxes_input to no longer uses field_set…
authored
265 end
a8489e9 @justinfrench whitepace
authored
266
49c4418 @yabawock Fix the test-suite
yabawock authored
267 describe "when :label option is set" do
268 before do
269 @new_post.stub!(:author_ids).and_return(nil)
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
270 concat(semantic_form_for(@new_post) do |builder|
49c4418 @yabawock Fix the test-suite
yabawock authored
271 concat(builder.input(:authors, :as => :check_boxes, :label => 'The authors'))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
272 end)
f4d6779 @pfeiffer Added spec for :label option
pfeiffer authored
273 end
a8489e9 @justinfrench whitepace
authored
274
49c4418 @yabawock Fix the test-suite
yabawock authored
275 it "should output the correct label title" do
276 output_buffer.should have_tag("legend.label label", /The authors/)
277 end
f4d6779 @pfeiffer Added spec for :label option
pfeiffer authored
278 end
a8489e9 @justinfrench whitepace
authored
279
214135d @coreyhaines Fix issue #331, :label=>false on checkboxes/radiobuttons
coreyhaines authored
280 describe "when :label option is false" do
281 before do
282 @output_buffer = ''
283 @new_post.stub!(:author_ids).and_return(nil)
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
284 concat(semantic_form_for(@new_post) do |builder|
214135d @coreyhaines Fix issue #331, :label=>false on checkboxes/radiobuttons
coreyhaines authored
285 concat(builder.input(:authors, :as => :check_boxes, :label => false))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
286 end)
214135d @coreyhaines Fix issue #331, :label=>false on checkboxes/radiobuttons
coreyhaines authored
287 end
a8489e9 @justinfrench whitepace
authored
288
214135d @coreyhaines Fix issue #331, :label=>false on checkboxes/radiobuttons
coreyhaines authored
289 it "should not output the legend" do
290 output_buffer.should_not have_tag("legend.label")
291 end
0ae3ba0 @justinfrench fix more cases of tainted/escaped HTML output
authored
292
293 it "should not cause escaped HTML" do
294 output_buffer.should_not include("&gt;")
295 end
296
214135d @coreyhaines Fix issue #331, :label=>false on checkboxes/radiobuttons
coreyhaines authored
297 end
a8489e9 @justinfrench whitepace
authored
298
c02f6f1 @dim Include 'required' information in :check_boxes and :radio inputs.
dim authored
299 describe "when :required option is true" do
300 before do
301 @new_post.stub!(:author_ids).and_return(nil)
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
302 concat(semantic_form_for(@new_post) do |builder|
c02f6f1 @dim Include 'required' information in :check_boxes and :radio inputs.
dim authored
303 concat(builder.input(:authors, :as => :check_boxes, :required => true))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
304 end)
c02f6f1 @dim Include 'required' information in :check_boxes and :radio inputs.
dim authored
305 end
a8489e9 @justinfrench whitepace
authored
306
c02f6f1 @dim Include 'required' information in :check_boxes and :radio inputs.
dim authored
307 it "should output the correct label title" do
308 output_buffer.should have_tag("legend.label label abbr")
309 end
310 end
a8489e9 @justinfrench whitepace
authored
311
f4d6779 @pfeiffer Added spec for :label option
pfeiffer authored
312 end
a8489e9 @justinfrench whitepace
authored
313
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
314 describe 'for a has_and_belongs_to_many association' do
a8489e9 @justinfrench whitepace
authored
315
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
316 before do
317 @output_buffer = ''
318 mock_everything
a8489e9 @justinfrench whitepace
authored
319
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
320 concat(semantic_form_for(@freds_post) do |builder|
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
321 concat(builder.input(:authors, :as => :check_boxes))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
322 end)
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
323 end
a8489e9 @justinfrench whitepace
authored
324
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
325 it 'should render checkboxes' do
326 # I'm aware these two lines test the same thing
327 output_buffer.should have_tag('input[type="checkbox"]', :count => 2)
328 output_buffer.should have_tag('input[type="checkbox"]', :count => ::Author.all.size)
329 end
a8489e9 @justinfrench whitepace
authored
330
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
331 it 'should only select checkboxes that are present in the association' do
332 # I'm aware these two lines test the same thing
333 output_buffer.should have_tag('input[checked="checked"]', :count => 1)
334 output_buffer.should have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
335 end
a8489e9 @justinfrench whitepace
authored
336
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
337 end
a8489e9 @justinfrench whitepace
authored
338
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
339 describe 'for an association when a :collection is provided' do
454dd44 @justinfrench Renamed (with backwards compatibility) and deprecation notices) :labe…
authored
340 describe 'it should use the specified :member_value option' do
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
341 before do
342 @output_buffer = ''
343 mock_everything
344 end
a8489e9 @justinfrench whitepace
authored
345
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
346 it 'to set the right input value' do
347 item = mock('item')
348 item.should_not_receive(:id)
349 item.stub!(:custom_value).and_return('custom_value')
350 item.should_receive(:custom_value).exactly(3).times
e7d3e0f @jnimety memoize the selected values array
jnimety authored
351 @new_post.author.should_receive(:custom_value).exactly(1).times
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
352 concat(semantic_form_for(@new_post) do |builder|
454dd44 @justinfrench Renamed (with backwards compatibility) and deprecation notices) :labe…
authored
353 concat(builder.input(:author, :as => :check_boxes, :member_value => :custom_value, :collection => [item, item, item]))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
354 end)
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
355 output_buffer.should have_tag('input[@type=checkbox][@value="custom_value"]', :count => 3)
356 end
357 end
358 end
1326648 @justinfrench clarify that spec a little bit more
authored
359
360 describe 'when :collection is provided as an array of arrays' do
361 before do
362 @output_buffer = ''
363 mock_everything
d2c4ff7 @justinfrench Collections of strings in CheckBoxesInput should now be checked if th…
authored
364 @fred.stub(:genres) { ['fiction', 'biography'] }
1326648 @justinfrench clarify that spec a little bit more
authored
365
366 concat(semantic_form_for(@fred) do |builder|
367 concat(builder.input(:genres, :as => :check_boxes, :collection => [['Fiction', 'fiction'], ['Non-fiction', 'non_fiction'], ['Biography', 'biography']]))
368 end)
369 end
370
371 it 'should check the correct checkboxes' do
372 output_buffer.should have_tag("form li fieldset ol li label input[@value='fiction'][@checked='checked']")
373 output_buffer.should have_tag("form li fieldset ol li label input[@value='biography'][@checked='checked']")
374 end
375 end
a8489e9 @justinfrench whitepace
authored
376
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
377 describe "when namespace is provided" do
a8489e9 @justinfrench whitepace
authored
378
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
379 before do
380 @output_buffer = ''
381 mock_everything
a8489e9 @justinfrench whitepace
authored
382
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
383 concat(semantic_form_for(@fred, :namespace => "context2") do |builder|
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
384 concat(builder.input(:posts, :as => :check_boxes))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
385 end)
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
386 end
14aef5f @justinfrench don't apply a .label class to <label> tags inside a .choice on radio …
authored
387
388 it "should have a label for #context2_author_post_ids_19" do
389 output_buffer.should have_tag("form li label[@for='context2_author_post_ids_19']")
390 end
a8489e9 @justinfrench whitepace
authored
391
89df25c @justinfrench cleaning up my last commit. was I drunk?
authored
392 it_should_have_input_with_id('context2_author_post_ids_19')
393 it_should_have_input_wrapper_with_id("context2_author_posts_input")
394 end
56bf917 @justinfrench fix checkboxes input to respect :index from fields_for in input[name]…
authored
395
396 describe "when index is provided" do
397
398 before do
399 @output_buffer = ''
400 mock_everything
401
402 concat(semantic_form_for(@fred) do |builder|
0566774 @jslag address syntax errors with 1.9.2-p290
jslag authored
403 concat(builder.fields_for(@fred.posts.first, :index => 3) do |author|
56bf917 @justinfrench fix checkboxes input to respect :index from fields_for in input[name]…
authored
404 concat(author.input(:authors, :as => :check_boxes))
405 end)
406 end)
407 end
408
409 it 'should index the id of the wrapper' do
410 output_buffer.should have_tag("li#author_post_3_authors_input")
411 end
412
413 it 'should index the id of the input tag' do
414 output_buffer.should have_tag("input#author_post_3_author_ids_42")
415 end
416
417 it 'should index the name of the checkbox input' do
418 output_buffer.should have_tag("input[@type='checkbox'][@name='author[post][3][author_ids][]']")
419 end
420
421 end
422
a8489e9 @justinfrench whitepace
authored
423
4d61e33 @TimothyKlim added specs
TimothyKlim authored
424 describe "when collection is an array" do
425 before do
426 @output_buffer = ''
427 @_collection = [["First", 1], ["Second", 2]]
428 mock_everything
429
430 concat(semantic_form_for(@fred) do |builder|
431 concat(builder.input(:posts, :as => :check_boxes, :collection => @_collection))
432 end)
433 end
434
435 it "should use array items for labels and values" do
436 @_collection.each do |post|
437 output_buffer.should have_tag('form li fieldset ol li label', /#{post.first}/)
438 output_buffer.should have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.last}']")
439 end
440 end
292a0c2 @cthiel add failing spec for issue #674
cthiel authored
441
442 it "should not check any items" do
443 output_buffer.should have_tag('form li input[@checked]', :count => 0)
12c086b @pfeiffer Make sure checkbox values with integers are checked.
pfeiffer authored
444 end
445
446 describe "and the attribute has values" do
447 before do
448 @fred.stub(:posts) { [1] }
449
450 concat(semantic_form_for(@fred) do |builder|
451 concat(builder.input(:posts, :as => :check_boxes, :collection => @_collection))
452 end)
453 end
454
455 it "should check the appropriate items" do
456 output_buffer.should have_tag("form li input[@value='1'][@checked]")
457 end
458 end
4d61e33 @TimothyKlim added specs
TimothyKlim authored
459 end
460
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
461 end
462
Something went wrong with that request. Please try again.