Class: Capybara::RackTest::Form

### Home Classes Methods

### In Files

- lib/capybara/rack_test/form.rb

### Parent

Capybara::RackTest::Node

### Namespace

- CLASS Capybara::RackTest::Form::NilUploadedFile

### Methods

- #multipart?
- #params
- #submit

### Files

- another_test_file.txt
- test_file.txt

### Class/Module Index

Quicksearch

- Capybara
- Capybara::Ambiguous
- Capybara::CapybaraError
- Capybara::DSL
- Capybara::Driver
- Capybara::Driver::Base
- Capybara::Driver::Node
- Capybara::DriverNotFoundError
- Capybara::ElementNotFound
- Capybara::ExpectationNotMet
- Capybara::Features
- Capybara::FileNotFound
- Capybara::FrozenInTime
- Capybara::Helpers
- Capybara::InfiniteRedirectError
- Capybara::ModalNotFound
- Capybara::Node
- Capybara::Node::Actions
- Capybara::Node::Base
- Capybara::Node::Document
- Capybara::Node::DocumentMatchers
- Capybara::Node::Element
- Capybara::Node::Finders
- Capybara::Node::Matchers
- Capybara::Node::Simple
- Capybara::NotSupportedByDriverError
- Capybara::Queries
- Capybara::Queries::BaseQuery
- Capybara::Queries::TextQuery
- Capybara::Queries::TitleQuery
- Capybara::Query
- Capybara::RSpecMatchers
- Capybara::RSpecMatchers::BecomeClosed
- Capybara::RSpecMatchers::HaveSelector
- Capybara::RSpecMatchers::HaveText
- Capybara::RSpecMatchers::HaveTitle
- Capybara::RSpecMatchers::Matcher
- Capybara::RackTest
- Capybara::RackTest::Browser
- Capybara::RackTest::CSSHandlers
- Capybara::RackTest::Driver
- Capybara::RackTest::Form
- Capybara::RackTest::Form::NilUploadedFile
- Capybara::RackTest::Node
- Capybara::ReadOnlyElementError
- Capybara::Result
- Capybara::ScopeError
- Capybara::Selector
- Capybara::Selector::Filter
- Capybara::Selenium
- Capybara::Selenium::Driver
- Capybara::Selenium::Node
- Capybara::Server
- Capybara::Server::Middleware
- Capybara::Session
- Capybara::SpecHelper
- Capybara::UnselectNotAllowed
- Capybara::Window
- Capybara::WindowError
- TestApp
- TestApp::TestAppError
- Object

No matching classes.

# Capybara::RackTest::Form

### Public Instance Methods

multipart?() click to toggle source

    # File lib/capybara/rack_test/form.rb, line 78
    def multipart?
      self[:enctype] == "multipart/form-data"
    end

params(button) click to toggle source

    # File lib/capybara/rack_test/form.rb, line 17
    def params(button)
      params = {}

      form_element_types=[:input, :select, :textarea]
      form_elements_xpath=XPath.generate do |x|
        xpath=x.descendant(*form_element_types).where(~x.attr(:form))
        xpath=xpath.union(x.anywhere(*form_element_types).where(x.attr(:form) == native[:id])) if native[:id]
        xpath.where(~x.attr(:disabled))
      end.to_s

      native.xpath(form_elements_xpath).map do |field|
        case field.name
        when 'input'
          if %(radio checkbox).include? field['type']
            if field['checked']
              node=Capybara::RackTest::Node.new(self.driver, field)
              merge_param!(params, field['name'].to_s, node.value.to_s)
            end
          elsif %(submit image).include? field['type']
            # TO DO identify the click button here (in document order, rather
            # than leaving until the end of the params)
          elsif field['type'] =='file'
            if multipart?
              file =                if (value = field['value']).to_s.empty?
                  NilUploadedFile.new
                else
                  content_type = MIME::Types.type_for(value).first.to_s
                  Rack::Test::UploadedFile.new(value, content_type)
                end
              merge_param!(params, field['name'].to_s, file)
            else
              merge_param!(params, field['name'].to_s, File.basename(field['value'].to_s))
            end
          else
            merge_param!(params, field['name'].to_s, field['value'].to_s)
          end
        when 'select'
          if field['multiple'] == 'multiple'
            options = field.xpath(".//option[@selected]")
            options.each do |option|
              merge_param!(params, field['name'].to_s, (option['value'] || option.text).to_s)
            end
          else
            option = field.xpath(".//option[@selected]").first
            option ||= field.xpath('.//option').first
            merge_param!(params, field['name'].to_s, (option['value'] || option.text).to_s) if option
          end
        when 'textarea'
          merge_param!(params, field['name'].to_s, field.text.to_s.gsub(/\n/, "\r\n"))
        end
      end
      merge_param!(params, button[:name], button[:value] || "") if button[:name]
      params
    end

submit(button) click to toggle source

    # File lib/capybara/rack_test/form.rb, line 73
    def submit(button)
      action = (button && button['formaction']) || native['action']
      driver.submit(method, action.to_s, params(button))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.