Cast to string if field has maxlength value, closes #989

This commit is contained in:
Jonas Nicklas 2013-03-26 21:29:25 +01:00
parent c5e46fdcc8
commit 6ce45f2efb
2 changed files with 11 additions and 5 deletions

View File

@ -79,7 +79,7 @@ class Capybara::RackTest::Node < Capybara::Driver::Node
string_node.disabled?
end
end
def path
native.path
end
@ -87,11 +87,11 @@ class Capybara::RackTest::Node < Capybara::Driver::Node
def find_xpath(locator)
native.xpath(locator).map { |n| self.class.new(driver, n) }
end
def find_css(locator)
def find_css(locator)
native.css(locator, Capybara::RackTest::CSSHandlers.new).map { |n| self.class.new(driver, n) }
end
def ==(other)
native == other.native
end
@ -153,7 +153,7 @@ private
if text_or_password? && attribute_is_not_blank?(:maxlength)
# Browser behavior for maxlength="0" is inconsistent, so we stick with
# Firefox, allowing no input
value = value[0...self[:maxlength].to_i]
value = value.to_s[0...self[:maxlength].to_i]
end
if Array === value #Assert multiple attribute is present
value.each do |v|

View File

@ -109,6 +109,12 @@ Capybara::SpecHelper.spec "#fill_in" do
extract_results(@session)['first_name'].should == 'Harry'
end
it "casts to string if field has maxlength", :focus => true do
@session.fill_in(:'form_zipcode', :with => 1234567)
@session.click_button('awesome')
extract_results(@session)['zipcode'].should == '12345'
end
context 'on a pre-populated textfield with a reformatting onchange', :requires => [:js] do
it 'should only trigger onchange once' do
@session.visit('/with_js')