Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 231 lines (179 sloc) 9.47 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 'boolean 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 before do
f9c1a8a @yabawock Revert all the changes introduced in commits 8d17ca4..8d8c50
yabawock authored
9 @output_buffer = ''
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
10 mock_everything
433dae2 @yabawock Whitespace Cleanup
yabawock authored
11
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
12 concat(semantic_form_for(@new_post) do |builder|
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
13 concat(builder.input(:allow_comments, :as => :boolean))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
14 end)
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
15 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
16
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
17 it_should_have_input_wrapper_with_class("boolean")
3535c5f @justinfrench add an .input class to all inputs to allow easy styling of all of them
authored
18 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
19 it_should_have_input_wrapper_with_id("post_allow_comments_input")
20 it_should_apply_error_logic_for_input_type(:boolean)
21
22 it 'should generate a label containing the input' do
2508880 @justinfrench Refactor labels CSS, add classes.
authored
23 output_buffer.should_not have_tag('label.label')
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
24 output_buffer.should have_tag('form li label', :count => 1)
25 output_buffer.should have_tag('form li label[@for="post_allow_comments"]')
26 output_buffer.should have_tag('form li label', /Allow comments/)
0f88cb3 @justinfrench Attempts to fix GH-264 by rendering our own hidden_field_tag outside …
authored
27 output_buffer.should have_tag('form li label input[@type="checkbox"]', :count => 1)
28 output_buffer.should have_tag('form li input[@type="hidden"]', :count => 1)
29 output_buffer.should_not have_tag('form li label input[@type="hidden"]', :count => 1) # invalid HTML5
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
30 end
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
31
fb8f8e1 Don't add the checkbox's name attribute to its label for boolean fields.
Steve Jorgensen authored
32 it 'should not add a "name" attribute to the label' do
33 output_buffer.should_not have_tag('form li label[@name]')
34 end
35
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
36 it 'should generate a checkbox input' do
37 output_buffer.should have_tag('form li label input')
38 output_buffer.should have_tag('form li label input#post_allow_comments')
39 output_buffer.should have_tag('form li label input[@type="checkbox"]')
40 output_buffer.should have_tag('form li label input[@name="post[allow_comments]"]')
41 output_buffer.should have_tag('form li label input[@type="checkbox"][@value="1"]')
42 end
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
43
8f75fc7 @lardawge input_html should be passed to checkbox_tag
lardawge authored
44 it 'should generate a checked input if object.method returns true' do
77ae6ad @lardawge [Fix] Input boolean checked values do not reflect database values
lardawge authored
45 output_buffer.should have_tag('form li label input[@checked="checked"]')
8f75fc7 @lardawge input_html should be passed to checkbox_tag
lardawge authored
46 output_buffer.should have_tag('form li input[@name="post[allow_comments]"]', :count => 2)
47 output_buffer.should have_tag('form li input#post_allow_comments', :count => 1)
77ae6ad @lardawge [Fix] Input boolean checked values do not reflect database values
lardawge authored
48 end
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
49
8f75fc7 @lardawge input_html should be passed to checkbox_tag
lardawge authored
50 it 'should generate a checked input if :input_html is passed :checked => checked' do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
51 concat(semantic_form_for(@new_post) do |builder|
8f75fc7 @lardawge input_html should be passed to checkbox_tag
lardawge authored
52 concat(builder.input(:answer_comments, :as => :boolean, :input_html => {:checked => 'checked'}))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
53 end)
8f75fc7 @lardawge input_html should be passed to checkbox_tag
lardawge authored
54 output_buffer.should have_tag('form li label input[@checked="checked"]')
55 end
34efd96 @justinfrench the hidden input rendered with a boolean input with respect a custom …
authored
56
57 it 'should name the hidden input with the :name html_option' do
4d998ff @justinfrench clean up specs from some lazy merges and cherry-picks
authored
58 concat(semantic_form_for(@new_post) do |builder|
34efd96 @justinfrench the hidden input rendered with a boolean input with respect a custom …
authored
59 concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
4d998ff @justinfrench clean up specs from some lazy merges and cherry-picks
authored
60 end)
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
61
34efd96 @justinfrench the hidden input rendered with a boolean input with respect a custom …
authored
62 output_buffer.should have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
63 output_buffer.should have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
64 end
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
65
bf3ed65 @justinfrench the hidden input rendered with a boolean input with respect a custom …
authored
66 it 'should name the hidden input with the :name html_option' do
945ab96 @justinfrench Merge branch 'v2' into master-v2-merge
authored
67 concat(semantic_form_for(@new_post) do |builder|
bf3ed65 @justinfrench the hidden input rendered with a boolean input with respect a custom …
authored
68 concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
945ab96 @justinfrench Merge branch 'v2' into master-v2-merge
authored
69 end)
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
70
bf3ed65 @justinfrench the hidden input rendered with a boolean input with respect a custom …
authored
71 output_buffer.should have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
72 output_buffer.should have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
73 end
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
74
7c4c4f3 @justinfrench The hidden field rendered before a BooleanInput checkbox should be di…
authored
75 it "should generate a disabled input and hidden input if :input_html is passed :disabled => 'disabled' " do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
76 concat(semantic_form_for(@new_post) do |builder|
8f75fc7 @lardawge input_html should be passed to checkbox_tag
lardawge authored
77 concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:disabled => 'disabled'}))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
78 end)
7c4c4f3 @justinfrench The hidden field rendered before a BooleanInput checkbox should be di…
authored
79 output_buffer.should have_tag('form li label input[@disabled="disabled"]', :count => 1)
80 output_buffer.should have_tag('form li input[@type="hidden"][@disabled="disabled"]', :count => 1)
8f75fc7 @lardawge input_html should be passed to checkbox_tag
lardawge authored
81 end
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
82
8f75fc7 @lardawge input_html should be passed to checkbox_tag
lardawge authored
83 it 'should generate an input[id] with matching label[for] when id passed in :input_html' do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
84 concat(semantic_form_for(@new_post) do |builder|
8f75fc7 @lardawge input_html should be passed to checkbox_tag
lardawge authored
85 concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:id => 'custom_id'}))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
86 end)
8f75fc7 @lardawge input_html should be passed to checkbox_tag
lardawge authored
87 output_buffer.should have_tag('form li label input[@id="custom_id"]')
88 output_buffer.should have_tag('form li label[@for="custom_id"]')
05c209b @lardawge [Fix] Boolean input will not update database column to false if unche…
lardawge authored
89 end
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
90
91 it 'should allow checked and unchecked values to be sent' do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
92 concat(semantic_form_for(@new_post) do |builder|
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
93 concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'checked', :unchecked_value => 'unchecked'))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
94 end)
281ea98 extract checked_value and unchecked_value before passing options to t…
Moritz Heidkamp authored
95 output_buffer.should have_tag('form li label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
0f88cb3 @justinfrench Attempts to fix GH-264 by rendering our own hidden_field_tag outside …
authored
96 output_buffer.should have_tag('form li input[@type="hidden"][@value="unchecked"]')
97 output_buffer.should_not have_tag('form li label input[@type="hidden"]') # invalid HTML5
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
98 end
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
99
6df4f98 @justinfrench replicate 'Use check_box_checked? from Rails for boolean inputs' (a2d…
authored
100 it 'should generate a checked input if object.method returns checked value' do
101 @new_post.stub!(:allow_comments).and_return('yes')
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
102
4d998ff @justinfrench clean up specs from some lazy merges and cherry-picks
authored
103 concat(semantic_form_for(@new_post) do |builder|
6df4f98 @justinfrench replicate 'Use check_box_checked? from Rails for boolean inputs' (a2d…
authored
104 concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
4d998ff @justinfrench clean up specs from some lazy merges and cherry-picks
authored
105 end)
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
106
6df4f98 @justinfrench replicate 'Use check_box_checked? from Rails for boolean inputs' (a2d…
authored
107 output_buffer.should have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
108 end
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
109
6df4f98 @justinfrench replicate 'Use check_box_checked? from Rails for boolean inputs' (a2d…
authored
110 it 'should not generate a checked input if object.method returns unchecked value' do
111 @new_post.stub!(:allow_comments).and_return('no')
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
112
4d998ff @justinfrench clean up specs from some lazy merges and cherry-picks
authored
113 concat(semantic_form_for(@new_post) do |builder|
6df4f98 @justinfrench replicate 'Use check_box_checked? from Rails for boolean inputs' (a2d…
authored
114 concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
4d998ff @justinfrench clean up specs from some lazy merges and cherry-picks
authored
115 end)
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
116
6df4f98 @justinfrench replicate 'Use check_box_checked? from Rails for boolean inputs' (a2d…
authored
117 output_buffer.should have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
118 end
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
119
a2d6a09 @eugenebolshakov Use check_box_checked? from Rails for boolean inputs
eugenebolshakov authored
120 it 'should generate a checked input if object.method returns checked value' do
121 @new_post.stub!(:allow_comments).and_return('yes')
122
945ab96 @justinfrench Merge branch 'v2' into master-v2-merge
authored
123 concat(semantic_form_for(@new_post) do |builder|
a2d6a09 @eugenebolshakov Use check_box_checked? from Rails for boolean inputs
eugenebolshakov authored
124 concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
945ab96 @justinfrench Merge branch 'v2' into master-v2-merge
authored
125 end)
a2d6a09 @eugenebolshakov Use check_box_checked? from Rails for boolean inputs
eugenebolshakov authored
126
127 output_buffer.should have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
128 end
129
130 it 'should not generate a checked input if object.method returns unchecked value' do
131 @new_post.stub!(:allow_comments).and_return('no')
132
945ab96 @justinfrench Merge branch 'v2' into master-v2-merge
authored
133 concat(semantic_form_for(@new_post) do |builder|
a2d6a09 @eugenebolshakov Use check_box_checked? from Rails for boolean inputs
eugenebolshakov authored
134 concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
945ab96 @justinfrench Merge branch 'v2' into master-v2-merge
authored
135 end)
a2d6a09 @eugenebolshakov Use check_box_checked? from Rails for boolean inputs
eugenebolshakov authored
136
137 output_buffer.should have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
138 end
139
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
140 it 'should generate a label and a checkbox even if no object is given' do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
141 concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
675698e @justinfrench shifted all :as => :blah specs out to their own files, so we now have…
authored
142 concat(builder.input(:allow_comments, :as => :boolean))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
143 end)
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
144
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 label[@for="project_allow_comments"]')
146 output_buffer.should have_tag('form li label', /Allow comments/)
147 output_buffer.should have_tag('form li label input[@type="checkbox"]')
148
149 output_buffer.should have_tag('form li label input#project_allow_comments')
150 output_buffer.should have_tag('form li label input[@type="checkbox"]')
151 output_buffer.should have_tag('form li label input[@name="project[allow_comments]"]')
152 end
182b954 @justinfrench tabindex should not be passed down to label_html_options (boolean inp…
authored
153
154 it 'should not pass input_html options down to the label html' do
155 concat(semantic_form_for(@new_post) do |builder|
156 builder.input(:title, :as => :boolean, :input_html => { :tabindex => 2 })
157 end)
158 output_buffer.should_not have_tag('label[tabindex]')
159 end
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
160
260674b @justinfrench Add the HTML5 required attribute to all inputs except HiddenInput, re…
authored
161 context "when required" do
7d3bb2f @justinfrench Changed HTML5 configuration defaults from true to false fixes #662
authored
162
260674b @justinfrench Add the HTML5 required attribute to all inputs except HiddenInput, re…
authored
163 it "should add the required attribute to the input's html options" do
7d3bb2f @justinfrench Changed HTML5 configuration defaults from true to false fixes #662
authored
164 with_config :use_required_attribute, true do
165 concat(semantic_form_for(@new_post) do |builder|
166 concat(builder.input(:title, :as => :boolean, :required => true))
167 end)
168 output_buffer.should have_tag("input[@required]")
169 end
260674b @justinfrench Add the HTML5 required attribute to all inputs except HiddenInput, re…
authored
170 end
7d3bb2f @justinfrench Changed HTML5 configuration defaults from true to false fixes #662
authored
171
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
172 it "should not add the required attribute to the boolean fields input's html options" do
7d3bb2f @justinfrench Changed HTML5 configuration defaults from true to false fixes #662
authored
173 with_config :use_required_attribute, true do
174 concat(semantic_form_for(@new_post) do |builder|
175 concat(builder.input(:title, :as => :boolean))
176 end)
177 output_buffer.should_not have_tag("input[@required]")
178 end
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
179 end
7d3bb2f @justinfrench Changed HTML5 configuration defaults from true to false fixes #662
authored
180
260674b @justinfrench Add the HTML5 required attribute to all inputs except HiddenInput, re…
authored
181 end
ff296bd @asanghi Boolean fields should not use global requied default. Fixes #580
asanghi authored
182
d174db0 @asanghi change id_prefix to namespace; added documentation in README
asanghi authored
183 describe "when namespace is provided" do
717d8e8 @asanghi full(ish) implementation of namespacing a form's id prefix; more test…
asanghi authored
184
185 before do
186 @output_buffer = ''
187 mock_everything
188
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
189 concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
717d8e8 @asanghi full(ish) implementation of namespacing a form's id prefix; more test…
asanghi authored
190 concat(builder.input(:allow_comments, :as => :boolean))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
191 end)
717d8e8 @asanghi full(ish) implementation of namespacing a form's id prefix; more test…
asanghi authored
192 end
193
194 it_should_have_input_wrapper_with_id("context2_post_allow_comments_input")
2508880 @justinfrench Refactor labels CSS, add classes.
authored
195 it_should_have_an_inline_label_for("context2_post_allow_comments")
717d8e8 @asanghi full(ish) implementation of namespacing a form's id prefix; more test…
asanghi authored
196
197 end
e05bbb6 @justinfrench fix boolean input to respect :index from fields_for in input[name] at…
authored
198
199 describe "when index is provided" do
200
201 before do
202 @output_buffer = ''
203 mock_everything
204
205 concat(semantic_form_for(@new_post) do |builder|
0566774 @jslag address syntax errors with 1.9.2-p290
jslag authored
206 concat(builder.fields_for(:author, :index => 3) do |author|
e05bbb6 @justinfrench fix boolean input to respect :index from fields_for in input[name] at…
authored
207 concat(author.input(:name, :as => :boolean))
208 end)
209 end)
210 end
211
212 it 'should index the id of the wrapper' do
213 output_buffer.should have_tag("li#post_author_attributes_3_name_input")
214 end
215
216 it 'should index the id of the input tag' do
217 output_buffer.should have_tag("input#post_author_attributes_3_name")
218 end
219
220 it 'should index the name of the hidden input' do
221 output_buffer.should have_tag("input[@type='hidden'][@name='post[author_attributes][3][name]']")
222 end
223
224 it 'should index the name of the checkbox input' do
225 output_buffer.should have_tag("input[@type='checkbox'][@name='post[author_attributes][3][name]']")
226 end
227
228 end
717d8e8 @asanghi full(ish) implementation of namespacing a form's id prefix; more test…
asanghi authored
229
87037c9 @grimen Adding support for :selected option for boolean input type as well, w…
grimen authored
230 end
Something went wrong with that request. Please try again.