Permalink
Browse files

Allow unselecting for select nodes with empty `multiple` attributes.

As well as `<select multiple="multiple" ...>`, it's also valid to
use an empty attribute (i.e. `<select multiple ... >`). In order to
support this, we need to treat `multiple` in the same way as
`disabled` or `checked`.
  • Loading branch information...
1 parent 13518d9 commit e67a30fb16bc4985d761abca1cdcdf20c25c1303 @lazyatom lazyatom committed with jferris Jul 24, 2012
Showing with 24 additions and 2 deletions.
  1. +2 −2 lib/capybara/webkit/node.rb
  2. +18 −0 spec/driver_spec.rb
  3. +4 −0 src/capybara.js
@@ -9,7 +9,7 @@ def text
def [](name)
value = invoke("attribute", name)
- if name == 'checked' || name == 'disabled'
+ if name == 'checked' || name == 'disabled' || name == 'multiple'
value == 'true'
else
value
@@ -112,7 +112,7 @@ def browser
end
def multiple_select?
- self.tag_name == "select" && self["multiple"] == "multiple"
+ self.tag_name == "select" && self["multiple"]
end
end
end
View
@@ -608,6 +608,10 @@ def in_iframe_request?
<option selected="selected" id="topping-cherry">Cherry</option>
</optgroup>
</select>
+ <select name="guitars" multiple>
+ <option selected="selected" id="fender">Fender</option>
+ <option selected="selected" id="gibson">Gibson</option>
+ </select>
<textarea id="only-textarea">what a wonderful area for text</textarea>
<input type="radio" id="only-radio" value="1"/>
<button type="reset">Reset Form</button>
@@ -679,6 +683,8 @@ def in_iframe_request?
let(:banana_option) { driver.find("//option[@id='topping-banana']").first }
let(:cherry_option) { driver.find("//option[@id='topping-cherry']").first }
let(:toppings_select) { driver.find("//select[@name='toppings']").first }
+ let(:guitars_select) { driver.find("//select[@name='guitars']").first }
+ let(:fender_option) { driver.find("//option[@id='fender']").first }
let(:reset_button) { driver.find("//button[@type='reset']").first }
context "a select element's selection has been changed" do
@@ -720,6 +726,18 @@ def in_iframe_request?
end
end
+ context "a multi-select (with empty multiple attribute) element's option has been unselected" do
+ before do
+ guitars_select.value.should include("Fender", "Gibson")
+
+ fender_option.unselect_option
+ end
+
+ it "does not return the deselected option" do
+ guitars_select.value.should_not include("Fender")
+ end
+ end
+
it "reselects an option in a multi-select" do
apple_option.unselect_option
banana_option.unselect_option
View
@@ -51,6 +51,10 @@ Capybara = {
return this.nodes[index].disabled;
break;
+ case 'multiple':
+ return this.nodes[index].multiple;
+ break;
+
default:
return this.nodes[index].getAttribute(name);
}

0 comments on commit e67a30f

Please sign in to comment.