Capybara::Driver::RackTest::Form

Public Instance Methods

multipart?() click to toggle source
# File lib/capybara/driver/rack_test_driver.rb, line 162
def multipart?
  self[:enctype] == "multipart/form-data"
end
params(button) click to toggle source
# File lib/capybara/driver/rack_test_driver.rb, line 119
def params(button)
  params = {}

  node.xpath(".//input[not(@type) or (@type!='radio' and @type!='checkbox' and @type!='submit' and @type!='image')]").map do |input|
    merge_param!(params, input['name'].to_s, input['value'].to_s)
  end
  node.xpath(".//textarea").map do |textarea|
    merge_param!(params, textarea['name'].to_s, textarea.text.to_s)
  end
  node.xpath(".//input[@type='radio' or @type='checkbox']").map do |input|
    merge_param!(params, input['name'].to_s, input['value'].to_s) if input['checked']
  end
  node.xpath(".//select").map do |select|
    if select['multiple'] == 'multiple'
      options = select.xpath(".//option[@selected]")
      options.each do |option|
        merge_param!(params, select['name'].to_s, (option['value'] || option.text).to_s)
      end
    else
      option = select.xpath(".//option[@selected]").first
      option ||= select.xpath('.//option').first
      merge_param!(params, select['name'].to_s, (option['value'] || option.text).to_s) if option
    end
  end
  node.xpath(".//input[@type='file']").map do |input|
    unless input['value'].to_s.empty?
      if multipart?
        content_type = MIME::Types.type_for(input['value'].to_s).first.to_s
        file = Rack::Test::UploadedFile.new(input['value'].to_s, content_type)
        merge_param!(params, input['name'].to_s, file)
      else
        merge_param!(params, input['name'].to_s, File.basename(input['value'].to_s))
      end
    end
  end
  merge_param!(params, button[:name], button[:value] || "") if button[:name]
  params
end
submit(button) click to toggle source
# File lib/capybara/driver/rack_test_driver.rb, line 158
def submit(button)
  driver.submit(method, node['action'].to_s, params(button))
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.