Skip to content
Newer
Older
100644 505 lines (422 sloc) 18.9 KB
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
1 # encoding: utf-8
2
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
3 module CustomMacros
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
4
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
5 def self.included(base)
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
6 base.extend(ClassMethods)
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
7 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
8
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
9 module ClassMethods
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
10
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
11 def it_should_have_input_wrapper_with_class(class_name)
12 it "should have input wrapper with class '#{class_name}'" do
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
13 output_buffer.should have_tag("form li.#{class_name}")
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
14 end
15 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
16
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
17 def it_should_have_input_wrapper_with_id(id_string)
18 it "should have input wrapper with id '#{id_string}'" do
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
19 output_buffer.should have_tag("form li##{id_string}")
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
20 end
21 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
22
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
23 def it_should_not_have_a_label
24 it "should not have a label" do
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
25 output_buffer.should_not have_tag("form li label")
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
26 end
27 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
28
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
29 def it_should_have_a_nested_fieldset
30 it "should have a nested_fieldset" do
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
31 output_buffer.should have_tag("form li fieldset")
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
32 end
33 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
34
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
35 def it_should_have_label_with_text(string_or_regex)
36 it "should have a label with text '#{string_or_regex}'" do
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
37 output_buffer.should have_tag("form li label", string_or_regex)
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
38 end
39 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
40
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
41 def it_should_have_label_for(element_id)
42 it "should have a label for ##{element_id}" do
43 output_buffer.should have_tag("form li label[@for='#{element_id}']")
44 end
45 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
46
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
47 def it_should_have_input_with_id(element_id)
48 it "should have an input with id '#{element_id}'" do
49 output_buffer.should have_tag("form li input##{element_id}")
50 end
51 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
52
717d8e8 @asanghi full(ish) implementation of namespacing a form's id prefix; more test…
asanghi authored Oct 17, 2010
53 def it_should_have_select_with_id(element_id)
54 it "should have a select box with id '#{element_id}'" do
55 output_buffer.should have_tag("form li select##{element_id}")
56 end
57 end
58
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
59 def it_should_have_input_with_type(input_type)
60 it "should have a #{input_type} input" do
61 output_buffer.should have_tag("form li input[@type=\"#{input_type}\"]")
62 end
63 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
64
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
65 def it_should_have_input_with_name(name)
66 it "should have an input named #{name}" do
67 output_buffer.should have_tag("form li input[@name=\"#{name}\"]")
68 end
69 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
70
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
71 def it_should_have_textarea_with_name(name)
72 it "should have an input named #{name}" do
73 output_buffer.should have_tag("form li textarea[@name=\"#{name}\"]")
74 end
75 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
76
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
77 def it_should_have_textarea_with_id(element_id)
78 it "should have an input with id '#{element_id}'" do
79 output_buffer.should have_tag("form li textarea##{element_id}")
80 end
81 end
7444066 @yabawock Whitespace cleanup from HTML5 merge
yabawock authored Oct 13, 2010
82
717d8e8 @asanghi full(ish) implementation of namespacing a form's id prefix; more test…
asanghi authored Oct 17, 2010
83 def it_should_have_label_and_input_with_id(element_id)
84 it "should have an input with id '#{element_id}'" do
85 output_buffer.should have_tag("form li input##{element_id}")
86 output_buffer.should have_tag("form li label[@for='#{element_id}']")
87 end
88 end
89
b766ddc @justinfrench string|numeric|password and other basic inputs no longer add a size a…
authored Sep 17, 2010
90 def it_should_use_default_text_field_size_when_not_nil(as)
91 it 'should use default_text_field_size when not nil' do
92 with_config :default_text_field_size, 30 do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
93 concat(semantic_form_for(@new_post) do |builder|
b766ddc @justinfrench string|numeric|password and other basic inputs no longer add a size a…
authored Sep 17, 2010
94 concat(builder.input(:title, :as => as))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
95 end)
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtasti…
authored Jan 18, 2011
96 output_buffer.should have_tag("form li input[@size='#{Formtastic::FormBuilder.default_text_field_size}']")
b766ddc @justinfrench string|numeric|password and other basic inputs no longer add a size a…
authored Sep 17, 2010
97 end
98 end
99 end
7444066 @yabawock Whitespace cleanup from HTML5 merge
yabawock authored Oct 13, 2010
100
b766ddc @justinfrench string|numeric|password and other basic inputs no longer add a size a…
authored Sep 17, 2010
101 def it_should_not_use_default_text_field_size_when_nil(as)
102 it 'should not use default_text_field_size when nil' do
103 with_config :default_text_field_size, nil do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
104 concat(semantic_form_for(@new_post) do |builder|
b766ddc @justinfrench string|numeric|password and other basic inputs no longer add a size a…
authored Sep 17, 2010
105 concat(builder.input(:title, :as => as))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
106 end)
b766ddc @justinfrench string|numeric|password and other basic inputs no longer add a size a…
authored Sep 17, 2010
107 output_buffer.should have_tag("form li input")
108 output_buffer.should_not have_tag("form li input[@size]")
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
109 end
110 end
111 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
112
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
113 def it_should_apply_custom_input_attributes_when_input_html_provided(as)
114 it 'it should apply custom input attributes when input_html provided' do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
115 concat(semantic_form_for(@new_post) do |builder|
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
116 concat(builder.input(:title, :as => as, :input_html => { :class => 'myclass' }))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
117 end)
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
118 output_buffer.should have_tag("form li input.myclass")
119 end
120 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
121
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
122 def it_should_apply_custom_for_to_label_when_input_html_id_provided(as)
123 it 'it should apply custom for to label when input_html :id provided' do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
124 concat(semantic_form_for(@new_post) do |builder|
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
125 concat(builder.input(:title, :as => as, :input_html => { :id => 'myid' }))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
126 end)
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
127 output_buffer.should have_tag('form li label[@for="myid"]')
128 end
129 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
130
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
131 def it_should_have_maxlength_matching_column_limit
132 it 'should have a maxlength matching column limit' do
133 @new_post.column_for_attribute(:title).limit.should == 50
134 output_buffer.should have_tag("form li input[@maxlength='50']")
135 end
136 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
137
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
138 def it_should_use_column_size_for_columns_shorter_than_default_text_field_size(as)
139 it 'should use the column size for columns shorter than default_text_field_size' do
140 column_limit_shorted_than_default = 1
141 @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => as, :limit => column_limit_shorted_than_default))
142
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
143 concat(semantic_form_for(@new_post) do |builder|
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
144 concat(builder.input(:title, :as => as))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
145 end)
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
146
147 output_buffer.should have_tag("form li input[@size='#{column_limit_shorted_than_default}']")
148 end
149 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
150
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored Nov 12, 2009
151 def it_should_apply_error_logic_for_input_type(type)
152 describe 'when there are errors on the object for this method' do
153 before do
154 @title_errors = ['must not be blank', 'must be longer than 10 characters', 'must be awesome']
155 @errors = mock('errors')
156 @errors.stub!(:[]).with(:title).and_return(@title_errors)
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtasti…
authored Jan 18, 2011
157 Formtastic::FormBuilder.file_metadata_suffixes.each do |suffix|
deb9f9b @asanghi automatic deduction of errors related to file type fields
asanghi authored Oct 28, 2010
158 @errors.stub!(:[]).with("title_#{suffix}".to_sym).and_return(nil)
159 end
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored Nov 12, 2009
160 @new_post.stub!(:errors).and_return(@errors)
161 end
162
163 it 'should apply an errors class to the list item' do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
164 concat(semantic_form_for(@new_post) do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored Nov 12, 2009
165 concat(builder.input(:title, :as => type))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
166 end)
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored Nov 12, 2009
167 output_buffer.should have_tag('form li.error')
168 end
169
170 it 'should not wrap the input with the Rails default error wrapping' do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
171 concat(semantic_form_for(@new_post) do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored Nov 12, 2009
172 concat(builder.input(:title, :as => type))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
173 end)
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored Nov 12, 2009
174 output_buffer.should_not have_tag('div.fieldWithErrors')
175 end
176
177 it 'should render a paragraph for the errors' do
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtasti…
authored Jan 18, 2011
178 Formtastic::FormBuilder.inline_errors = :sentence
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
179 concat(semantic_form_for(@new_post) do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored Nov 12, 2009
180 concat(builder.input(:title, :as => type))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
181 end)
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored Nov 12, 2009
182 output_buffer.should have_tag('form li.error p.inline-errors')
183 end
184
185 it 'should not display an error list' do
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtasti…
authored Jan 18, 2011
186 Formtastic::FormBuilder.inline_errors = :list
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
187 concat(semantic_form_for(@new_post) do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored Nov 12, 2009
188 concat(builder.input(:title, :as => type))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
189 end)
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored Nov 12, 2009
190 output_buffer.should have_tag('form li.error ul.errors')
191 end
192 end
193
194 describe 'when there are no errors on the object for this method' do
195 before do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored Apr 13, 2010
196 @form = semantic_form_for(@new_post) do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored Nov 12, 2009
197 concat(builder.input(:title, :as => type))
198 end
199 end
200
201 it 'should not apply an errors class to the list item' do
202 output_buffer.should_not have_tag('form li.error')
203 end
204
205 it 'should not render a paragraph for the errors' do
206 output_buffer.should_not have_tag('form li.error p.inline-errors')
207 end
208
209 it 'should not display an error list' do
210 output_buffer.should_not have_tag('form li.error ul.errors')
211 end
212 end
213
214 describe 'when no object is provided' do
215 before do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
216 concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored Nov 12, 2009
217 concat(builder.input(:title, :as => type))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
218 end)
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored Nov 12, 2009
219 end
220
221 it 'should not apply an errors class to the list item' do
222 output_buffer.should_not have_tag('form li.error')
223 end
224
225 it 'should not render a paragraph for the errors' do
226 output_buffer.should_not have_tag('form li.error p.inline-errors')
227 end
228
229 it 'should not display an error list' do
230 output_buffer.should_not have_tag('form li.error ul.errors')
231 end
232 end
233 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
234
446e173 @justinfrench add macro for default collection logic, shifting it out of the collec…
authored Nov 12, 2009
235 def it_should_call_find_on_association_class_when_no_collection_is_provided(as)
236 it "should call find on the association class when no collection is provided" do
4134c12 @justinfrench fix a bunch of issues and failing select input specs around #where vs…
authored Mar 16, 2011
237 ::Author.should_receive(:where)
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
238 concat(semantic_form_for(@new_post) do |builder|
446e173 @justinfrench add macro for default collection logic, shifting it out of the collec…
authored Nov 12, 2009
239 concat(builder.input(:author, :as => as))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
240 end)
446e173 @justinfrench add macro for default collection logic, shifting it out of the collec…
authored Nov 12, 2009
241 end
242 end
c453c36 @grimen Failing spec and a "for some reason a non-working solution" for issue #…
grimen authored Nov 24, 2009
243
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
244 def it_should_use_the_collection_when_provided(as, countable)
245 describe 'when the :collection option is provided' do
246
247 before do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored Sep 27, 2010
248 @authors = ::Author.all * 2
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
249 output_buffer.replace ''
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
250 end
251
252 it 'should use the provided collection' do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
253 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
254 concat(builder.input(:author, :as => as, :collection => @authors))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
255 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
256 output_buffer.should have_tag("form li.#{as} #{countable}", :count => @authors.size + (as == :select ? 1 : 0))
257 end
258
259 describe 'and the :collection is an array of strings' do
260 before do
261 @categories = [ 'General', 'Design', 'Development', 'Quasi-Serious Inventions' ]
262 end
263
264 it "should use the string as the label text and value for each #{countable}" do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
265 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
266 concat(builder.input(:category_name, :as => as, :collection => @categories))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
267 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
268
269 @categories.each do |value|
270 output_buffer.should have_tag("form li.#{as}", /#{value}/)
271 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value}']")
272 end
273 end
274
275 if as == :radio
276 it 'should generate a sanitized label for attribute' do
277 @bob.stub!(:category_name).and_return(@categories)
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
278 concat(semantic_form_for(@new_post) do |builder|
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored Apr 13, 2010
279 fields = builder.semantic_fields_for(@bob) do |bob_builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
280 concat(bob_builder.input(:category_name, :as => as, :collection => @categories))
281 end
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored Apr 13, 2010
282 concat(fields)
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
283 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
284 output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_general']")
285 output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_design']")
286 output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_development']")
287 output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_quasiserious_inventions']")
288 end
289 end
290 end
291
292 describe 'and the :collection is a hash of strings' do
293 before do
294 @categories = { 'General' => 'gen', 'Design' => 'des','Development' => 'dev' }
295 end
296
297 it "should use the key as the label text and the hash value as the value attribute for each #{countable}" do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
298 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
299 concat(builder.input(:category_name, :as => as, :collection => @categories))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
300 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
301
302 @categories.each do |label, value|
303 output_buffer.should have_tag("form li.#{as}", /#{label}/)
304 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value}']")
305 end
306 end
307 end
308
309 describe 'and the :collection is an array of arrays' do
310 before do
311 @categories = { 'General' => 'gen', 'Design' => 'des', 'Development' => 'dev' }.to_a
312 end
313
314 it "should use the first value as the label text and the last value as the value attribute for #{countable}" do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
315 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
316 concat(builder.input(:category_name, :as => as, :collection => @categories))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
317 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
318
319 @categories.each do |text, value|
320 label = as == :select ? :option : :label
321 output_buffer.should have_tag("form li.#{as} #{label}", /#{text}/i)
322 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value.to_s}']")
323 output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_#{value.to_s}") if as == :radio
324 end
325 end
326 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
327
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
328 if as == :radio
329 describe 'and the :collection is an array of arrays with boolean values' do
330 before do
331 @choices = { 'Yeah' => true, 'Nah' => false }.to_a
332 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
333
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
334 it "should use the first value as the label text and the last value as the value attribute for #{countable}" do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
335 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
336 concat(builder.input(:category_name, :as => as, :collection => @choices))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
337 end)
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
338
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
339 output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_true")
340 output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_false")
341 end
342 end
343 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
344
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
345 describe 'and the :collection is an array of symbols' do
346 before do
347 @categories = [ :General, :Design, :Development ]
348 end
349
350 it "should use the symbol as the label text and value for each #{countable}" do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
351 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
352 concat(builder.input(:category_name, :as => as, :collection => @categories))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
353 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
354
355 @categories.each do |value|
356 label = as == :select ? :option : :label
357 output_buffer.should have_tag("form li.#{as} #{label}", /#{value}/i)
358 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value.to_s}']")
359 end
360 end
361 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
362
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
363 describe 'and the :collection is an OrderedHash of strings' do
364 before do
365 @categories = ActiveSupport::OrderedHash.new('General' => 'gen', 'Design' => 'des','Development' => 'dev')
366 end
367
368 it "should use the key as the label text and the hash value as the value attribute for each #{countable}" do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
369 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
370 concat(builder.input(:category_name, :as => as, :collection => @categories))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
371 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
372
373 @categories.each do |label, value|
374 output_buffer.should have_tag("form li.#{as}", /#{label}/)
375 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value}']")
376 end
377 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
378
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
379 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
380
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
381 describe 'when the :label_method option is provided' do
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
382
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
383 describe 'as a symbol' do
384 before do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
385 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
386 concat(builder.input(:author, :as => as, :label_method => :login))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
387 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
388 end
389
390 it 'should have options with text content from the specified method' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored Sep 27, 2010
391 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
392 output_buffer.should have_tag("form li.#{as}", /#{author.login}/)
393 end
394 end
395 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
396
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
397 describe 'as a proc' do
398 before do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
399 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
400 concat(builder.input(:author, :as => as, :label_method => Proc.new {|a| a.login.reverse }))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
401 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
402 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
403
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
404 it 'should have options with the proc applied to each' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored Sep 27, 2010
405 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
406 output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
407 end
408 end
409 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
410
40b3cd3 @bruce Support Method objects for :label_method and :value_method.
bruce authored Apr 16, 2011
411 describe 'as a method object' do
412 before do
413 def reverse_login(a)
414 a.login.reverse
415 end
416 concat(semantic_form_for(@new_post) do |builder|
417 concat(builder.input(:author, :as => as, :label_method => method(:reverse_login)))
418 end)
419 end
420
421 it 'should have options with the proc applied to each' do
422 ::Author.all.each do |author|
423 output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
424 end
425 end
426 end
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
427 end
428
429 describe 'when the :label_method option is not provided' do
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtasti…
authored Jan 18, 2011
430 Formtastic::FormBuilder.collection_label_methods.each do |label_method|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
431
432 describe "when the collection objects respond to #{label_method}" do
433 before do
8fb219c @yabawock Refactor the label and value detection for collections
yabawock authored Aug 3, 2010
434 @fred.stub!(:respond_to?).and_return { |m| m.to_s == label_method || m.to_s == 'id' }
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored Sep 27, 2010
435 ::Author.all.each { |a| a.stub!(label_method).and_return('The Label Text') }
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
436
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
437 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
438 concat(builder.input(:author, :as => as))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
439 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
440 end
441
442 it "should render the options with #{label_method} as the label" do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored Sep 27, 2010
443 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
444 output_buffer.should have_tag("form li.#{as}", /The Label Text/)
445 end
446 end
447 end
448
449 end
450 end
451
452 describe 'when the :value_method option is provided' do
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
453
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
454 describe 'as a symbol' do
455 before do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
456 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
457 concat(builder.input(:author, :as => as, :value_method => :login))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
458 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
459 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
460
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
461 it 'should have options with values from specified method' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored Sep 27, 2010
462 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
463 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login}']")
464 end
465 end
466 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
467
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
468 describe 'as a proc' do
469 before do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
470 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
471 concat(builder.input(:author, :as => as, :value_method => Proc.new {|a| a.login.reverse }))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored Jan 14, 2011
472 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
473 end
474
475 it 'should have options with the proc applied to each value' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored Sep 27, 2010
476 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
477 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
478 end
479 end
480 end
40b3cd3 @bruce Support Method objects for :label_method and :value_method.
bruce authored Apr 16, 2011
481
482 describe 'as a method object' do
483 before do
484 def reverse_login(a)
485 a.login.reverse
486 end
487 concat(semantic_form_for(@new_post) do |builder|
488 concat(builder.input(:author, :as => as, :value_method => method(:reverse_login)))
489 end)
490 end
491
492 it 'should have options with the proc applied to each value' do
493 ::Author.all.each do |author|
494 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
495 end
496 end
497 end
93cd786 @justinfrench created an ugly macro for testing collections
authored Nov 12, 2009
498 end
499
500 end
501 end
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored Nov 12, 2009
502
4a732fd @justinfrench Spec Refactor:
authored Nov 11, 2009
503 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored Sep 27, 2010
504 end
Something went wrong with that request. Please try again.