webrat 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +140 -30
- data/README.rdoc +85 -0
- data/Rakefile +72 -22
- data/install.rb +1 -1
- data/lib/webrat.rb +12 -17
- data/lib/webrat/core.rb +9 -7
- data/lib/webrat/core/configuration.rb +87 -0
- data/lib/webrat/core/{area.rb → elements/area.rb} +7 -20
- data/lib/webrat/core/elements/element.rb +33 -0
- data/lib/webrat/core/elements/field.rb +394 -0
- data/lib/webrat/core/elements/form.rb +103 -0
- data/lib/webrat/core/elements/label.rb +31 -0
- data/lib/webrat/core/{link.rb → elements/link.rb} +15 -26
- data/lib/webrat/core/elements/select_option.rb +35 -0
- data/lib/webrat/core/locators.rb +13 -85
- data/lib/webrat/core/locators/area_locator.rb +38 -0
- data/lib/webrat/core/locators/button_locator.rb +54 -0
- data/lib/webrat/core/locators/field_by_id_locator.rb +37 -0
- data/lib/webrat/core/locators/field_labeled_locator.rb +56 -0
- data/lib/webrat/core/locators/field_locator.rb +25 -0
- data/lib/webrat/core/locators/field_named_locator.rb +41 -0
- data/lib/webrat/core/locators/form_locator.rb +19 -0
- data/lib/webrat/core/locators/label_locator.rb +34 -0
- data/lib/webrat/core/locators/link_locator.rb +66 -0
- data/lib/webrat/core/locators/locator.rb +20 -0
- data/lib/webrat/core/locators/select_option_locator.rb +59 -0
- data/lib/webrat/core/logging.rb +5 -9
- data/lib/webrat/core/matchers/have_content.rb +19 -44
- data/lib/webrat/core/matchers/have_selector.rb +15 -2
- data/lib/webrat/core/matchers/have_tag.rb +15 -2
- data/lib/webrat/core/matchers/have_xpath.rb +21 -28
- data/lib/webrat/core/methods.rb +32 -15
- data/lib/webrat/core/mime.rb +3 -3
- data/lib/webrat/core/save_and_open_page.rb +50 -0
- data/lib/webrat/core/scope.rb +183 -41
- data/lib/webrat/core/session.rb +125 -63
- data/lib/webrat/core/xml.rb +115 -0
- data/lib/webrat/core/xml/hpricot.rb +19 -0
- data/lib/webrat/core/xml/nokogiri.rb +76 -0
- data/lib/webrat/core/xml/rexml.rb +24 -0
- data/lib/webrat/core_extensions/deprecate.rb +1 -1
- data/lib/webrat/mechanize.rb +58 -12
- data/lib/webrat/merb.rb +7 -73
- data/lib/webrat/merb_session.rb +65 -0
- data/lib/webrat/rack.rb +1 -1
- data/lib/webrat/rails.rb +56 -55
- data/lib/webrat/rspec-rails.rb +13 -0
- data/lib/webrat/selenium.rb +92 -1
- data/lib/webrat/selenium/matchers.rb +146 -0
- data/lib/webrat/selenium/selenium_session.rb +179 -80
- data/lib/webrat/sinatra.rb +14 -4
- data/vendor/selenium-server.jar +0 -0
- metadata +36 -17
- data/README.txt +0 -90
- data/TODO.txt +0 -10
- data/init.rb +0 -3
- data/lib/webrat/core/field.rb +0 -332
- data/lib/webrat/core/flunk.rb +0 -7
- data/lib/webrat/core/form.rb +0 -130
- data/lib/webrat/core/label.rb +0 -18
- data/lib/webrat/core/nokogiri.rb +0 -44
- data/lib/webrat/core/select_option.rb +0 -29
- data/lib/webrat/rails/redirect_actions.rb +0 -18
data/lib/webrat/sinatra.rb
CHANGED
@@ -2,18 +2,28 @@ require 'webrat/rack'
|
|
2
2
|
require 'sinatra'
|
3
3
|
require 'sinatra/test/methods'
|
4
4
|
|
5
|
+
class Sinatra::Application
|
6
|
+
# Override this to prevent Sinatra from barfing on the options passed from RSpec
|
7
|
+
def self.load_default_options_from_command_line!
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
disable :run
|
12
|
+
disable :reload
|
13
|
+
|
5
14
|
module Webrat
|
6
15
|
class SinatraSession < RackSession #:nodoc:
|
7
16
|
include Sinatra::Test::Methods
|
8
17
|
|
18
|
+
attr_reader :request, :response
|
19
|
+
|
9
20
|
%w(get head post put delete).each do |verb|
|
10
21
|
define_method(verb) do |*args| # (path, data, headers = nil)
|
11
22
|
path, data, headers = *args
|
12
|
-
|
23
|
+
data = data.inject({}) {|data, (key,value)| data[key] = Rack::Utils.unescape(value); data }
|
24
|
+
params = data.merge(:env => headers || {})
|
13
25
|
self.__send__("#{verb}_it", path, params)
|
14
|
-
follow! while @response.redirect?
|
15
26
|
end
|
16
27
|
end
|
17
|
-
|
18
28
|
end
|
19
|
-
end
|
29
|
+
end
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webrat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Helmkamp
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-18 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -29,24 +29,37 @@ executables: []
|
|
29
29
|
extensions: []
|
30
30
|
|
31
31
|
extra_rdoc_files:
|
32
|
-
- README.
|
32
|
+
- README.rdoc
|
33
33
|
- MIT-LICENSE.txt
|
34
34
|
files:
|
35
35
|
- History.txt
|
36
|
-
- init.rb
|
37
36
|
- install.rb
|
38
37
|
- MIT-LICENSE.txt
|
39
|
-
- README.
|
38
|
+
- README.rdoc
|
40
39
|
- Rakefile
|
41
|
-
- TODO.txt
|
42
40
|
- lib/webrat
|
43
41
|
- lib/webrat/core
|
44
|
-
- lib/webrat/core/
|
45
|
-
- lib/webrat/core/
|
46
|
-
- lib/webrat/core/
|
47
|
-
- lib/webrat/core/
|
48
|
-
- lib/webrat/core/
|
49
|
-
- lib/webrat/core/
|
42
|
+
- lib/webrat/core/configuration.rb
|
43
|
+
- lib/webrat/core/elements
|
44
|
+
- lib/webrat/core/elements/area.rb
|
45
|
+
- lib/webrat/core/elements/element.rb
|
46
|
+
- lib/webrat/core/elements/field.rb
|
47
|
+
- lib/webrat/core/elements/form.rb
|
48
|
+
- lib/webrat/core/elements/label.rb
|
49
|
+
- lib/webrat/core/elements/link.rb
|
50
|
+
- lib/webrat/core/elements/select_option.rb
|
51
|
+
- lib/webrat/core/locators
|
52
|
+
- lib/webrat/core/locators/area_locator.rb
|
53
|
+
- lib/webrat/core/locators/button_locator.rb
|
54
|
+
- lib/webrat/core/locators/field_by_id_locator.rb
|
55
|
+
- lib/webrat/core/locators/field_labeled_locator.rb
|
56
|
+
- lib/webrat/core/locators/field_locator.rb
|
57
|
+
- lib/webrat/core/locators/field_named_locator.rb
|
58
|
+
- lib/webrat/core/locators/form_locator.rb
|
59
|
+
- lib/webrat/core/locators/label_locator.rb
|
60
|
+
- lib/webrat/core/locators/link_locator.rb
|
61
|
+
- lib/webrat/core/locators/locator.rb
|
62
|
+
- lib/webrat/core/locators/select_option_locator.rb
|
50
63
|
- lib/webrat/core/locators.rb
|
51
64
|
- lib/webrat/core/logging.rb
|
52
65
|
- lib/webrat/core/matchers
|
@@ -57,10 +70,14 @@ files:
|
|
57
70
|
- lib/webrat/core/matchers.rb
|
58
71
|
- lib/webrat/core/methods.rb
|
59
72
|
- lib/webrat/core/mime.rb
|
60
|
-
- lib/webrat/core/
|
73
|
+
- lib/webrat/core/save_and_open_page.rb
|
61
74
|
- lib/webrat/core/scope.rb
|
62
|
-
- lib/webrat/core/select_option.rb
|
63
75
|
- lib/webrat/core/session.rb
|
76
|
+
- lib/webrat/core/xml
|
77
|
+
- lib/webrat/core/xml/hpricot.rb
|
78
|
+
- lib/webrat/core/xml/nokogiri.rb
|
79
|
+
- lib/webrat/core/xml/rexml.rb
|
80
|
+
- lib/webrat/core/xml.rb
|
64
81
|
- lib/webrat/core.rb
|
65
82
|
- lib/webrat/core_extensions
|
66
83
|
- lib/webrat/core_extensions/blank.rb
|
@@ -71,10 +88,10 @@ files:
|
|
71
88
|
- lib/webrat/core_extensions/nil_to_param.rb
|
72
89
|
- lib/webrat/mechanize.rb
|
73
90
|
- lib/webrat/merb.rb
|
91
|
+
- lib/webrat/merb_session.rb
|
74
92
|
- lib/webrat/rack.rb
|
75
|
-
- lib/webrat/rails
|
76
|
-
- lib/webrat/rails/redirect_actions.rb
|
77
93
|
- lib/webrat/rails.rb
|
94
|
+
- lib/webrat/rspec-rails.rb
|
78
95
|
- lib/webrat/selenium
|
79
96
|
- lib/webrat/selenium/location_strategy_javascript
|
80
97
|
- lib/webrat/selenium/location_strategy_javascript/button.js
|
@@ -83,11 +100,13 @@ files:
|
|
83
100
|
- lib/webrat/selenium/location_strategy_javascript/webratlink.js
|
84
101
|
- lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js
|
85
102
|
- lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js
|
103
|
+
- lib/webrat/selenium/matchers.rb
|
86
104
|
- lib/webrat/selenium/selenium_extensions.js
|
87
105
|
- lib/webrat/selenium/selenium_session.rb
|
88
106
|
- lib/webrat/selenium.rb
|
89
107
|
- lib/webrat/sinatra.rb
|
90
108
|
- lib/webrat.rb
|
109
|
+
- vendor/selenium-server.jar
|
91
110
|
has_rdoc: true
|
92
111
|
homepage: http://github.com/brynary/webrat
|
93
112
|
post_install_message:
|
@@ -109,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
128
|
version:
|
110
129
|
requirements: []
|
111
130
|
|
112
|
-
rubyforge_project:
|
131
|
+
rubyforge_project: webrat
|
113
132
|
rubygems_version: 1.3.1
|
114
133
|
signing_key:
|
115
134
|
specification_version: 2
|
data/README.txt
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
=== Webrat
|
2
|
-
|
3
|
-
- [Code on GitHub](http://github.com/brynary/webrat)
|
4
|
-
- [Tickets on Lighthouse](http://webrat.lighthouseapp.com/)
|
5
|
-
|
6
|
-
=== Description
|
7
|
-
|
8
|
-
Webrat (_Ruby Acceptance Testing for Web applications_)
|
9
|
-
lets you quickly write robust and thorough acceptance tests for a Ruby
|
10
|
-
web application. By leveraging the DOM, it can run tests similarly to an
|
11
|
-
in-browser testing solution without the associated performance hit (and
|
12
|
-
browser dependency). The result is tests that are less fragile and more
|
13
|
-
effective at verifying that the app will respond properly to users.
|
14
|
-
|
15
|
-
When comparing Webrat with an in-browser testing solution like Watir or
|
16
|
-
Selenium, the primary consideration should be how much JavaScript the
|
17
|
-
application uses. In-browser testing is currently the only way to test JS, and
|
18
|
-
that may make it a requirement for your project. If JavaScript is not central
|
19
|
-
to your application, Webrat is a simpler, effective solution that will let you
|
20
|
-
run your tests much faster and more frequently.
|
21
|
-
|
22
|
-
Initial development was sponsored by [EastMedia](http://www.eastmedia.com).
|
23
|
-
|
24
|
-
=== Synopsis
|
25
|
-
|
26
|
-
def test_sign_up
|
27
|
-
visit "/"
|
28
|
-
click_link "Sign up"
|
29
|
-
fill_in "Email", :with => "good@example.com"
|
30
|
-
select "Free account"
|
31
|
-
click_button "Register"
|
32
|
-
...
|
33
|
-
end
|
34
|
-
|
35
|
-
Behind the scenes, this will perform the following work:
|
36
|
-
|
37
|
-
1. Verify that loading the home page is successful
|
38
|
-
2. Verify that a "Sign up" link exists on the home page
|
39
|
-
3. Verify that loading the URL pointed to by the "Sign up" link leads to a
|
40
|
-
successful page
|
41
|
-
4. Verify that there is an "Email" input field on the Sign Up page
|
42
|
-
5. Verify that there is an select field on the Sign Up page with an option for
|
43
|
-
"Free account"
|
44
|
-
6. Verify that there is a "Register" submit button on the page
|
45
|
-
7. Verify that submitting the Sign Up form with the values "good@example.com"
|
46
|
-
and "Free account" leads to a successful page
|
47
|
-
|
48
|
-
Take special note of the things _not_ specified in that test, that might cause
|
49
|
-
tests to break unnecessarily as your application evolves:
|
50
|
-
|
51
|
-
- The input field IDs or names (e.g. "user_email" or "user[email]"), which
|
52
|
-
could change if you rename a model
|
53
|
-
- The ID of the form element (Webrat can do a good job of guessing, even if
|
54
|
-
there are multiple forms on the page.)
|
55
|
-
- The URLs of links followed
|
56
|
-
- The URL the form submission should be sent to, which could change if you
|
57
|
-
adjust your routes or controllers
|
58
|
-
- The HTTP method for the login request
|
59
|
-
|
60
|
-
A test written with Webrat can handle these changes to these without any modifications.
|
61
|
-
|
62
|
-
=== Merb
|
63
|
-
To avoid losing sessions, you need this in environments/test.rb:
|
64
|
-
|
65
|
-
Merb::Config.use do |c|
|
66
|
-
c[:session_store] = 'memory'
|
67
|
-
end
|
68
|
-
|
69
|
-
=== Install
|
70
|
-
|
71
|
-
To install the latest release:
|
72
|
-
|
73
|
-
sudo gem install webrat
|
74
|
-
|
75
|
-
In your stories/helper.rb:
|
76
|
-
|
77
|
-
require "webrat"
|
78
|
-
|
79
|
-
You could also unpack the gem into vendor/plugins.
|
80
|
-
|
81
|
-
=== Authors
|
82
|
-
|
83
|
-
- Maintained by [Bryan Helmkamp](mailto:bryan@brynary.com)
|
84
|
-
- Original code written by [Seth Fitzsimmons](mailto:seth@mojodna.net)
|
85
|
-
- Many other contributors. See attributions in History.txt
|
86
|
-
|
87
|
-
=== License
|
88
|
-
|
89
|
-
Copyright (c) 2007 Bryan Helmkamp, Seth Fitzsimmons.
|
90
|
-
See MIT-LICENSE.txt in this directory.
|
data/TODO.txt
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
Run tests in separate processes to eliminate constant-level dependencies
|
2
|
-
Add rake tasks for selenium runs
|
3
|
-
Add tests for selenium
|
4
|
-
Add tests for locator strategies
|
5
|
-
Use Webrat::Methods for Rails integration
|
6
|
-
Get file uploads workign with merb
|
7
|
-
Fix #within scoping for forms that exist outside the scope
|
8
|
-
Make current_url work with redirections
|
9
|
-
Track the current form based on the location of the last manipulated input, use this as a default for click_button
|
10
|
-
Verify SSL support in Rails and Merb
|
data/init.rb
DELETED
data/lib/webrat/core/field.rb
DELETED
@@ -1,332 +0,0 @@
|
|
1
|
-
require "cgi"
|
2
|
-
require "webrat/core_extensions/blank"
|
3
|
-
require "webrat/core_extensions/nil_to_param"
|
4
|
-
|
5
|
-
module Webrat
|
6
|
-
class Field #:nodoc:
|
7
|
-
|
8
|
-
def self.class_for_element(element)
|
9
|
-
if element.name == "input"
|
10
|
-
if %w[submit image].include?(element["type"])
|
11
|
-
field_class = "button"
|
12
|
-
else
|
13
|
-
field_class = element["type"] || "text" #default type; 'type' attribute is not mandatory
|
14
|
-
end
|
15
|
-
else
|
16
|
-
field_class = element.name
|
17
|
-
end
|
18
|
-
Webrat.const_get("#{field_class.capitalize}Field")
|
19
|
-
rescue NameError
|
20
|
-
raise "Invalid field element: #{element.inspect}"
|
21
|
-
end
|
22
|
-
|
23
|
-
def initialize(form, element)
|
24
|
-
@form = form
|
25
|
-
@element = element
|
26
|
-
|
27
|
-
@value = default_value
|
28
|
-
end
|
29
|
-
|
30
|
-
def label_text
|
31
|
-
return nil if labels.empty?
|
32
|
-
labels.first.text
|
33
|
-
end
|
34
|
-
|
35
|
-
def matches_id?(id)
|
36
|
-
@element["id"] == id.to_s
|
37
|
-
end
|
38
|
-
|
39
|
-
def matches_name?(name)
|
40
|
-
@element["name"] == name.to_s
|
41
|
-
end
|
42
|
-
|
43
|
-
def matches_label?(label_text)
|
44
|
-
return false if labels.empty?
|
45
|
-
labels.any? { |label| label.matches_text?(label_text) }
|
46
|
-
end
|
47
|
-
|
48
|
-
def matches_alt?(alt)
|
49
|
-
@element["alt"] =~ /^\W*#{Regexp.escape(alt.to_s)}/i
|
50
|
-
end
|
51
|
-
|
52
|
-
def disabled?
|
53
|
-
@element.attributes.has_key?("disabled") && @element["disabled"] != 'false'
|
54
|
-
end
|
55
|
-
|
56
|
-
def raise_error_if_disabled
|
57
|
-
raise "Cannot interact with disabled form element (#{self})" if disabled?
|
58
|
-
end
|
59
|
-
|
60
|
-
def to_param
|
61
|
-
return nil if disabled?
|
62
|
-
|
63
|
-
key_and_value = "#{name}=#{escaped_value}"
|
64
|
-
|
65
|
-
if defined?(CGIMethods)
|
66
|
-
CGIMethods.parse_query_parameters(key_and_value)
|
67
|
-
elsif defined?(ActionController::AbstractRequest)
|
68
|
-
ActionController::AbstractRequest.parse_query_parameters(key_and_value)
|
69
|
-
else
|
70
|
-
::Merb::Parse.query(key_and_value)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def set(value)
|
75
|
-
@value = value
|
76
|
-
end
|
77
|
-
|
78
|
-
def unset
|
79
|
-
@value = default_value
|
80
|
-
end
|
81
|
-
|
82
|
-
protected
|
83
|
-
|
84
|
-
def id
|
85
|
-
@element["id"]
|
86
|
-
end
|
87
|
-
|
88
|
-
def name
|
89
|
-
@element["name"]
|
90
|
-
end
|
91
|
-
|
92
|
-
def escaped_value
|
93
|
-
CGI.escape(@value.to_s)
|
94
|
-
end
|
95
|
-
|
96
|
-
def labels
|
97
|
-
@labels ||= label_elements.map { |element| Label.new(self, element) }
|
98
|
-
end
|
99
|
-
|
100
|
-
def label_elements
|
101
|
-
return @label_elements unless @label_elements.nil?
|
102
|
-
@label_elements = []
|
103
|
-
|
104
|
-
parent = @element.parent
|
105
|
-
while parent.respond_to?(:parent)
|
106
|
-
if parent.name == 'label'
|
107
|
-
@label_elements.push parent
|
108
|
-
break
|
109
|
-
end
|
110
|
-
parent = parent.parent
|
111
|
-
end
|
112
|
-
|
113
|
-
unless id.blank?
|
114
|
-
@label_elements += @form.element.search("label[@for='#{id}']")
|
115
|
-
end
|
116
|
-
|
117
|
-
@label_elements
|
118
|
-
end
|
119
|
-
|
120
|
-
def default_value
|
121
|
-
@element["value"]
|
122
|
-
end
|
123
|
-
|
124
|
-
def replace_param_value(params, oval, nval)
|
125
|
-
output = Hash.new
|
126
|
-
params.each do |key, value|
|
127
|
-
case value
|
128
|
-
when Hash
|
129
|
-
value = replace_param_value(value, oval, nval)
|
130
|
-
when Array
|
131
|
-
value = value.map { |o| o == oval ? nval : oval }
|
132
|
-
when oval
|
133
|
-
value = nval
|
134
|
-
end
|
135
|
-
output[key] = value
|
136
|
-
end
|
137
|
-
output
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
class ButtonField < Field #:nodoc:
|
142
|
-
|
143
|
-
def matches_text?(text)
|
144
|
-
@element.inner_html =~ /#{Regexp.escape(text.to_s)}/i
|
145
|
-
end
|
146
|
-
|
147
|
-
def matches_value?(value)
|
148
|
-
@element["value"] =~ /^\W*#{Regexp.escape(value.to_s)}/i || matches_text?(value) || matches_alt?(value)
|
149
|
-
end
|
150
|
-
|
151
|
-
def to_param
|
152
|
-
return nil if @value.nil?
|
153
|
-
super
|
154
|
-
end
|
155
|
-
|
156
|
-
def default_value
|
157
|
-
nil
|
158
|
-
end
|
159
|
-
|
160
|
-
def click
|
161
|
-
raise_error_if_disabled
|
162
|
-
set(@element["value"]) unless @element["name"].blank?
|
163
|
-
@form.submit
|
164
|
-
end
|
165
|
-
|
166
|
-
end
|
167
|
-
|
168
|
-
class HiddenField < Field #:nodoc:
|
169
|
-
|
170
|
-
def to_param
|
171
|
-
if collection_name?
|
172
|
-
super
|
173
|
-
else
|
174
|
-
checkbox_with_same_name = @form.field(name, CheckboxField)
|
175
|
-
|
176
|
-
if checkbox_with_same_name.to_param.blank?
|
177
|
-
super
|
178
|
-
else
|
179
|
-
nil
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
protected
|
185
|
-
|
186
|
-
def collection_name?
|
187
|
-
name =~ /\[\]/
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
191
|
-
|
192
|
-
class CheckboxField < Field #:nodoc:
|
193
|
-
|
194
|
-
def to_param
|
195
|
-
return nil if @value.nil?
|
196
|
-
super
|
197
|
-
end
|
198
|
-
|
199
|
-
def check
|
200
|
-
raise_error_if_disabled
|
201
|
-
set(@element["value"] || "on")
|
202
|
-
end
|
203
|
-
|
204
|
-
def checked?
|
205
|
-
@element["checked"] == "checked"
|
206
|
-
end
|
207
|
-
|
208
|
-
def uncheck
|
209
|
-
raise_error_if_disabled
|
210
|
-
set(nil)
|
211
|
-
end
|
212
|
-
|
213
|
-
protected
|
214
|
-
|
215
|
-
def default_value
|
216
|
-
if @element["checked"] == "checked"
|
217
|
-
@element["value"] || "on"
|
218
|
-
else
|
219
|
-
nil
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
end
|
224
|
-
|
225
|
-
class PasswordField < Field #:nodoc:
|
226
|
-
end
|
227
|
-
|
228
|
-
class RadioField < Field #:nodoc:
|
229
|
-
|
230
|
-
def to_param
|
231
|
-
return nil if @value.nil?
|
232
|
-
super
|
233
|
-
end
|
234
|
-
|
235
|
-
def choose
|
236
|
-
raise_error_if_disabled
|
237
|
-
other_options.each do |option|
|
238
|
-
option.set(nil)
|
239
|
-
end
|
240
|
-
|
241
|
-
set(@element["value"] || "on")
|
242
|
-
end
|
243
|
-
|
244
|
-
protected
|
245
|
-
|
246
|
-
def other_options
|
247
|
-
@form.fields.select { |f| f.name == name }
|
248
|
-
end
|
249
|
-
|
250
|
-
def default_value
|
251
|
-
if @element["checked"] == "checked"
|
252
|
-
@element["value"] || "on"
|
253
|
-
else
|
254
|
-
nil
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
end
|
259
|
-
|
260
|
-
class TextareaField < Field #:nodoc:
|
261
|
-
|
262
|
-
protected
|
263
|
-
|
264
|
-
def default_value
|
265
|
-
@element.inner_html
|
266
|
-
end
|
267
|
-
|
268
|
-
end
|
269
|
-
|
270
|
-
class FileField < Field #:nodoc:
|
271
|
-
|
272
|
-
attr_accessor :content_type
|
273
|
-
|
274
|
-
def set(value, content_type = nil)
|
275
|
-
super(value)
|
276
|
-
@content_type = content_type
|
277
|
-
end
|
278
|
-
|
279
|
-
def to_param
|
280
|
-
if @value.nil?
|
281
|
-
super
|
282
|
-
else
|
283
|
-
replace_param_value(super, @value, test_uploaded_file)
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
protected
|
288
|
-
|
289
|
-
def test_uploaded_file
|
290
|
-
if content_type
|
291
|
-
ActionController::TestUploadedFile.new(@value, content_type)
|
292
|
-
else
|
293
|
-
ActionController::TestUploadedFile.new(@value)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
end
|
298
|
-
|
299
|
-
class TextField < Field #:nodoc:
|
300
|
-
end
|
301
|
-
|
302
|
-
class ResetField < Field #:nodoc:
|
303
|
-
end
|
304
|
-
|
305
|
-
class SelectField < Field #:nodoc:
|
306
|
-
|
307
|
-
def find_option(text)
|
308
|
-
options.detect { |o| o.matches_text?(text) }
|
309
|
-
end
|
310
|
-
|
311
|
-
protected
|
312
|
-
|
313
|
-
def default_value
|
314
|
-
selected_options = @element.search(".//option[@selected='selected']")
|
315
|
-
selected_options = @element.search(".//option[position() = 1]") if selected_options.empty?
|
316
|
-
|
317
|
-
selected_options.map do |option|
|
318
|
-
return "" if option.nil?
|
319
|
-
option["value"] || option.inner_html
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
def options
|
324
|
-
option_elements.map { |oe| SelectOption.new(self, oe) }
|
325
|
-
end
|
326
|
-
|
327
|
-
def option_elements
|
328
|
-
@element.search(".//option")
|
329
|
-
end
|
330
|
-
|
331
|
-
end
|
332
|
-
end
|