diff --git a/lib/capybara/rack_test/node.rb b/lib/capybara/rack_test/node.rb index 6ec66289..98d1f471 100644 --- a/lib/capybara/rack_test/node.rb +++ b/lib/capybara/rack_test/node.rb @@ -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| diff --git a/lib/capybara/spec/session/fill_in_spec.rb b/lib/capybara/spec/session/fill_in_spec.rb index be7dff24..4b8eda87 100644 --- a/lib/capybara/spec/session/fill_in_spec.rb +++ b/lib/capybara/spec/session/fill_in_spec.rb @@ -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')