winton-sum 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. data/Capfile +3 -0
  2. data/MIT-LICENSE +18 -0
  3. data/README.markdown +55 -0
  4. data/Rakefile +45 -0
  5. data/config/database.example.yml +10 -0
  6. data/config/deploy.example.rb +36 -0
  7. data/config/externals.yml +18 -0
  8. data/config/mail.example.yml +32 -0
  9. data/config/schedule.rb +20 -0
  10. data/config.ru +3 -0
  11. data/db/migrate/001_users.rb +22 -0
  12. data/db/migrate/002_user_emails.rb +15 -0
  13. data/features/front_page.feature +14 -0
  14. data/features/read_email.feature +446 -0
  15. data/features/receive_email.feature +59 -0
  16. data/features/step_definitions/email.rb +52 -0
  17. data/features/step_definitions/given.rb +60 -0
  18. data/features/step_definitions/then.rb +32 -0
  19. data/features/step_definitions/when.rb +41 -0
  20. data/features/support/env.rb +27 -0
  21. data/features/support/helpers.rb +44 -0
  22. data/features/support/rspec.rb +11 -0
  23. data/features/support/webrat.rb +3 -0
  24. data/features/update_user.feature +76 -0
  25. data/gemspec.rb +45 -0
  26. data/lib/sum/boot.rb +29 -0
  27. data/lib/sum/controller/cron.rb +12 -0
  28. data/lib/sum/controller/front.rb +6 -0
  29. data/lib/sum/controller/new.rb +15 -0
  30. data/lib/sum/helper/application.rb +8 -0
  31. data/lib/sum/helper/cron.rb +12 -0
  32. data/lib/sum/helper/new.rb +26 -0
  33. data/lib/sum/model/incoming_mail.rb +89 -0
  34. data/lib/sum/model/user.rb +286 -0
  35. data/lib/sum/model/user_email.rb +31 -0
  36. data/lib/sum/view/email.haml +70 -0
  37. data/lib/sum/view/field.haml +10 -0
  38. data/lib/sum/view/form.haml +12 -0
  39. data/lib/sum/view/front.haml +25 -0
  40. data/lib/sum/view/layout.haml +26 -0
  41. data/lib/sum/view/new.haml +15 -0
  42. data/lib/sum.rb +30 -0
  43. data/public/image/1.png +0 -0
  44. data/public/image/2.png +0 -0
  45. data/public/image/3.png +0 -0
  46. data/public/image/bg.png +0 -0
  47. data/public/image/bot.png +0 -0
  48. data/public/image/facebox/b.png +0 -0
  49. data/public/image/facebox/bl.png +0 -0
  50. data/public/image/facebox/br.png +0 -0
  51. data/public/image/facebox/closelabel.gif +0 -0
  52. data/public/image/facebox/loading.gif +0 -0
  53. data/public/image/facebox/tl.png +0 -0
  54. data/public/image/facebox/tr.png +0 -0
  55. data/public/image/favicon.png +0 -0
  56. data/public/image/field_off.png +0 -0
  57. data/public/image/field_on.png +0 -0
  58. data/public/image/ribbon.png +0 -0
  59. data/public/image/screenshot_receive.png +0 -0
  60. data/public/image/screenshot_send.png +0 -0
  61. data/public/image/submit.png +0 -0
  62. data/public/image/top.png +0 -0
  63. data/public/javascript/facebox.js +319 -0
  64. data/public/javascript/jquery-1.3.2.js +19 -0
  65. data/public/javascript/sum.js +9 -0
  66. data/public/style/facebox.css +95 -0
  67. data/public/style/ie.css +35 -0
  68. data/public/style/print.css +30 -0
  69. data/public/style/screen.css +256 -0
  70. data/public/style/sum.css +22 -0
  71. data/public/style/sum.less +135 -0
  72. data/spec/spec.opts +1 -0
  73. data/spec/spec_helper.rb +58 -0
  74. data/spec/sum/model/incoming_mail_spec.rb +106 -0
  75. data/spec/sum/model/user_spec.rb +171 -0
  76. data/sum.gemspec +69 -0
  77. data/vendor/webrat/History.txt +358 -0
  78. data/vendor/webrat/MIT-LICENSE.txt +19 -0
  79. data/vendor/webrat/README.rdoc +85 -0
  80. data/vendor/webrat/Rakefile +200 -0
  81. data/vendor/webrat/install.rb +1 -0
  82. data/vendor/webrat/lib/webrat/core/configuration.rb +102 -0
  83. data/vendor/webrat/lib/webrat/core/elements/area.rb +31 -0
  84. data/vendor/webrat/lib/webrat/core/elements/element.rb +33 -0
  85. data/vendor/webrat/lib/webrat/core/elements/field.rb +409 -0
  86. data/vendor/webrat/lib/webrat/core/elements/form.rb +103 -0
  87. data/vendor/webrat/lib/webrat/core/elements/label.rb +31 -0
  88. data/vendor/webrat/lib/webrat/core/elements/link.rb +93 -0
  89. data/vendor/webrat/lib/webrat/core/elements/select_option.rb +35 -0
  90. data/vendor/webrat/lib/webrat/core/locators/area_locator.rb +38 -0
  91. data/vendor/webrat/lib/webrat/core/locators/button_locator.rb +54 -0
  92. data/vendor/webrat/lib/webrat/core/locators/field_by_id_locator.rb +37 -0
  93. data/vendor/webrat/lib/webrat/core/locators/field_labeled_locator.rb +56 -0
  94. data/vendor/webrat/lib/webrat/core/locators/field_locator.rb +25 -0
  95. data/vendor/webrat/lib/webrat/core/locators/field_named_locator.rb +41 -0
  96. data/vendor/webrat/lib/webrat/core/locators/form_locator.rb +19 -0
  97. data/vendor/webrat/lib/webrat/core/locators/label_locator.rb +34 -0
  98. data/vendor/webrat/lib/webrat/core/locators/link_locator.rb +74 -0
  99. data/vendor/webrat/lib/webrat/core/locators/locator.rb +20 -0
  100. data/vendor/webrat/lib/webrat/core/locators/select_option_locator.rb +59 -0
  101. data/vendor/webrat/lib/webrat/core/locators.rb +20 -0
  102. data/vendor/webrat/lib/webrat/core/logging.rb +24 -0
  103. data/vendor/webrat/lib/webrat/core/matchers/have_content.rb +73 -0
  104. data/vendor/webrat/lib/webrat/core/matchers/have_selector.rb +74 -0
  105. data/vendor/webrat/lib/webrat/core/matchers/have_tag.rb +21 -0
  106. data/vendor/webrat/lib/webrat/core/matchers/have_xpath.rb +147 -0
  107. data/vendor/webrat/lib/webrat/core/matchers.rb +4 -0
  108. data/vendor/webrat/lib/webrat/core/methods.rb +63 -0
  109. data/vendor/webrat/lib/webrat/core/mime.rb +29 -0
  110. data/vendor/webrat/lib/webrat/core/save_and_open_page.rb +48 -0
  111. data/vendor/webrat/lib/webrat/core/scope.rb +350 -0
  112. data/vendor/webrat/lib/webrat/core/session.rb +299 -0
  113. data/vendor/webrat/lib/webrat/core/xml/hpricot.rb +19 -0
  114. data/vendor/webrat/lib/webrat/core/xml/nokogiri.rb +76 -0
  115. data/vendor/webrat/lib/webrat/core/xml/rexml.rb +24 -0
  116. data/vendor/webrat/lib/webrat/core/xml.rb +115 -0
  117. data/vendor/webrat/lib/webrat/core.rb +14 -0
  118. data/vendor/webrat/lib/webrat/core_extensions/blank.rb +58 -0
  119. data/vendor/webrat/lib/webrat/core_extensions/deprecate.rb +8 -0
  120. data/vendor/webrat/lib/webrat/core_extensions/detect_mapped.rb +12 -0
  121. data/vendor/webrat/lib/webrat/core_extensions/meta_class.rb +6 -0
  122. data/vendor/webrat/lib/webrat/core_extensions/nil_to_param.rb +5 -0
  123. data/vendor/webrat/lib/webrat/core_extensions/tcp_socket.rb +27 -0
  124. data/vendor/webrat/lib/webrat/mechanize.rb +74 -0
  125. data/vendor/webrat/lib/webrat/merb.rb +9 -0
  126. data/vendor/webrat/lib/webrat/merb_multipart_support.rb +27 -0
  127. data/vendor/webrat/lib/webrat/merb_session.rb +82 -0
  128. data/vendor/webrat/lib/webrat/rack.rb +25 -0
  129. data/vendor/webrat/lib/webrat/rails.rb +106 -0
  130. data/vendor/webrat/lib/webrat/rspec-rails.rb +10 -0
  131. data/vendor/webrat/lib/webrat/selenium/application_server_factory.rb +40 -0
  132. data/vendor/webrat/lib/webrat/selenium/application_servers/base.rb +46 -0
  133. data/vendor/webrat/lib/webrat/selenium/application_servers/external.rb +26 -0
  134. data/vendor/webrat/lib/webrat/selenium/application_servers/merb.rb +50 -0
  135. data/vendor/webrat/lib/webrat/selenium/application_servers/rails.rb +44 -0
  136. data/vendor/webrat/lib/webrat/selenium/application_servers/sinatra.rb +37 -0
  137. data/vendor/webrat/lib/webrat/selenium/application_servers.rb +5 -0
  138. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/button.js +19 -0
  139. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/label.js +16 -0
  140. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/webrat.js +5 -0
  141. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/webratlink.js +12 -0
  142. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js +15 -0
  143. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js +5 -0
  144. data/vendor/webrat/lib/webrat/selenium/matchers/have_content.rb +66 -0
  145. data/vendor/webrat/lib/webrat/selenium/matchers/have_selector.rb +49 -0
  146. data/vendor/webrat/lib/webrat/selenium/matchers/have_tag.rb +72 -0
  147. data/vendor/webrat/lib/webrat/selenium/matchers/have_xpath.rb +45 -0
  148. data/vendor/webrat/lib/webrat/selenium/matchers.rb +4 -0
  149. data/vendor/webrat/lib/webrat/selenium/selenium_extensions.js +6 -0
  150. data/vendor/webrat/lib/webrat/selenium/selenium_rc_server.rb +84 -0
  151. data/vendor/webrat/lib/webrat/selenium/selenium_session.rb +248 -0
  152. data/vendor/webrat/lib/webrat/selenium/silence_stream.rb +18 -0
  153. data/vendor/webrat/lib/webrat/selenium.rb +81 -0
  154. data/vendor/webrat/lib/webrat/sinatra.rb +11 -0
  155. data/vendor/webrat/lib/webrat.rb +31 -0
  156. data/vendor/webrat/spec/fakes/test_session.rb +34 -0
  157. data/vendor/webrat/spec/integration/merb/Rakefile +35 -0
  158. data/vendor/webrat/spec/integration/merb/app/controllers/application.rb +2 -0
  159. data/vendor/webrat/spec/integration/merb/app/controllers/exceptions.rb +13 -0
  160. data/vendor/webrat/spec/integration/merb/app/controllers/testing.rb +27 -0
  161. data/vendor/webrat/spec/integration/merb/app/views/exceptions/not_acceptable.html.erb +63 -0
  162. data/vendor/webrat/spec/integration/merb/app/views/exceptions/not_found.html.erb +47 -0
  163. data/vendor/webrat/spec/integration/merb/app/views/layout/application.html.erb +12 -0
  164. data/vendor/webrat/spec/integration/merb/app/views/testing/show_form.html.erb +27 -0
  165. data/vendor/webrat/spec/integration/merb/app/views/testing/upload.html.erb +9 -0
  166. data/vendor/webrat/spec/integration/merb/config/environments/development.rb +15 -0
  167. data/vendor/webrat/spec/integration/merb/config/environments/rake.rb +11 -0
  168. data/vendor/webrat/spec/integration/merb/config/environments/test.rb +14 -0
  169. data/vendor/webrat/spec/integration/merb/config/init.rb +25 -0
  170. data/vendor/webrat/spec/integration/merb/config/rack.rb +11 -0
  171. data/vendor/webrat/spec/integration/merb/config/router.rb +34 -0
  172. data/vendor/webrat/spec/integration/merb/spec/spec.opts +1 -0
  173. data/vendor/webrat/spec/integration/merb/spec/spec_helper.rb +24 -0
  174. data/vendor/webrat/spec/integration/merb/spec/webrat_spec.rb +39 -0
  175. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/app_script.rb +31 -0
  176. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/common.rb +64 -0
  177. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/gem_ext.rb +124 -0
  178. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/main.thor +150 -0
  179. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/ops.rb +93 -0
  180. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/utils.rb +40 -0
  181. data/vendor/webrat/spec/integration/rack/Rakefile +5 -0
  182. data/vendor/webrat/spec/integration/rack/app.rb +73 -0
  183. data/vendor/webrat/spec/integration/rack/test/helper.rb +20 -0
  184. data/vendor/webrat/spec/integration/rack/test/webrat_rack_test.rb +62 -0
  185. data/vendor/webrat/spec/integration/rails/Rakefile +30 -0
  186. data/vendor/webrat/spec/integration/rails/app/controllers/application.rb +15 -0
  187. data/vendor/webrat/spec/integration/rails/app/controllers/buttons_controller.rb +7 -0
  188. data/vendor/webrat/spec/integration/rails/app/controllers/fields_controller.rb +4 -0
  189. data/vendor/webrat/spec/integration/rails/app/controllers/links_controller.rb +7 -0
  190. data/vendor/webrat/spec/integration/rails/app/controllers/webrat_controller.rb +43 -0
  191. data/vendor/webrat/spec/integration/rails/app/helpers/buttons_helper.rb +2 -0
  192. data/vendor/webrat/spec/integration/rails/app/helpers/fields_helper.rb +2 -0
  193. data/vendor/webrat/spec/integration/rails/app/helpers/links_helper.rb +2 -0
  194. data/vendor/webrat/spec/integration/rails/app/views/buttons/show.html.erb +11 -0
  195. data/vendor/webrat/spec/integration/rails/app/views/fields/show.html.erb +9 -0
  196. data/vendor/webrat/spec/integration/rails/app/views/links/show.html.erb +5 -0
  197. data/vendor/webrat/spec/integration/rails/app/views/webrat/before_redirect_form.html.erb +4 -0
  198. data/vendor/webrat/spec/integration/rails/app/views/webrat/buttons.html.erb +11 -0
  199. data/vendor/webrat/spec/integration/rails/app/views/webrat/form.html.erb +28 -0
  200. data/vendor/webrat/spec/integration/rails/config/boot.rb +109 -0
  201. data/vendor/webrat/spec/integration/rails/config/environment.rb +12 -0
  202. data/vendor/webrat/spec/integration/rails/config/environments/development.rb +17 -0
  203. data/vendor/webrat/spec/integration/rails/config/environments/selenium.rb +22 -0
  204. data/vendor/webrat/spec/integration/rails/config/environments/test.rb +22 -0
  205. data/vendor/webrat/spec/integration/rails/config/initializers/inflections.rb +10 -0
  206. data/vendor/webrat/spec/integration/rails/config/initializers/mime_types.rb +5 -0
  207. data/vendor/webrat/spec/integration/rails/config/initializers/new_rails_defaults.rb +17 -0
  208. data/vendor/webrat/spec/integration/rails/config/locales/en.yml +5 -0
  209. data/vendor/webrat/spec/integration/rails/config/routes.rb +18 -0
  210. data/vendor/webrat/spec/integration/rails/public/404.html +30 -0
  211. data/vendor/webrat/spec/integration/rails/public/422.html +30 -0
  212. data/vendor/webrat/spec/integration/rails/public/500.html +33 -0
  213. data/vendor/webrat/spec/integration/rails/script/about +4 -0
  214. data/vendor/webrat/spec/integration/rails/script/console +3 -0
  215. data/vendor/webrat/spec/integration/rails/script/dbconsole +3 -0
  216. data/vendor/webrat/spec/integration/rails/script/destroy +3 -0
  217. data/vendor/webrat/spec/integration/rails/script/generate +3 -0
  218. data/vendor/webrat/spec/integration/rails/script/performance/benchmarker +3 -0
  219. data/vendor/webrat/spec/integration/rails/script/performance/profiler +3 -0
  220. data/vendor/webrat/spec/integration/rails/script/performance/request +3 -0
  221. data/vendor/webrat/spec/integration/rails/script/plugin +3 -0
  222. data/vendor/webrat/spec/integration/rails/script/process/inspector +3 -0
  223. data/vendor/webrat/spec/integration/rails/script/process/reaper +3 -0
  224. data/vendor/webrat/spec/integration/rails/script/process/spawner +3 -0
  225. data/vendor/webrat/spec/integration/rails/script/runner +3 -0
  226. data/vendor/webrat/spec/integration/rails/script/server +3 -0
  227. data/vendor/webrat/spec/integration/rails/test/integration/button_click_test.rb +80 -0
  228. data/vendor/webrat/spec/integration/rails/test/integration/fill_in_test.rb +24 -0
  229. data/vendor/webrat/spec/integration/rails/test/integration/link_click_test.rb +27 -0
  230. data/vendor/webrat/spec/integration/rails/test/integration/webrat_test.rb +97 -0
  231. data/vendor/webrat/spec/integration/rails/test/test_helper.rb +25 -0
  232. data/vendor/webrat/spec/integration/sinatra/Rakefile +5 -0
  233. data/vendor/webrat/spec/integration/sinatra/classic_app.rb +64 -0
  234. data/vendor/webrat/spec/integration/sinatra/modular_app.rb +16 -0
  235. data/vendor/webrat/spec/integration/sinatra/test/classic_app_test.rb +37 -0
  236. data/vendor/webrat/spec/integration/sinatra/test/modular_app_test.rb +18 -0
  237. data/vendor/webrat/spec/integration/sinatra/test/test_helper.rb +16 -0
  238. data/vendor/webrat/spec/private/core/configuration_spec.rb +116 -0
  239. data/vendor/webrat/spec/private/core/field_spec.rb +85 -0
  240. data/vendor/webrat/spec/private/core/link_spec.rb +24 -0
  241. data/vendor/webrat/spec/private/core/logging_spec.rb +10 -0
  242. data/vendor/webrat/spec/private/core/session_spec.rb +195 -0
  243. data/vendor/webrat/spec/private/mechanize/mechanize_session_spec.rb +81 -0
  244. data/vendor/webrat/spec/private/merb/attaches_file_spec.rb +93 -0
  245. data/vendor/webrat/spec/private/merb/merb_session_spec.rb +61 -0
  246. data/vendor/webrat/spec/private/nokogiri_spec.rb +77 -0
  247. data/vendor/webrat/spec/private/rails/attaches_file_spec.rb +81 -0
  248. data/vendor/webrat/spec/private/rails/rails_session_spec.rb +112 -0
  249. data/vendor/webrat/spec/private/selenium/application_servers/rails_spec.rb +26 -0
  250. data/vendor/webrat/spec/public/basic_auth_spec.rb +24 -0
  251. data/vendor/webrat/spec/public/check_spec.rb +191 -0
  252. data/vendor/webrat/spec/public/choose_spec.rb +118 -0
  253. data/vendor/webrat/spec/public/click_area_spec.rb +106 -0
  254. data/vendor/webrat/spec/public/click_button_spec.rb +496 -0
  255. data/vendor/webrat/spec/public/click_link_spec.rb +511 -0
  256. data/vendor/webrat/spec/public/fill_in_spec.rb +209 -0
  257. data/vendor/webrat/spec/public/locators/field_by_xpath_spec.rb +19 -0
  258. data/vendor/webrat/spec/public/locators/field_labeled_spec.rb +172 -0
  259. data/vendor/webrat/spec/public/locators/field_with_id_spec.rb +16 -0
  260. data/vendor/webrat/spec/public/matchers/contain_spec.rb +114 -0
  261. data/vendor/webrat/spec/public/matchers/have_selector_spec.rb +142 -0
  262. data/vendor/webrat/spec/public/matchers/have_tag_spec.rb +39 -0
  263. data/vendor/webrat/spec/public/matchers/have_xpath_spec.rb +136 -0
  264. data/vendor/webrat/spec/public/reload_spec.rb +10 -0
  265. data/vendor/webrat/spec/public/save_and_open_spec.rb +70 -0
  266. data/vendor/webrat/spec/public/select_date_spec.rb +112 -0
  267. data/vendor/webrat/spec/public/select_datetime_spec.rb +137 -0
  268. data/vendor/webrat/spec/public/select_spec.rb +249 -0
  269. data/vendor/webrat/spec/public/select_time_spec.rb +100 -0
  270. data/vendor/webrat/spec/public/selenium/application_server_factory_spec.rb +49 -0
  271. data/vendor/webrat/spec/public/selenium/application_servers/external_spec.rb +12 -0
  272. data/vendor/webrat/spec/public/selenium/selenium_session_spec.rb +37 -0
  273. data/vendor/webrat/spec/public/set_hidden_field_spec.rb +5 -0
  274. data/vendor/webrat/spec/public/submit_form_spec.rb +5 -0
  275. data/vendor/webrat/spec/public/visit_spec.rb +58 -0
  276. data/vendor/webrat/spec/public/within_spec.rb +177 -0
  277. data/vendor/webrat/spec/rcov.opts +1 -0
  278. data/vendor/webrat/spec/spec.opts +2 -0
  279. data/vendor/webrat/spec/spec_helper.rb +50 -0
  280. metadata +554 -0
@@ -0,0 +1,102 @@
1
+ require "webrat/core_extensions/deprecate"
2
+
3
+ module Webrat
4
+
5
+ # Configures Webrat. If this is not done, Webrat will be created
6
+ # with all of the default settings.
7
+ def self.configure(configuration = Webrat.configuration)
8
+ yield configuration if block_given?
9
+ @@configuration = configuration
10
+ end
11
+
12
+ def self.configuration # :nodoc:
13
+ @@configuration ||= Webrat::Configuration.new
14
+ end
15
+
16
+ # Webrat can be configured using the Webrat.configure method. For example:
17
+ #
18
+ # Webrat.configure do |config|
19
+ # config.parse_with_nokogiri = false
20
+ # end
21
+ class Configuration
22
+
23
+ # Should XHTML be parsed with Nokogiri? Defaults to true, except on JRuby. When false, Hpricot and REXML are used
24
+ attr_writer :parse_with_nokogiri
25
+
26
+ # Webrat's mode, set automatically when requiring webrat/rails, webrat/merb, etc.
27
+ attr_reader :mode # :nodoc:
28
+
29
+ # Save and open pages with error status codes (500-599) in a browser? Defualts to true.
30
+ attr_writer :open_error_files
31
+
32
+ # Which rails environment should the selenium tests be run in? Defaults to selenium.
33
+ attr_accessor :application_environment
34
+ webrat_deprecate :selenium_environment, :application_environment
35
+ webrat_deprecate :selenium_environment=, :application_environment=
36
+
37
+ # Which port is the application running on for selenium testing? Defaults to 3001.
38
+ attr_accessor :application_port
39
+ webrat_deprecate :selenium_port, :application_port
40
+ webrat_deprecate :selenium_port=, :application_port=
41
+
42
+ # Which underlying app framework we're testing with selenium
43
+ attr_accessor :application_framework
44
+
45
+ # Which server the application is running on for selenium testing? Defaults to localhost
46
+ attr_accessor :application_address
47
+
48
+ # Which server Selenium server is running on. Defaults to nil(server starts in webrat process and runs locally)
49
+ attr_accessor :selenium_server_address
50
+
51
+ # Which server Selenium port is running on. Defaults to 4444
52
+ attr_accessor :selenium_server_port
53
+
54
+ # Set the key that Selenium uses to determine the browser running. Default *firefox
55
+ attr_accessor :selenium_browser_key
56
+
57
+ # Set the timeout for waiting for the browser process to start
58
+ attr_accessor :selenium_browser_startup_timeout
59
+
60
+ # How many redirects to the same URL should be halted as an infinite redirect
61
+ # loop? Defaults to 10
62
+ attr_accessor :infinite_redirect_limit
63
+
64
+ def initialize # :nodoc:
65
+ self.open_error_files = true
66
+ self.parse_with_nokogiri = true
67
+ self.application_environment = :test
68
+ self.application_port = 3001
69
+ self.application_address = 'localhost'
70
+ self.application_framework = :rails
71
+ self.selenium_server_port = 4444
72
+ self.infinite_redirect_limit = 10
73
+ self.selenium_browser_key = '*firefox'
74
+ self.selenium_browser_startup_timeout = 5
75
+ end
76
+
77
+ def parse_with_nokogiri? #:nodoc:
78
+ @parse_with_nokogiri ? true : false
79
+ end
80
+
81
+ def open_error_files? #:nodoc:
82
+ @open_error_files ? true : false
83
+ end
84
+
85
+ # Allows setting of webrat's mode, valid modes are:
86
+ # :rails, :selenium, :rack, :sinatra, :mechanize, :merb
87
+ def mode=(mode)
88
+ @mode = mode.to_sym
89
+
90
+ # This is a temporary hack to support backwards compatibility
91
+ # with Merb 1.0.8 until it's updated to use the new Webrat.configure
92
+ # syntax
93
+ if @mode == :merb
94
+ require("webrat/merb_session")
95
+ else
96
+ require("webrat/#{mode}")
97
+ end
98
+ end
99
+
100
+ end
101
+
102
+ end
@@ -0,0 +1,31 @@
1
+ require "webrat/core/elements/element"
2
+
3
+ module Webrat
4
+ class Area < Element #:nodoc:
5
+
6
+ def self.xpath_search
7
+ ".//area"
8
+ end
9
+
10
+ def click(method = nil, options = {})
11
+ @session.request_page(absolute_href, :get, {})
12
+ end
13
+
14
+ protected
15
+
16
+ def href
17
+ Webrat::XML.attribute(@element, "href")
18
+ end
19
+
20
+ def absolute_href
21
+ if href =~ /^\?/
22
+ "#{@session.current_url}#{href}"
23
+ elsif href !~ %r{^https?://[\w|.]+(/.*)} && (href !~ /^\//)
24
+ "#{@session.current_url}/#{href}"
25
+ else
26
+ href
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,33 @@
1
+ module Webrat
2
+
3
+ class Element # :nodoc:
4
+
5
+ def self.load_all(session, dom)
6
+ Webrat::XML.xpath_search(dom, xpath_search).map do |element|
7
+ load(session, element)
8
+ end
9
+ end
10
+
11
+ def self.load(session, element)
12
+ return nil if element.nil?
13
+ session.elements[Webrat::XML.xpath_to(element)] ||= self.new(session, element)
14
+ end
15
+
16
+ attr_reader :element
17
+
18
+ def initialize(session, element)
19
+ @session = session
20
+ @element = element
21
+ end
22
+
23
+ def path
24
+ Webrat::XML.xpath_to(@element)
25
+ end
26
+
27
+ def inspect
28
+ "#<#{self.class} @element=#{element.inspect}>"
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,409 @@
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 => 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].first.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
+ case Webrat.configuration.mode
360
+ when :rails
361
+ if content_type
362
+ ActionController::TestUploadedFile.new(@value, content_type)
363
+ else
364
+ ActionController::TestUploadedFile.new(@value)
365
+ end
366
+ when :merb
367
+ # TODO: support content_type
368
+ File.new(@value)
369
+ end
370
+ end
371
+
372
+ end
373
+
374
+ class TextField < Field #:nodoc:
375
+ def self.xpath_search
376
+ [".//input[@type = 'text']", ".//input[not(@type)]"]
377
+ end
378
+ end
379
+
380
+ class ResetField < Field #:nodoc:
381
+ def self.xpath_search
382
+ ".//input[@type = 'reset']"
383
+ end
384
+ end
385
+
386
+ class SelectField < Field #:nodoc:
387
+
388
+ def self.xpath_search
389
+ ".//select"
390
+ end
391
+
392
+ def options
393
+ @options ||= SelectOption.load_all(@session, @element)
394
+ end
395
+
396
+ protected
397
+
398
+ def default_value
399
+ selected_options = Webrat::XML.xpath_search(@element, ".//option[@selected = 'selected']")
400
+ selected_options = Webrat::XML.xpath_search(@element, ".//option[position() = 1]") if selected_options.empty?
401
+
402
+ selected_options.map do |option|
403
+ return "" if option.nil?
404
+ Webrat::XML.attribute(option, "value") || Webrat::XML.inner_html(option)
405
+ end.uniq
406
+ end
407
+
408
+ end
409
+ end
@@ -0,0 +1,103 @@
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
@@ -0,0 +1,31 @@
1
+ require "webrat/core/elements/element"
2
+
3
+ module Webrat
4
+ class Label < Element #:nodoc:
5
+
6
+ attr_reader :element
7
+
8
+ def self.xpath_search
9
+ ".//label"
10
+ end
11
+
12
+ def for_id
13
+ Webrat::XML.attribute(@element, "for")
14
+ end
15
+
16
+ def field
17
+ Field.load(@session, field_element)
18
+ end
19
+
20
+ protected
21
+
22
+ def field_element
23
+ if for_id.blank?
24
+ Webrat::XML.xpath_at(@element, *Field.xpath_search_excluding_hidden)
25
+ else
26
+ Webrat::XML.css_search(@session.current_dom, "#" + for_id).first
27
+ end
28
+ end
29
+
30
+ end
31
+ end