Skip to content

Commit

Permalink
Merge remote branch 'PickLive/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jnicklas committed May 9, 2010
2 parents 5fd3744 + 73800eb commit 87aa2ca
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/capybara/driver/rack_test_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def set(value)
driver.html.xpath("//input[@name=#{Capybara::XPath.escape(self[:name])}]").each { |node| node.remove_attribute("checked") }
node['checked'] = 'checked'
elsif tag_name == 'input' and type == 'checkbox'
if value
if value && !node['checked']
node['checked'] = 'checked'
else
elsif !value && node['checked']
node.remove_attribute('checked')
end
elsif tag_name == 'input'
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/driver/selenium_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def set(value)
elsif tag_name == 'input' and type == 'radio'
node.click
elsif tag_name == 'input' and type == 'checkbox'
node.click
node.click if node.attribute('checked') != value
end
end

Expand Down
28 changes: 28 additions & 0 deletions lib/capybara/spec/session/check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ module CheckSpec
end
end

describe "checking" do
it "should not change an already checked checkbox" do
@session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
@session.check('form_pets_dog')
@session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
end

it "should check an unchecked checkbox" do
@session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
@session.check('form_pets_cat')
@session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_true
end
end

describe "unchecking" do
it "should not change an already unchecked checkbox" do
@session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
@session.uncheck('form_pets_cat')
@session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
end

it "should uncheck a checked checkbox" do
@session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
@session.uncheck('form_pets_dog')
@session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_false
end
end

it "should check a checkbox by id" do
@session.check("form_pets_cat")
@session.click_button('awesome')
Expand Down

0 comments on commit 87aa2ca

Please sign in to comment.