integrity 0.1.9 → 0.1.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. data/Rakefile +57 -31
  2. data/config/heroku/.gems +4 -0
  3. data/config/heroku/Rakefile +6 -0
  4. data/config/heroku/config.ru +7 -0
  5. data/config/heroku/integrity-config.rb +11 -0
  6. data/integrity.gemspec +123 -0
  7. data/lib/integrity.rb +7 -14
  8. data/lib/integrity/installer.rb +45 -35
  9. data/lib/integrity/notifier/test.rb +59 -0
  10. data/lib/integrity/notifier/test/fixtures.rb +108 -0
  11. data/lib/integrity/notifier/test/hpricot_matcher.rb +38 -0
  12. data/test/acceptance/build_notifications_test.rb +2 -2
  13. data/test/acceptance/installer_test.rb +25 -7
  14. data/test/helpers.rb +1 -1
  15. data/test/helpers/acceptance.rb +1 -4
  16. data/test/helpers/fixtures.rb +0 -22
  17. data/test/unit/notifier/test_test.rb +29 -0
  18. data/test/unit/project_builder_test.rb +4 -1
  19. data/vendor/sinatra-ditties/README.rdoc +3 -0
  20. data/vendor/sinatra-ditties/lib/sinatra/ditties.rb +12 -0
  21. data/vendor/sinatra-ditties/lib/sinatra/ditties/authorization.rb +61 -0
  22. data/vendor/sinatra-ditties/lib/sinatra/ditties/mailer.rb +146 -0
  23. metadata +79 -318
  24. data/VERSION.yml +0 -4
  25. data/config/config.ru +0 -29
  26. data/config/config.yml +0 -34
  27. data/lib/integrity/notifier/test_helpers.rb +0 -100
  28. data/vendor/webrat/History.txt +0 -306
  29. data/vendor/webrat/MIT-LICENSE.txt +0 -19
  30. data/vendor/webrat/README.rdoc +0 -85
  31. data/vendor/webrat/Rakefile +0 -151
  32. data/vendor/webrat/install.rb +0 -1
  33. data/vendor/webrat/lib/webrat.rb +0 -34
  34. data/vendor/webrat/lib/webrat/core.rb +0 -14
  35. data/vendor/webrat/lib/webrat/core/configuration.rb +0 -98
  36. data/vendor/webrat/lib/webrat/core/elements/area.rb +0 -31
  37. data/vendor/webrat/lib/webrat/core/elements/element.rb +0 -33
  38. data/vendor/webrat/lib/webrat/core/elements/field.rb +0 -403
  39. data/vendor/webrat/lib/webrat/core/elements/form.rb +0 -103
  40. data/vendor/webrat/lib/webrat/core/elements/label.rb +0 -31
  41. data/vendor/webrat/lib/webrat/core/elements/link.rb +0 -90
  42. data/vendor/webrat/lib/webrat/core/elements/select_option.rb +0 -35
  43. data/vendor/webrat/lib/webrat/core/locators.rb +0 -20
  44. data/vendor/webrat/lib/webrat/core/locators/area_locator.rb +0 -38
  45. data/vendor/webrat/lib/webrat/core/locators/button_locator.rb +0 -54
  46. data/vendor/webrat/lib/webrat/core/locators/field_by_id_locator.rb +0 -37
  47. data/vendor/webrat/lib/webrat/core/locators/field_labeled_locator.rb +0 -56
  48. data/vendor/webrat/lib/webrat/core/locators/field_locator.rb +0 -25
  49. data/vendor/webrat/lib/webrat/core/locators/field_named_locator.rb +0 -41
  50. data/vendor/webrat/lib/webrat/core/locators/form_locator.rb +0 -19
  51. data/vendor/webrat/lib/webrat/core/locators/label_locator.rb +0 -34
  52. data/vendor/webrat/lib/webrat/core/locators/link_locator.rb +0 -66
  53. data/vendor/webrat/lib/webrat/core/locators/locator.rb +0 -20
  54. data/vendor/webrat/lib/webrat/core/locators/select_option_locator.rb +0 -59
  55. data/vendor/webrat/lib/webrat/core/logging.rb +0 -21
  56. data/vendor/webrat/lib/webrat/core/matchers.rb +0 -4
  57. data/vendor/webrat/lib/webrat/core/matchers/have_content.rb +0 -73
  58. data/vendor/webrat/lib/webrat/core/matchers/have_selector.rb +0 -74
  59. data/vendor/webrat/lib/webrat/core/matchers/have_tag.rb +0 -21
  60. data/vendor/webrat/lib/webrat/core/matchers/have_xpath.rb +0 -147
  61. data/vendor/webrat/lib/webrat/core/methods.rb +0 -61
  62. data/vendor/webrat/lib/webrat/core/mime.rb +0 -29
  63. data/vendor/webrat/lib/webrat/core/save_and_open_page.rb +0 -50
  64. data/vendor/webrat/lib/webrat/core/scope.rb +0 -350
  65. data/vendor/webrat/lib/webrat/core/session.rb +0 -281
  66. data/vendor/webrat/lib/webrat/core/xml.rb +0 -115
  67. data/vendor/webrat/lib/webrat/core/xml/hpricot.rb +0 -19
  68. data/vendor/webrat/lib/webrat/core/xml/nokogiri.rb +0 -76
  69. data/vendor/webrat/lib/webrat/core/xml/rexml.rb +0 -24
  70. data/vendor/webrat/lib/webrat/core_extensions/blank.rb +0 -58
  71. data/vendor/webrat/lib/webrat/core_extensions/deprecate.rb +0 -8
  72. data/vendor/webrat/lib/webrat/core_extensions/detect_mapped.rb +0 -12
  73. data/vendor/webrat/lib/webrat/core_extensions/meta_class.rb +0 -6
  74. data/vendor/webrat/lib/webrat/core_extensions/nil_to_param.rb +0 -5
  75. data/vendor/webrat/lib/webrat/mechanize.rb +0 -74
  76. data/vendor/webrat/lib/webrat/merb.rb +0 -9
  77. data/vendor/webrat/lib/webrat/merb_session.rb +0 -65
  78. data/vendor/webrat/lib/webrat/rack.rb +0 -24
  79. data/vendor/webrat/lib/webrat/rails.rb +0 -105
  80. data/vendor/webrat/lib/webrat/rspec-rails.rb +0 -13
  81. data/vendor/webrat/lib/webrat/selenium.rb +0 -154
  82. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/button.js +0 -12
  83. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/label.js +0 -16
  84. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/webrat.js +0 -5
  85. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/webratlink.js +0 -9
  86. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js +0 -15
  87. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js +0 -5
  88. data/vendor/webrat/lib/webrat/selenium/matchers.rb +0 -4
  89. data/vendor/webrat/lib/webrat/selenium/matchers/have_content.rb +0 -66
  90. data/vendor/webrat/lib/webrat/selenium/matchers/have_selector.rb +0 -49
  91. data/vendor/webrat/lib/webrat/selenium/matchers/have_tag.rb +0 -72
  92. data/vendor/webrat/lib/webrat/selenium/matchers/have_xpath.rb +0 -45
  93. data/vendor/webrat/lib/webrat/selenium/selenium_extensions.js +0 -6
  94. data/vendor/webrat/lib/webrat/selenium/selenium_session.rb +0 -247
  95. data/vendor/webrat/lib/webrat/sinatra.rb +0 -44
  96. data/vendor/webrat/spec/fakes/test_session.rb +0 -34
  97. data/vendor/webrat/spec/integration/merb/Rakefile +0 -35
  98. data/vendor/webrat/spec/integration/merb/app/controllers/application.rb +0 -2
  99. data/vendor/webrat/spec/integration/merb/app/controllers/exceptions.rb +0 -13
  100. data/vendor/webrat/spec/integration/merb/app/controllers/testing.rb +0 -18
  101. data/vendor/webrat/spec/integration/merb/app/views/exceptions/not_acceptable.html.erb +0 -63
  102. data/vendor/webrat/spec/integration/merb/app/views/exceptions/not_found.html.erb +0 -47
  103. data/vendor/webrat/spec/integration/merb/app/views/layout/application.html.erb +0 -12
  104. data/vendor/webrat/spec/integration/merb/app/views/testing/show_form.html.erb +0 -27
  105. data/vendor/webrat/spec/integration/merb/config/environments/development.rb +0 -15
  106. data/vendor/webrat/spec/integration/merb/config/environments/rake.rb +0 -11
  107. data/vendor/webrat/spec/integration/merb/config/environments/test.rb +0 -14
  108. data/vendor/webrat/spec/integration/merb/config/init.rb +0 -25
  109. data/vendor/webrat/spec/integration/merb/config/rack.rb +0 -11
  110. data/vendor/webrat/spec/integration/merb/config/router.rb +0 -33
  111. data/vendor/webrat/spec/integration/merb/spec/spec.opts +0 -1
  112. data/vendor/webrat/spec/integration/merb/spec/spec_helper.rb +0 -24
  113. data/vendor/webrat/spec/integration/merb/spec/webrat_spec.rb +0 -32
  114. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/app_script.rb +0 -31
  115. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/common.rb +0 -64
  116. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/gem_ext.rb +0 -124
  117. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/main.thor +0 -150
  118. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/ops.rb +0 -93
  119. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/utils.rb +0 -40
  120. data/vendor/webrat/spec/integration/rails/Rakefile +0 -30
  121. data/vendor/webrat/spec/integration/rails/app/controllers/application.rb +0 -15
  122. data/vendor/webrat/spec/integration/rails/app/controllers/webrat_controller.rb +0 -39
  123. data/vendor/webrat/spec/integration/rails/app/views/webrat/before_redirect_form.html.erb +0 -4
  124. data/vendor/webrat/spec/integration/rails/app/views/webrat/form.html.erb +0 -28
  125. data/vendor/webrat/spec/integration/rails/config/boot.rb +0 -109
  126. data/vendor/webrat/spec/integration/rails/config/environment.rb +0 -12
  127. data/vendor/webrat/spec/integration/rails/config/environments/development.rb +0 -17
  128. data/vendor/webrat/spec/integration/rails/config/environments/selenium.rb +0 -22
  129. data/vendor/webrat/spec/integration/rails/config/environments/test.rb +0 -22
  130. data/vendor/webrat/spec/integration/rails/config/initializers/inflections.rb +0 -10
  131. data/vendor/webrat/spec/integration/rails/config/initializers/mime_types.rb +0 -5
  132. data/vendor/webrat/spec/integration/rails/config/initializers/new_rails_defaults.rb +0 -17
  133. data/vendor/webrat/spec/integration/rails/config/locales/en.yml +0 -5
  134. data/vendor/webrat/spec/integration/rails/config/routes.rb +0 -14
  135. data/vendor/webrat/spec/integration/rails/public/404.html +0 -30
  136. data/vendor/webrat/spec/integration/rails/public/422.html +0 -30
  137. data/vendor/webrat/spec/integration/rails/public/500.html +0 -33
  138. data/vendor/webrat/spec/integration/rails/script/about +0 -4
  139. data/vendor/webrat/spec/integration/rails/script/console +0 -3
  140. data/vendor/webrat/spec/integration/rails/script/dbconsole +0 -3
  141. data/vendor/webrat/spec/integration/rails/script/destroy +0 -3
  142. data/vendor/webrat/spec/integration/rails/script/generate +0 -3
  143. data/vendor/webrat/spec/integration/rails/script/performance/benchmarker +0 -3
  144. data/vendor/webrat/spec/integration/rails/script/performance/profiler +0 -3
  145. data/vendor/webrat/spec/integration/rails/script/performance/request +0 -3
  146. data/vendor/webrat/spec/integration/rails/script/plugin +0 -3
  147. data/vendor/webrat/spec/integration/rails/script/process/inspector +0 -3
  148. data/vendor/webrat/spec/integration/rails/script/process/reaper +0 -3
  149. data/vendor/webrat/spec/integration/rails/script/process/spawner +0 -3
  150. data/vendor/webrat/spec/integration/rails/script/runner +0 -3
  151. data/vendor/webrat/spec/integration/rails/script/server +0 -3
  152. data/vendor/webrat/spec/integration/rails/test/integration/webrat_test.rb +0 -80
  153. data/vendor/webrat/spec/integration/rails/test/test_helper.rb +0 -25
  154. data/vendor/webrat/spec/integration/sinatra/Rakefile +0 -5
  155. data/vendor/webrat/spec/integration/sinatra/classic_app.rb +0 -64
  156. data/vendor/webrat/spec/integration/sinatra/modular_app.rb +0 -16
  157. data/vendor/webrat/spec/integration/sinatra/test/classic_app_test.rb +0 -37
  158. data/vendor/webrat/spec/integration/sinatra/test/modular_app_test.rb +0 -18
  159. data/vendor/webrat/spec/integration/sinatra/test/test_helper.rb +0 -16
  160. data/vendor/webrat/spec/private/core/configuration_spec.rb +0 -104
  161. data/vendor/webrat/spec/private/core/field_spec.rb +0 -67
  162. data/vendor/webrat/spec/private/core/link_spec.rb +0 -24
  163. data/vendor/webrat/spec/private/core/logging_spec.rb +0 -10
  164. data/vendor/webrat/spec/private/core/session_spec.rb +0 -198
  165. data/vendor/webrat/spec/private/mechanize/mechanize_session_spec.rb +0 -81
  166. data/vendor/webrat/spec/private/merb/merb_session_spec.rb +0 -42
  167. data/vendor/webrat/spec/private/nokogiri_spec.rb +0 -77
  168. data/vendor/webrat/spec/private/rails/attaches_file_spec.rb +0 -81
  169. data/vendor/webrat/spec/private/rails/rails_session_spec.rb +0 -110
  170. data/vendor/webrat/spec/private/selenium/selenium_session_spec.rb +0 -44
  171. data/vendor/webrat/spec/private/selenium/selenium_spec.rb +0 -109
  172. data/vendor/webrat/spec/public/basic_auth_spec.rb +0 -24
  173. data/vendor/webrat/spec/public/check_spec.rb +0 -191
  174. data/vendor/webrat/spec/public/choose_spec.rb +0 -118
  175. data/vendor/webrat/spec/public/click_area_spec.rb +0 -106
  176. data/vendor/webrat/spec/public/click_button_spec.rb +0 -502
  177. data/vendor/webrat/spec/public/click_link_spec.rb +0 -469
  178. data/vendor/webrat/spec/public/fill_in_spec.rb +0 -209
  179. data/vendor/webrat/spec/public/locators/field_by_xpath_spec.rb +0 -19
  180. data/vendor/webrat/spec/public/locators/field_labeled_spec.rb +0 -157
  181. data/vendor/webrat/spec/public/locators/field_with_id_spec.rb +0 -16
  182. data/vendor/webrat/spec/public/matchers/contain_spec.rb +0 -114
  183. data/vendor/webrat/spec/public/matchers/have_selector_spec.rb +0 -135
  184. data/vendor/webrat/spec/public/matchers/have_tag_spec.rb +0 -39
  185. data/vendor/webrat/spec/public/matchers/have_xpath_spec.rb +0 -123
  186. data/vendor/webrat/spec/public/reload_spec.rb +0 -10
  187. data/vendor/webrat/spec/public/save_and_open_spec.rb +0 -51
  188. data/vendor/webrat/spec/public/select_date_spec.rb +0 -88
  189. data/vendor/webrat/spec/public/select_datetime_spec.rb +0 -106
  190. data/vendor/webrat/spec/public/select_spec.rb +0 -246
  191. data/vendor/webrat/spec/public/select_time_spec.rb +0 -79
  192. data/vendor/webrat/spec/public/set_hidden_field_spec.rb +0 -5
  193. data/vendor/webrat/spec/public/submit_form_spec.rb +0 -5
  194. data/vendor/webrat/spec/public/visit_spec.rb +0 -58
  195. data/vendor/webrat/spec/public/within_spec.rb +0 -177
  196. data/vendor/webrat/spec/rcov.opts +0 -1
  197. data/vendor/webrat/spec/spec.opts +0 -2
  198. data/vendor/webrat/spec/spec_helper.rb +0 -50
  199. data/vendor/webrat/vendor/selenium-server.jar +0 -0
@@ -1,403 +0,0 @@
1
- require "cgi"
2
- require "webrat/core_extensions/blank"
3
- require "webrat/core_extensions/nil_to_param"
4
-
5
- require "webrat/core/elements/element"
6
-
7
- module Webrat
8
- # Raised when Webrat is asked to manipulate a disabled form field
9
- class DisabledFieldError < WebratError
10
- end
11
-
12
- class Field < Element #:nodoc:
13
- attr_reader :value
14
-
15
- def self.xpath_search
16
- [".//button", ".//input", ".//textarea", ".//select"]
17
- end
18
-
19
- def self.xpath_search_excluding_hidden
20
- [".//button", ".//input[ @type != 'hidden']", ".//textarea", ".//select"]
21
- end
22
-
23
- def self.field_classes
24
- @field_classes || []
25
- end
26
-
27
- def self.inherited(klass)
28
- @field_classes ||= []
29
- @field_classes << klass
30
- # raise args.inspect
31
- end
32
-
33
- def self.load(session, element)
34
- return nil if element.nil?
35
- session.elements[Webrat::XML.xpath_to(element)] ||= field_class(element).new(session, element)
36
- end
37
-
38
- def self.field_class(element)
39
- case element.name
40
- when "button" then ButtonField
41
- when "select" then SelectField
42
- when "textarea" then TextareaField
43
- else
44
- case Webrat::XML.attribute(element, "type")
45
- when "checkbox" then CheckboxField
46
- when "hidden" then HiddenField
47
- when "radio" then RadioField
48
- when "password" then PasswordField
49
- when "file" then FileField
50
- when "reset" then ResetField
51
- when "submit" then ButtonField
52
- when "button" then ButtonField
53
- when "image" then ButtonField
54
- else TextField
55
- end
56
- end
57
- end
58
-
59
- def initialize(*args)
60
- super
61
- @value = default_value
62
- end
63
-
64
- def label_text
65
- return nil if labels.empty?
66
- labels.first.text
67
- end
68
-
69
- def id
70
- Webrat::XML.attribute(@element, "id")
71
- end
72
-
73
- def disabled?
74
- @element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false'
75
- end
76
-
77
- def raise_error_if_disabled
78
- return unless disabled?
79
- raise DisabledFieldError.new("Cannot interact with disabled form element (#{self})")
80
- end
81
-
82
- def to_param
83
- return nil if disabled?
84
-
85
- case Webrat.configuration.mode
86
- when :rails
87
- parse_rails_request_params("#{name}=#{escaped_value}")
88
- when :merb
89
- ::Merb::Parse.query("#{name}=#{escaped_value}")
90
- else
91
- { name => escaped_value }
92
- end
93
- end
94
-
95
- def set(value)
96
- @value = value
97
- end
98
-
99
- def unset
100
- @value = default_value
101
- end
102
-
103
- protected
104
-
105
- def parse_rails_request_params(params)
106
- if defined?(ActionController::AbstractRequest)
107
- ActionController::AbstractRequest.parse_query_parameters(params)
108
- elsif defined?(ActionController::UrlEncodedPairParser)
109
- # For Rails > 2.2
110
- ActionController::UrlEncodedPairParser.parse_query_parameters(params)
111
- else
112
- # For Rails > 2.3
113
- Rack::Utils.parse_nested_query(params)
114
- end
115
- end
116
-
117
- def form
118
- Form.load(@session, form_element)
119
- end
120
-
121
- def form_element
122
- parent = @element.parent
123
-
124
- while parent.respond_to?(:parent)
125
- return parent if parent.name == 'form'
126
- parent = parent.parent
127
- end
128
- end
129
-
130
- def name
131
- Webrat::XML.attribute(@element, "name")
132
- end
133
-
134
- def escaped_value
135
- CGI.escape(@value.to_s)
136
- end
137
-
138
- def labels
139
- @labels ||= label_elements.map do |element|
140
- Label.load(@session, element)
141
- end
142
- end
143
-
144
- def label_elements
145
- return @label_elements unless @label_elements.nil?
146
- @label_elements = []
147
-
148
- parent = @element.parent
149
- while parent.respond_to?(:parent)
150
- if parent.name == 'label'
151
- @label_elements.push parent
152
- break
153
- end
154
- parent = parent.parent
155
- end
156
-
157
- unless id.blank?
158
- @label_elements += Webrat::XML.xpath_search(form.element, ".//label[@for = '#{id}']")
159
- end
160
-
161
- @label_elements
162
- end
163
-
164
- def default_value
165
- Webrat::XML.attribute(@element, "value")
166
- end
167
-
168
- def replace_param_value(params, oval, nval)
169
- output = Hash.new
170
- params.each do |key, value|
171
- case value
172
- when Hash
173
- value = replace_param_value(value, oval, nval)
174
- when Array
175
- value = value.map { |o| o == oval ? nval : oval }
176
- when oval
177
- value = nval
178
- end
179
- output[key] = value
180
- end
181
- output
182
- end
183
- end
184
-
185
- class ButtonField < Field #:nodoc:
186
-
187
- def self.xpath_search
188
- [".//button", ".//input[@type = 'submit']", ".//input[@type = 'button']", ".//input[@type = 'image']"]
189
- end
190
-
191
- def to_param
192
- return nil if @value.nil?
193
- super
194
- end
195
-
196
- def default_value
197
- nil
198
- end
199
-
200
- def click
201
- raise_error_if_disabled
202
- set(Webrat::XML.attribute(@element, "value")) unless Webrat::XML.attribute(@element, "name").blank?
203
- form.submit
204
- end
205
-
206
- end
207
-
208
- class HiddenField < Field #:nodoc:
209
-
210
- def self.xpath_search
211
- ".//input[@type = 'hidden']"
212
- end
213
-
214
- def to_param
215
- if collection_name?
216
- super
217
- else
218
- checkbox_with_same_name = form.field_named(name, CheckboxField)
219
-
220
- if checkbox_with_same_name.to_param.blank?
221
- super
222
- else
223
- nil
224
- end
225
- end
226
- end
227
-
228
- protected
229
-
230
- def collection_name?
231
- name =~ /\[\]/
232
- end
233
-
234
- end
235
-
236
- class CheckboxField < Field #:nodoc:
237
-
238
- def self.xpath_search
239
- ".//input[@type = 'checkbox']"
240
- end
241
-
242
- def to_param
243
- return nil if @value.nil?
244
- super
245
- end
246
-
247
- def check
248
- raise_error_if_disabled
249
- set(Webrat::XML.attribute(@element, "value") || "on")
250
- end
251
-
252
- def checked?
253
- Webrat::XML.attribute(@element, "checked") == "checked"
254
- end
255
-
256
- def uncheck
257
- raise_error_if_disabled
258
- set(nil)
259
- end
260
-
261
- protected
262
-
263
- def default_value
264
- if Webrat::XML.attribute(@element, "checked") == "checked"
265
- Webrat::XML.attribute(@element, "value") || "on"
266
- else
267
- nil
268
- end
269
- end
270
-
271
- end
272
-
273
- class PasswordField < Field #:nodoc:
274
-
275
- def self.xpath_search
276
- ".//input[@type = 'password']"
277
- end
278
-
279
- end
280
-
281
- class RadioField < Field #:nodoc:
282
-
283
- def self.xpath_search
284
- ".//input[@type = 'radio']"
285
- end
286
-
287
- def to_param
288
- return nil if @value.nil?
289
- super
290
- end
291
-
292
- def choose
293
- raise_error_if_disabled
294
- other_options.each do |option|
295
- option.set(nil)
296
- end
297
-
298
- set(Webrat::XML.attribute(@element, "value") || "on")
299
- end
300
-
301
- def checked?
302
- Webrat::XML.attribute(@element, "checked") == "checked"
303
- end
304
-
305
- protected
306
-
307
- def other_options
308
- form.fields.select { |f| f.name == name }
309
- end
310
-
311
- def default_value
312
- if Webrat::XML.attribute(@element, "checked") == "checked"
313
- Webrat::XML.attribute(@element, "value") || "on"
314
- else
315
- nil
316
- end
317
- end
318
-
319
- end
320
-
321
- class TextareaField < Field #:nodoc:
322
-
323
- def self.xpath_search
324
- ".//textarea"
325
- end
326
-
327
- protected
328
-
329
- def default_value
330
- Webrat::XML.inner_html(@element)
331
- end
332
-
333
- end
334
-
335
- class FileField < Field #:nodoc:
336
-
337
- def self.xpath_search
338
- ".//input[@type = 'file']"
339
- end
340
-
341
- attr_accessor :content_type
342
-
343
- def set(value, content_type = nil)
344
- super(value)
345
- @content_type = content_type
346
- end
347
-
348
- def to_param
349
- if @value.nil?
350
- super
351
- else
352
- replace_param_value(super, @value, test_uploaded_file)
353
- end
354
- end
355
-
356
- protected
357
-
358
- def test_uploaded_file
359
- if content_type
360
- ActionController::TestUploadedFile.new(@value, content_type)
361
- else
362
- ActionController::TestUploadedFile.new(@value)
363
- end
364
- end
365
-
366
- end
367
-
368
- class TextField < Field #:nodoc:
369
- def self.xpath_search
370
- [".//input[@type = 'text']", ".//input[not(@type)]"]
371
- end
372
- end
373
-
374
- class ResetField < Field #:nodoc:
375
- def self.xpath_search
376
- ".//input[@type = 'reset']"
377
- end
378
- end
379
-
380
- class SelectField < Field #:nodoc:
381
-
382
- def self.xpath_search
383
- ".//select"
384
- end
385
-
386
- def options
387
- @options ||= SelectOption.load_all(@session, @element)
388
- end
389
-
390
- protected
391
-
392
- def default_value
393
- selected_options = Webrat::XML.xpath_search(@element, ".//option[@selected = 'selected']")
394
- selected_options = Webrat::XML.xpath_search(@element, ".//option[position() = 1]") if selected_options.empty?
395
-
396
- selected_options.map do |option|
397
- return "" if option.nil?
398
- Webrat::XML.attribute(option, "value") || Webrat::XML.inner_html(option)
399
- end
400
- end
401
-
402
- end
403
- end
@@ -1,103 +0,0 @@
1
- require "webrat/core/elements/field"
2
- require "webrat/core_extensions/blank"
3
-
4
- require "webrat/core/elements/element"
5
- require "webrat/core/locators/field_named_locator"
6
-
7
- module Webrat
8
- class Form < Element #:nodoc:
9
- attr_reader :element
10
-
11
- def self.xpath_search
12
- ".//form"
13
- end
14
-
15
- def fields
16
- @fields ||= Field.load_all(@session, @element)
17
- end
18
-
19
- def submit
20
- @session.request_page(form_action, form_method, params)
21
- end
22
-
23
- def field_named(name, *field_types)
24
- Webrat::Locators::FieldNamedLocator.new(@session, dom, name, *field_types).locate
25
- end
26
-
27
- protected
28
-
29
- def dom
30
- Webrat::XML.xpath_at(@session.dom, path)
31
- end
32
-
33
- def fields_by_type(field_types)
34
- if field_types.any?
35
- fields.select { |f| field_types.include?(f.class) }
36
- else
37
- fields
38
- end
39
- end
40
-
41
- def params
42
- all_params = {}
43
-
44
- fields.each do |field|
45
- next if field.to_param.nil?
46
- merge(all_params, field.to_param)
47
- end
48
-
49
- all_params
50
- end
51
-
52
- def form_method
53
- Webrat::XML.attribute(@element, "method").blank? ? :get : Webrat::XML.attribute(@element, "method").downcase
54
- end
55
-
56
- def form_action
57
- Webrat::XML.attribute(@element, "action").blank? ? @session.current_url : Webrat::XML.attribute(@element, "action")
58
- end
59
-
60
- def merge(all_params, new_param)
61
- new_param.each do |key, value|
62
- case all_params[key]
63
- when *hash_classes
64
- merge_hash_values(all_params[key], value)
65
- when Array
66
- all_params[key] += value
67
- else
68
- all_params[key] = value
69
- end
70
- end
71
- end
72
-
73
- def merge_hash_values(a, b) # :nodoc:
74
- a.keys.each do |k|
75
- if b.has_key?(k)
76
- case [a[k], b[k]].map{|value| value.class}
77
- when *hash_classes.zip(hash_classes)
78
- a[k] = merge_hash_values(a[k], b[k])
79
- b.delete(k)
80
- when [Array, Array]
81
- a[k] += b[k]
82
- b.delete(k)
83
- end
84
- end
85
- end
86
- a.merge!(b)
87
- end
88
-
89
- def hash_classes
90
- klasses = [Hash]
91
-
92
- case Webrat.configuration.mode
93
- when :rails
94
- klasses << HashWithIndifferentAccess
95
- when :merb
96
- klasses << Mash
97
- end
98
-
99
- klasses
100
- end
101
-
102
- end
103
- end