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

@ -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')