add support for form attribute on input, select, and textarea elements
This commit is contained in:
parent
83d0e16799
commit
b252d8f988
|
@ -16,8 +16,9 @@ class Capybara::RackTest::Form < Capybara::RackTest::Node
|
|||
|
||||
def params(button)
|
||||
params = {}
|
||||
|
||||
native.xpath("(.//input|.//select|.//textarea)[not(@disabled)]").map do |field|
|
||||
element_query="((.//input|.//select|.//textarea)[not(@form)])"
|
||||
element_query+="|((//input|//select|//textarea)[@form='#{native[:id]}'])" if native[:id]
|
||||
native.xpath("(#{element_query})[not(@disabled)]").map do |field|
|
||||
case field.name
|
||||
when 'input'
|
||||
if %w(radio checkbox).include? field['type']
|
||||
|
|
|
@ -162,6 +162,30 @@ Capybara::SpecHelper.spec '#click_button' do
|
|||
end
|
||||
end
|
||||
|
||||
context "with fields associated with the form using the form attribute" do
|
||||
before do
|
||||
@session.click_button('submit_form1')
|
||||
@results = extract_results(@session)
|
||||
end
|
||||
|
||||
it "should serialize and submit text fields" do
|
||||
@results['outside_input'].should == 'outside_input'
|
||||
end
|
||||
|
||||
it "should serialize text areas" do
|
||||
@results['outside_textarea'].should == 'Some text here'
|
||||
end
|
||||
|
||||
it "should serialize select tags" do
|
||||
@results['outside_select'].should == 'Ruby'
|
||||
end
|
||||
|
||||
it "should not serliaze fields associated with a different form" do
|
||||
@results['for_form2'].should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "with submit button outside the form defined by <button> tag" do
|
||||
before do
|
||||
@session.click_button('outside_button')
|
||||
|
@ -190,7 +214,7 @@ Capybara::SpecHelper.spec '#click_button' do
|
|||
|
||||
it "should submit the button that was clicked, but not other buttons" do
|
||||
@results['outside_submit'].should == 'outside_submit'
|
||||
@results['unused'].should be_nil
|
||||
@results['submit_form1'].should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -257,9 +257,12 @@
|
|||
</p>
|
||||
</form>
|
||||
|
||||
<input type="text" name="form[outside_input]" value="outside_input" form="form1"/>
|
||||
|
||||
<form id="form1" action="/form" method="post">
|
||||
<input type="text" name="form[which_form]" value="form1" id="form_which_form"/>
|
||||
<input type="submit" name="form[unused]" value="unused"/>
|
||||
<input type="text" name="form[for_form2]" value="for_form2" form="form2"/>
|
||||
<input type="submit" name="form[submit_form1]" value="submit_form1" id="submit_form1"/>
|
||||
</form>
|
||||
|
||||
<form id="form2" action="/form" method="post">
|
||||
|
@ -268,6 +271,13 @@
|
|||
<button type="submit" name="form[other_form_button]" value="other_form_button" form="form1">Form1</button>
|
||||
</form>
|
||||
|
||||
<textarea name="form[outside_textarea]" form="form1">Some text here</textarea>
|
||||
<select name="form[outside_select]" form="form1">
|
||||
<option>Lisp</option>
|
||||
<option selected="selected">Ruby</option>
|
||||
<option>Php</option>
|
||||
</select>
|
||||
|
||||
<input type="submit" name="form[outside_submit]" value="outside_submit" form="form1"/>
|
||||
<button type="submit" name="form[outside_button]" value="outside_button" form="form2">Outside!</button>
|
||||
|
||||
|
|
Loading…
Reference in New Issue