Class: Capybara::Driver::RackTest::Form
- Inherits:
-
Node
- Object
- Node
- Node
- Capybara::Driver::RackTest::Form
show all
- Defined in:
- lib/capybara/driver/rack_test_driver.rb
Instance Attribute Summary
Attributes inherited from Node
#driver, #node
Instance Method Summary
collapse
Methods inherited from Node
#[], #click, #select, #set, #tag_name, #text
Methods inherited from Node
#[], #click, #initialize, #select, #set, #tag_name, #text, #value
Constructor Details
This class inherits a constructor from Capybara::Node
Instance Method Details
#multipart? ⇒ Boolean
109
110
111
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 109
def multipart?
self[:enctype] == "multipart/form-data"
end
|
#params(button) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 61
def params(button)
params = []
params += node.xpath(".//input[@type='text']", ".//input[@type='hidden']", ".//input[@type='password']").inject([]) do |agg, input|
agg << [input['name'].to_s, input['value'].to_s]
agg
end
params += node.xpath(".//textarea").inject([]) do |agg, textarea|
agg << [textarea['name'].to_s, textarea.text.to_s]
agg
end
params += node.xpath(".//input[@type='radio']").inject([]) do |agg, input|
agg << [input['name'].to_s, input['value'].to_s] if input['checked']
agg
end
params += node.xpath(".//input[@type='checkbox']").inject([]) do |agg, input|
agg << [input['name'].to_s, input['value'].to_s] if input['checked']
agg
end
params += node.xpath(".//select").inject([]) do |agg, select|
option = select.xpath(".//option[@selected]").first
option ||= select.xpath('.//option').first
agg << [select['name'].to_s, (option['value'] || option.text).to_s] if option
agg
end
params += node.xpath(".//input[@type='file']").inject([]) do |agg, input|
if multipart?
agg << [input['name'].to_s, Rack::Test::UploadedFile.new(input['value'].to_s)]
else
agg << [input['name'].to_s, File.basename(input['value'].to_s)]
end
agg
end
params.push [button[:name], button[:value]] if button[:name]
if multipart?
params.inject({}) { |agg, (key, value)| agg[key] = value; agg }
else
params.map { |key, value| "#{key}=#{value}" }.join('&')
end
end
|
#post? ⇒ Boolean
113
114
115
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 113
def post?
self[:method] =~ /post/i
end
|
#submit(button) ⇒ Object
101
102
103
104
105
106
107
|
# File 'lib/capybara/driver/rack_test_driver.rb', line 101
def submit(button)
if post?
driver.submit(node['action'].to_s, params(button))
else
driver.visit(node['action'].to_s.split('?').first + '?' + params(button))
end
end
|