unpoly-rails 1.0.3 → 2.0.0.pre.rc2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of unpoly-rails might be problematic. Click here for more details.

Files changed (344) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +43 -25
  4. data/README.md +5 -6
  5. data/README_RAILS.md +295 -14
  6. data/dist/unpoly-bootstrap3.css +9 -14
  7. data/dist/unpoly-bootstrap3.js +4 -18
  8. data/dist/unpoly-bootstrap3.min.css +1 -1
  9. data/dist/unpoly-bootstrap3.min.js +1 -1
  10. data/dist/unpoly-bootstrap4.css +9 -0
  11. data/dist/unpoly-bootstrap4.js +16 -0
  12. data/dist/unpoly-bootstrap4.min.css +1 -0
  13. data/dist/unpoly-bootstrap4.min.js +1 -0
  14. data/dist/unpoly-bootstrap5.css +9 -0
  15. data/dist/unpoly-bootstrap5.js +14 -0
  16. data/dist/unpoly-bootstrap5.min.css +1 -0
  17. data/dist/unpoly-bootstrap5.min.js +1 -0
  18. data/dist/unpoly-migrate.js +1213 -0
  19. data/dist/unpoly-migrate.min.js +1 -0
  20. data/dist/unpoly.css +109 -140
  21. data/dist/unpoly.js +15376 -10484
  22. data/dist/unpoly.min.css +1 -1
  23. data/dist/unpoly.min.js +6 -4
  24. data/lib/unpoly/rails/change/cache.rb +26 -0
  25. data/lib/unpoly/rails/change/context.rb +80 -0
  26. data/lib/unpoly/rails/change/field.rb +117 -0
  27. data/lib/unpoly/rails/change/field_definition.rb +74 -0
  28. data/lib/unpoly/rails/change/layer.rb +60 -0
  29. data/lib/unpoly/rails/change.rb +372 -0
  30. data/lib/unpoly/rails/controller.rb +47 -0
  31. data/lib/unpoly/rails/error.rb +5 -0
  32. data/lib/unpoly/rails/request_echo_headers.rb +2 -2
  33. data/lib/unpoly/rails/version.rb +1 -1
  34. data/lib/unpoly/tasks.rb +45 -0
  35. data/lib/unpoly-rails.rb +9 -3
  36. metadata +42 -316
  37. data/.gitignore +0 -10
  38. data/.ruby-version +0 -1
  39. data/Gemfile +0 -7
  40. data/Gemfile.lock +0 -39
  41. data/Rakefile +0 -154
  42. data/bower.json +0 -27
  43. data/design/animation-ghosting.txt +0 -72
  44. data/design/design.txt +0 -34
  45. data/design/draft.html.erb +0 -48
  46. data/design/draft.rb +0 -9
  47. data/design/es6.js +0 -32
  48. data/design/ghost-debugging.txt +0 -118
  49. data/design/homepage.txt +0 -236
  50. data/design/ie11.txt +0 -9
  51. data/design/measure_import_node.js +0 -330
  52. data/design/measure_jquery/element_list.js +0 -41
  53. data/design/measure_jquery/up.on_vs_addEventListener.js +0 -56
  54. data/design/positioning.txt +0 -28
  55. data/design/query-params-in-form-actions/cases.html +0 -125
  56. data/design/rename.txt +0 -0
  57. data/design/test_rejected_promise.txt +0 -5
  58. data/design/unpoly errors.txt +0 -19
  59. data/lib/assets/javascripts/unpoly/browser.coffee.erb +0 -240
  60. data/lib/assets/javascripts/unpoly/classes/body_shifter.coffee +0 -45
  61. data/lib/assets/javascripts/unpoly/classes/cache.coffee +0 -127
  62. data/lib/assets/javascripts/unpoly/classes/compile_pass.coffee +0 -93
  63. data/lib/assets/javascripts/unpoly/classes/config.coffee +0 -9
  64. data/lib/assets/javascripts/unpoly/classes/css_transition.coffee +0 -118
  65. data/lib/assets/javascripts/unpoly/classes/divertible_chain.coffee +0 -39
  66. data/lib/assets/javascripts/unpoly/classes/event_listener.coffee +0 -116
  67. data/lib/assets/javascripts/unpoly/classes/extract_cascade.coffee +0 -86
  68. data/lib/assets/javascripts/unpoly/classes/extract_plan.coffee +0 -111
  69. data/lib/assets/javascripts/unpoly/classes/field_observer.coffee +0 -80
  70. data/lib/assets/javascripts/unpoly/classes/focus_follower.coffee +0 -29
  71. data/lib/assets/javascripts/unpoly/classes/follow_variant.coffee +0 -64
  72. data/lib/assets/javascripts/unpoly/classes/html_parser.coffee +0 -46
  73. data/lib/assets/javascripts/unpoly/classes/motion_controller.coffee +0 -157
  74. data/lib/assets/javascripts/unpoly/classes/params.coffee.erb +0 -544
  75. data/lib/assets/javascripts/unpoly/classes/record.coffee +0 -22
  76. data/lib/assets/javascripts/unpoly/classes/rect.js +0 -21
  77. data/lib/assets/javascripts/unpoly/classes/request.coffee +0 -247
  78. data/lib/assets/javascripts/unpoly/classes/response.coffee +0 -157
  79. data/lib/assets/javascripts/unpoly/classes/reveal_motion.coffee +0 -102
  80. data/lib/assets/javascripts/unpoly/classes/scroll_motion.coffee +0 -67
  81. data/lib/assets/javascripts/unpoly/classes/selector.coffee +0 -60
  82. data/lib/assets/javascripts/unpoly/classes/store/memory.coffee +0 -26
  83. data/lib/assets/javascripts/unpoly/classes/store/session.coffee +0 -59
  84. data/lib/assets/javascripts/unpoly/classes/tether.coffee +0 -105
  85. data/lib/assets/javascripts/unpoly/classes/url_set.coffee +0 -32
  86. data/lib/assets/javascripts/unpoly/cookie.coffee +0 -56
  87. data/lib/assets/javascripts/unpoly/element.coffee.erb +0 -1129
  88. data/lib/assets/javascripts/unpoly/event.coffee.erb +0 -445
  89. data/lib/assets/javascripts/unpoly/feedback.coffee +0 -353
  90. data/lib/assets/javascripts/unpoly/form.coffee.erb +0 -1084
  91. data/lib/assets/javascripts/unpoly/fragment.coffee.erb +0 -928
  92. data/lib/assets/javascripts/unpoly/framework.coffee +0 -65
  93. data/lib/assets/javascripts/unpoly/history.coffee +0 -268
  94. data/lib/assets/javascripts/unpoly/legacy.coffee +0 -60
  95. data/lib/assets/javascripts/unpoly/link.coffee.erb +0 -622
  96. data/lib/assets/javascripts/unpoly/log.coffee +0 -253
  97. data/lib/assets/javascripts/unpoly/modal.coffee.erb +0 -827
  98. data/lib/assets/javascripts/unpoly/motion.coffee.erb +0 -668
  99. data/lib/assets/javascripts/unpoly/namespace.coffee.erb +0 -5
  100. data/lib/assets/javascripts/unpoly/popup.coffee.erb +0 -515
  101. data/lib/assets/javascripts/unpoly/protocol.coffee +0 -300
  102. data/lib/assets/javascripts/unpoly/proxy.coffee +0 -672
  103. data/lib/assets/javascripts/unpoly/radio.coffee +0 -60
  104. data/lib/assets/javascripts/unpoly/rails.coffee +0 -24
  105. data/lib/assets/javascripts/unpoly/syntax.coffee.erb +0 -476
  106. data/lib/assets/javascripts/unpoly/toast.coffee +0 -67
  107. data/lib/assets/javascripts/unpoly/tooltip.coffee +0 -276
  108. data/lib/assets/javascripts/unpoly/util.coffee.erb +0 -1677
  109. data/lib/assets/javascripts/unpoly/viewport.coffee.erb +0 -830
  110. data/lib/assets/javascripts/unpoly-bootstrap3/feedback-ext.coffee +0 -5
  111. data/lib/assets/javascripts/unpoly-bootstrap3/form-ext.coffee +0 -1
  112. data/lib/assets/javascripts/unpoly-bootstrap3/modal-ext.coffee +0 -14
  113. data/lib/assets/javascripts/unpoly-bootstrap3/viewport-ext.coffee +0 -5
  114. data/lib/assets/javascripts/unpoly-bootstrap3.coffee +0 -2
  115. data/lib/assets/javascripts/unpoly.coffee +0 -28
  116. data/lib/assets/stylesheets/unpoly/close.sass +0 -2
  117. data/lib/assets/stylesheets/unpoly/dom.sass +0 -5
  118. data/lib/assets/stylesheets/unpoly/layout.sass +0 -2
  119. data/lib/assets/stylesheets/unpoly/link.sass +0 -2
  120. data/lib/assets/stylesheets/unpoly/modal.sass +0 -116
  121. data/lib/assets/stylesheets/unpoly/popup.sass +0 -7
  122. data/lib/assets/stylesheets/unpoly/toast.sass +0 -33
  123. data/lib/assets/stylesheets/unpoly/tooltip.sass +0 -62
  124. data/lib/assets/stylesheets/unpoly-bootstrap3/modal-ext.sass +0 -27
  125. data/lib/assets/stylesheets/unpoly-bootstrap3.sass +0 -1
  126. data/lib/assets/stylesheets/unpoly.sass +0 -1
  127. data/lib/unpoly/rails/inspector.rb +0 -149
  128. data/lib/unpoly/rails/inspector_accessor.rb +0 -30
  129. data/package.json +0 -38
  130. data/spec_app/.firefox-version +0 -1
  131. data/spec_app/.gitignore +0 -17
  132. data/spec_app/.rspec +0 -2
  133. data/spec_app/Gemfile +0 -29
  134. data/spec_app/Gemfile.lock +0 -223
  135. data/spec_app/README.rdoc +0 -28
  136. data/spec_app/Rakefile +0 -6
  137. data/spec_app/app/assets/images/.keep +0 -0
  138. data/spec_app/app/assets/images/favicon.png +0 -0
  139. data/spec_app/app/assets/images/grid.png +0 -0
  140. data/spec_app/app/assets/javascripts/bootstrap_manifest.coffee +0 -6
  141. data/spec_app/app/assets/javascripts/integration_test.coffee +0 -5
  142. data/spec_app/app/assets/javascripts/jasmine_specs.coffee +0 -6
  143. data/spec_app/app/assets/stylesheets/_helpers.sass +0 -5
  144. data/spec_app/app/assets/stylesheets/bootstrap_manifest.sass +0 -2
  145. data/spec_app/app/assets/stylesheets/integration_test.sass +0 -88
  146. data/spec_app/app/assets/stylesheets/jasmine_specs.sass +0 -20
  147. data/spec_app/app/controllers/application_controller.rb +0 -14
  148. data/spec_app/app/controllers/binding_test_controller.rb +0 -51
  149. data/spec_app/app/controllers/boot_test_controller.rb +0 -31
  150. data/spec_app/app/controllers/compiler_test_controller.rb +0 -5
  151. data/spec_app/app/controllers/css_test_controller.rb +0 -5
  152. data/spec_app/app/controllers/error_test_controller.rb +0 -5
  153. data/spec_app/app/controllers/form_test/basics_controller.rb +0 -14
  154. data/spec_app/app/controllers/form_test/redirects_controller.rb +0 -17
  155. data/spec_app/app/controllers/form_test/uploads_controller.rb +0 -15
  156. data/spec_app/app/controllers/hash_test_controller.rb +0 -5
  157. data/spec_app/app/controllers/method_test_controller.rb +0 -16
  158. data/spec_app/app/controllers/motion_test_controller.rb +0 -5
  159. data/spec_app/app/controllers/pages_controller.rb +0 -17
  160. data/spec_app/app/controllers/replace_test_controller.rb +0 -5
  161. data/spec_app/app/controllers/reveal_test_controller.rb +0 -5
  162. data/spec_app/app/controllers/scroll_test_controller.rb +0 -5
  163. data/spec_app/app/helpers/application_helper.rb +0 -11
  164. data/spec_app/app/mailers/.keep +0 -0
  165. data/spec_app/app/models/concerns/.keep +0 -0
  166. data/spec_app/app/views/boot_test/defer.erb +0 -18
  167. data/spec_app/app/views/boot_test/module.erb +0 -18
  168. data/spec_app/app/views/boot_test/sync.erb +0 -17
  169. data/spec_app/app/views/compiler_test/timestamp.erb +0 -10
  170. data/spec_app/app/views/css_test/modal.erb +0 -47
  171. data/spec_app/app/views/css_test/modal_contents.erb +0 -5
  172. data/spec_app/app/views/css_test/modal_contents_wide.erb +0 -5
  173. data/spec_app/app/views/css_test/popup.erb +0 -81
  174. data/spec_app/app/views/css_test/popup_contents.erb +0 -5
  175. data/spec_app/app/views/css_test/tooltip.erb +0 -48
  176. data/spec_app/app/views/error_test/trigger.erb +0 -80
  177. data/spec_app/app/views/error_test/unexpected_response.erb +0 -3
  178. data/spec_app/app/views/form_test/basics/new.erb +0 -60
  179. data/spec_app/app/views/form_test/redirects/new.erb +0 -27
  180. data/spec_app/app/views/form_test/redirects/target.erb +0 -6
  181. data/spec_app/app/views/form_test/submission_result.erb +0 -30
  182. data/spec_app/app/views/form_test/uploads/new.erb +0 -44
  183. data/spec_app/app/views/hash_test/unpoly.erb +0 -30
  184. data/spec_app/app/views/hash_test/vanilla.erb +0 -13
  185. data/spec_app/app/views/layouts/integration_test.erb +0 -22
  186. data/spec_app/app/views/layouts/jasmine_rails/spec_runner.html.erb +0 -20
  187. data/spec_app/app/views/method_test/form_target.erb +0 -17
  188. data/spec_app/app/views/method_test/page1.erb +0 -11
  189. data/spec_app/app/views/method_test/page2.erb +0 -6
  190. data/spec_app/app/views/motion_test/animations.erb +0 -16
  191. data/spec_app/app/views/motion_test/transitions.erb +0 -13
  192. data/spec_app/app/views/pages/start.erb +0 -82
  193. data/spec_app/app/views/replace_test/_nav.erb +0 -6
  194. data/spec_app/app/views/replace_test/page1.erb +0 -14
  195. data/spec_app/app/views/replace_test/page2.erb +0 -14
  196. data/spec_app/app/views/replace_test/table.erb +0 -16
  197. data/spec_app/app/views/reveal_test/long1.erb +0 -17
  198. data/spec_app/app/views/reveal_test/long2.erb +0 -17
  199. data/spec_app/app/views/reveal_test/within_document_viewport.erb +0 -24
  200. data/spec_app/app/views/reveal_test/within_overflowing_div_viewport.erb +0 -28
  201. data/spec_app/app/views/scroll_test/long1.erb +0 -30
  202. data/spec_app/bin/bundle +0 -3
  203. data/spec_app/bin/rails +0 -8
  204. data/spec_app/bin/rake +0 -8
  205. data/spec_app/bin/setup +0 -29
  206. data/spec_app/bin/spring +0 -18
  207. data/spec_app/config/application.rb +0 -28
  208. data/spec_app/config/boot.rb +0 -3
  209. data/spec_app/config/database.yml +0 -25
  210. data/spec_app/config/environment.rb +0 -5
  211. data/spec_app/config/environments/development.rb +0 -41
  212. data/spec_app/config/environments/production.rb +0 -79
  213. data/spec_app/config/environments/test.rb +0 -42
  214. data/spec_app/config/initializers/assets.rb +0 -19
  215. data/spec_app/config/initializers/backtrace_silencers.rb +0 -7
  216. data/spec_app/config/initializers/bower_rails.rb +0 -16
  217. data/spec_app/config/initializers/cookies_serializer.rb +0 -3
  218. data/spec_app/config/initializers/filter_parameter_logging.rb +0 -4
  219. data/spec_app/config/initializers/inflections.rb +0 -16
  220. data/spec_app/config/initializers/mime_types.rb +0 -4
  221. data/spec_app/config/initializers/session_store.rb +0 -3
  222. data/spec_app/config/initializers/wrap_parameters.rb +0 -14
  223. data/spec_app/config/locales/en.yml +0 -23
  224. data/spec_app/config/routes.rb +0 -33
  225. data/spec_app/config/secrets.yml +0 -22
  226. data/spec_app/config.ru +0 -4
  227. data/spec_app/db/schema.rb +0 -23
  228. data/spec_app/db/seeds.rb +0 -7
  229. data/spec_app/lib/assets/.keep +0 -0
  230. data/spec_app/lib/tasks/.keep +0 -0
  231. data/spec_app/lib/tasks/cucumber.rake +0 -65
  232. data/spec_app/log/.keep +0 -0
  233. data/spec_app/public/404.html +0 -67
  234. data/spec_app/public/422.html +0 -67
  235. data/spec_app/public/500.html +0 -66
  236. data/spec_app/public/favicon.ico +0 -0
  237. data/spec_app/public/robots.txt +0 -5
  238. data/spec_app/script/cucumber +0 -10
  239. data/spec_app/spec/controllers/binding_test_controller_spec.rb +0 -248
  240. data/spec_app/spec/javascripts/helpers/agent_detector.coffee +0 -20
  241. data/spec_app/spec/javascripts/helpers/async_sequence.js.coffee +0 -103
  242. data/spec_app/spec/javascripts/helpers/browser_switches.js.coffee +0 -21
  243. data/spec_app/spec/javascripts/helpers/enable_logging.js.coffee +0 -2
  244. data/spec_app/spec/javascripts/helpers/fixture.js.coffee +0 -25
  245. data/spec_app/spec/javascripts/helpers/index.js.coffee +0 -1
  246. data/spec_app/spec/javascripts/helpers/jquery_no_conflict.js +0 -1
  247. data/spec_app/spec/javascripts/helpers/knife.js.coffee +0 -69
  248. data/spec_app/spec/javascripts/helpers/last_request.js.coffee +0 -25
  249. data/spec_app/spec/javascripts/helpers/mock_ajax.js.coffee +0 -8
  250. data/spec_app/spec/javascripts/helpers/mock_clock.js.coffee +0 -2
  251. data/spec_app/spec/javascripts/helpers/parse_form_data.js.coffee +0 -24
  252. data/spec_app/spec/javascripts/helpers/promise_state.js +0 -18
  253. data/spec_app/spec/javascripts/helpers/protect_jasmine_runner.coffee +0 -12
  254. data/spec_app/spec/javascripts/helpers/remove_body_margin.js.coffee +0 -8
  255. data/spec_app/spec/javascripts/helpers/reset_history.js.coffee +0 -23
  256. data/spec_app/spec/javascripts/helpers/reset_knife.js.coffee +0 -2
  257. data/spec_app/spec/javascripts/helpers/reset_up.js.coffee +0 -25
  258. data/spec_app/spec/javascripts/helpers/restore_body_scroll.js.coffee +0 -5
  259. data/spec_app/spec/javascripts/helpers/show_lib_versions.coffee +0 -12
  260. data/spec_app/spec/javascripts/helpers/spec_util.coffee +0 -47
  261. data/spec_app/spec/javascripts/helpers/to_be_around.js.coffee +0 -8
  262. data/spec_app/spec/javascripts/helpers/to_be_array.coffee +0 -5
  263. data/spec_app/spec/javascripts/helpers/to_be_attached.coffee +0 -9
  264. data/spec_app/spec/javascripts/helpers/to_be_blank.js.coffee +0 -8
  265. data/spec_app/spec/javascripts/helpers/to_be_detached.coffee +0 -9
  266. data/spec_app/spec/javascripts/helpers/to_be_element.js.coffee +0 -8
  267. data/spec_app/spec/javascripts/helpers/to_be_error.coffee +0 -8
  268. data/spec_app/spec/javascripts/helpers/to_be_given.js.coffee +0 -8
  269. data/spec_app/spec/javascripts/helpers/to_be_hidden.js.coffee +0 -8
  270. data/spec_app/spec/javascripts/helpers/to_be_jquery.js.coffee +0 -5
  271. data/spec_app/spec/javascripts/helpers/to_be_missing.js.coffee +0 -8
  272. data/spec_app/spec/javascripts/helpers/to_be_present.js.coffee +0 -8
  273. data/spec_app/spec/javascripts/helpers/to_be_scrolled_to.coffee +0 -11
  274. data/spec_app/spec/javascripts/helpers/to_be_visible.js.coffee +0 -9
  275. data/spec_app/spec/javascripts/helpers/to_contain.js.coffee +0 -8
  276. data/spec_app/spec/javascripts/helpers/to_end_with.js.coffee +0 -11
  277. data/spec_app/spec/javascripts/helpers/to_equal_jquery.js.coffee +0 -8
  278. data/spec_app/spec/javascripts/helpers/to_equal_node_list.coffee +0 -7
  279. data/spec_app/spec/javascripts/helpers/to_equal_via_is_equal.js.coffee +0 -7
  280. data/spec_app/spec/javascripts/helpers/to_have_class.js.coffee +0 -10
  281. data/spec_app/spec/javascripts/helpers/to_have_descendant.js.coffee +0 -10
  282. data/spec_app/spec/javascripts/helpers/to_have_length.js.coffee +0 -8
  283. data/spec_app/spec/javascripts/helpers/to_have_opacity.coffee +0 -15
  284. data/spec_app/spec/javascripts/helpers/to_have_own_property.js.coffee +0 -8
  285. data/spec_app/spec/javascripts/helpers/to_have_request_method.js.coffee +0 -16
  286. data/spec_app/spec/javascripts/helpers/to_have_text.js.coffee +0 -9
  287. data/spec_app/spec/javascripts/helpers/to_have_unhandled_rejections.coffee +0 -18
  288. data/spec_app/spec/javascripts/helpers/to_match_list.coffee +0 -14
  289. data/spec_app/spec/javascripts/helpers/to_match_selector.coffee +0 -8
  290. data/spec_app/spec/javascripts/helpers/to_match_text.js.coffee +0 -13
  291. data/spec_app/spec/javascripts/helpers/to_match_url.coffee +0 -14
  292. data/spec_app/spec/javascripts/helpers/trigger.js.coffee +0 -200
  293. data/spec_app/spec/javascripts/helpers/wait_until_dom_ready.js.coffee +0 -5
  294. data/spec_app/spec/javascripts/support/jasmine.yml +0 -51
  295. data/spec_app/spec/javascripts/up/browser_spec.js.coffee +0 -150
  296. data/spec_app/spec/javascripts/up/classes/cache_spec.js.coffee +0 -82
  297. data/spec_app/spec/javascripts/up/classes/config_spec.coffee +0 -24
  298. data/spec_app/spec/javascripts/up/classes/divertible_chain_spec.coffee +0 -45
  299. data/spec_app/spec/javascripts/up/classes/focus_tracker_spec.coffee +0 -34
  300. data/spec_app/spec/javascripts/up/classes/params_spec.coffee +0 -557
  301. data/spec_app/spec/javascripts/up/classes/request_spec.coffee +0 -50
  302. data/spec_app/spec/javascripts/up/classes/scroll_motion_spec.js.coffee +0 -51
  303. data/spec_app/spec/javascripts/up/classes/store/memory_spec.js.coffee +0 -70
  304. data/spec_app/spec/javascripts/up/classes/store/session_spec.js.coffee +0 -114
  305. data/spec_app/spec/javascripts/up/element_spec.coffee +0 -897
  306. data/spec_app/spec/javascripts/up/event_spec.js.coffee +0 -530
  307. data/spec_app/spec/javascripts/up/feedback_spec.js.coffee +0 -401
  308. data/spec_app/spec/javascripts/up/form_spec.js.coffee +0 -1527
  309. data/spec_app/spec/javascripts/up/fragment_spec.js.coffee +0 -2624
  310. data/spec_app/spec/javascripts/up/history_spec.js.coffee +0 -340
  311. data/spec_app/spec/javascripts/up/jquery_spec.js.coffee +0 -4
  312. data/spec_app/spec/javascripts/up/legacy_spec.js.coffee +0 -27
  313. data/spec_app/spec/javascripts/up/link_spec.js.coffee +0 -1098
  314. data/spec_app/spec/javascripts/up/log_spec.js.coffee +0 -119
  315. data/spec_app/spec/javascripts/up/modal_spec.js.coffee +0 -939
  316. data/spec_app/spec/javascripts/up/motion_spec.js.coffee +0 -582
  317. data/spec_app/spec/javascripts/up/popup_spec.js.coffee +0 -508
  318. data/spec_app/spec/javascripts/up/protocol_spec.js.coffee +0 -39
  319. data/spec_app/spec/javascripts/up/proxy_spec.js.coffee +0 -1145
  320. data/spec_app/spec/javascripts/up/radio_spec.js.coffee +0 -212
  321. data/spec_app/spec/javascripts/up/rails_spec.js.coffee +0 -118
  322. data/spec_app/spec/javascripts/up/spec_spec.js.coffee +0 -9
  323. data/spec_app/spec/javascripts/up/syntax_spec.js.coffee +0 -304
  324. data/spec_app/spec/javascripts/up/toast_spec.js.coffee +0 -37
  325. data/spec_app/spec/javascripts/up/tooltip_spec.js.coffee +0 -163
  326. data/spec_app/spec/javascripts/up/util_spec.js.coffee +0 -1434
  327. data/spec_app/spec/javascripts/up/viewport_spec.js.coffee +0 -655
  328. data/spec_app/spec/spec_helper.rb +0 -62
  329. data/spec_app/test/controllers/.keep +0 -0
  330. data/spec_app/test/fixtures/.keep +0 -0
  331. data/spec_app/test/helpers/.keep +0 -0
  332. data/spec_app/test/integration/.keep +0 -0
  333. data/spec_app/test/mailers/.keep +0 -0
  334. data/spec_app/test/models/.keep +0 -0
  335. data/spec_app/test/test_helper.rb +0 -10
  336. data/spec_app/vendor/asset-libs/es6-promise-4.1.6/es6-promise.auto.js +0 -1159
  337. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.bower.json +0 -43
  338. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.gitignore +0 -6
  339. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.npmignore +0 -10
  340. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.pairs +0 -6
  341. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.travis.yml +0 -56
  342. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/jasmine-ajax.js +0 -790
  343. data/spec_app/vendor/assets/.keep +0 -0
  344. data/unpoly-rails.gemspec +0 -24
@@ -1,1145 +0,0 @@
1
- u = up.util
2
- $ = jQuery
3
-
4
- describe 'up.proxy', ->
5
-
6
- describe 'JavaScript functions', ->
7
-
8
- describe 'up.request', ->
9
-
10
- it 'makes a request with the given URL and params', ->
11
- up.request('/foo', params: { key: 'value' }, method: 'post')
12
- request = @lastRequest()
13
- expect(request.url).toMatchUrl('/foo')
14
- expect(request.data()).toEqual(key: ['value'])
15
- expect(request.method).toEqual('POST')
16
-
17
- it 'also allows to pass the URL as a { url } option instead', ->
18
- up.request(url: '/foo', params: { key: 'value' }, method: 'post')
19
- request = @lastRequest()
20
- expect(request.url).toMatchUrl('/foo')
21
- expect(request.data()).toEqual(key: ['value'])
22
- expect(request.method).toEqual('POST')
23
-
24
- it 'allows to pass in an up.Request instance instead of an options object', ->
25
- requestArg = new up.Request(url: '/foo', params: { key: 'value' }, method: 'post')
26
- up.request(requestArg)
27
-
28
- jasmineRequest = @lastRequest()
29
- expect(jasmineRequest.url).toMatchUrl('/foo')
30
- expect(jasmineRequest.data()).toEqual(key: ['value'])
31
- expect(jasmineRequest.method).toEqual('POST')
32
-
33
- it 'submits the replacement targets as HTTP headers, so the server may choose to only frender the requested fragments', asyncSpec (next) ->
34
- up.request(url: '/foo', target: '.target', failTarget: '.fail-target')
35
-
36
- next =>
37
- request = @lastRequest()
38
- expect(request.requestHeaders['X-Up-Target']).toEqual('.target')
39
- expect(request.requestHeaders['X-Up-Fail-Target']).toEqual('.fail-target')
40
-
41
- it "sends Unpoly's version as an X-Up-Version request header", asyncSpec (next) ->
42
- up.request(url: '/foo')
43
-
44
- next =>
45
- versionHeader = @lastRequest().requestHeaders['X-Up-Version']
46
- expect(versionHeader).toBePresent()
47
- expect(versionHeader).toEqual(up.version)
48
-
49
- it 'resolves to a Response object that contains information about the response and request', (done) ->
50
- promise = up.request(
51
- url: '/url'
52
- params: { key: 'value' }
53
- method: 'post'
54
- target: '.target'
55
- )
56
-
57
- u.task =>
58
- @respondWith(
59
- status: 201,
60
- responseText: 'response-text'
61
- )
62
-
63
- promise.then (response) ->
64
- expect(response.request.url).toMatchUrl('/url')
65
- expect(response.request.params).toEqual(new up.Params(key: 'value'))
66
- expect(response.request.method).toEqual('POST')
67
- expect(response.request.target).toEqual('.target')
68
- expect(response.request.hash).toBeBlank()
69
-
70
- expect(response.url).toMatchUrl('/url') # If the server signaled a redirect with X-Up-Location, this would be reflected here
71
- expect(response.method).toEqual('POST') # If the server sent a X-Up-Method header, this would be reflected here
72
- expect(response.text).toEqual('response-text')
73
- expect(response.status).toEqual(201)
74
- expect(response.xhr).toBePresent()
75
-
76
- done()
77
-
78
- it 'resolves to a Response that contains the response headers', (done) ->
79
- promise = up.request(url: '/url')
80
-
81
- u.task =>
82
- @respondWith
83
- responseHeaders: { 'foo': 'bar', 'baz': 'bam' }
84
- responseText: 'hello'
85
-
86
- promise.then (response) ->
87
- expect(response.getHeader('foo')).toEqual('bar')
88
-
89
- # Lookup is case-insensitive
90
- expect(response.getHeader('BAZ')).toEqual('bam')
91
-
92
- done()
93
-
94
- it "preserves the URL hash in a separate { hash } property, since although it isn't sent to server, code might need it to process the response", (done) ->
95
- promise = up.request('/url#hash')
96
-
97
- u.task =>
98
- request = @lastRequest()
99
- expect(request.url).toMatchUrl('/url')
100
-
101
- @respondWith('response-text')
102
-
103
- promise.then (response) ->
104
- expect(response.request.url).toMatchUrl('/url')
105
- expect(response.request.hash).toEqual('#hash')
106
- expect(response.url).toMatchUrl('/url')
107
- done()
108
-
109
- describe 'when the server responds with an X-Up-Method header', ->
110
-
111
- it 'updates the { method } property in the response object', (done) ->
112
- promise = up.request(
113
- url: '/url'
114
- params: { key: 'value' }
115
- method: 'post'
116
- target: '.target'
117
- )
118
-
119
- u.task =>
120
- @respondWith(
121
- responseHeaders:
122
- 'X-Up-Location': '/redirect'
123
- 'X-Up-Method': 'GET'
124
- )
125
-
126
- promise.then (response) ->
127
- expect(response.request.url).toMatchUrl('/url')
128
- expect(response.request.method).toEqual('POST')
129
- expect(response.url).toMatchUrl('/redirect')
130
- expect(response.method).toEqual('GET')
131
- done()
132
-
133
- describe 'when the server responds with an X-Up-Location header', ->
134
-
135
- it 'sets the { url } property on the response object', (done) ->
136
- promise = up.request('/request-url#request-hash')
137
-
138
- u.task =>
139
- @respondWith
140
- responseHeaders:
141
- 'X-Up-Location': '/response-url'
142
-
143
- promise.then (response) ->
144
- expect(response.request.url).toMatchUrl('/request-url')
145
- expect(response.request.hash).toEqual('#request-hash')
146
- expect(response.url).toMatchUrl('/response-url')
147
- done()
148
-
149
- it 'considers a redirection URL an alias for the requested URL', asyncSpec (next) ->
150
- up.request('/foo')
151
-
152
- next =>
153
- expect(jasmine.Ajax.requests.count()).toEqual(1)
154
- @respondWith
155
- responseHeaders:
156
- 'X-Up-Location': '/bar'
157
- 'X-Up-Method': 'GET'
158
-
159
- next =>
160
- up.request('/bar')
161
-
162
- next =>
163
- # See that the cached alias is used and no additional requests are made
164
- expect(jasmine.Ajax.requests.count()).toEqual(1)
165
-
166
- it 'does not considers a redirection URL an alias for the requested URL if the original request was never cached', asyncSpec (next) ->
167
- up.request('/foo', method: 'post') # POST requests are not cached
168
-
169
- next =>
170
- expect(jasmine.Ajax.requests.count()).toEqual(1)
171
- @respondWith
172
- responseHeaders:
173
- 'X-Up-Location': '/bar'
174
- 'X-Up-Method': 'GET'
175
-
176
- next =>
177
- up.request('/bar')
178
-
179
- next =>
180
- # See that an additional request was made
181
- expect(jasmine.Ajax.requests.count()).toEqual(2)
182
-
183
- it 'does not considers a redirection URL an alias for the requested URL if the response returned a non-200 status code', asyncSpec (next) ->
184
- up.request('/foo')
185
-
186
- next =>
187
- expect(jasmine.Ajax.requests.count()).toEqual(1)
188
- @respondWith
189
- responseHeaders:
190
- 'X-Up-Location': '/bar'
191
- 'X-Up-Method': 'GET'
192
- status: 500
193
-
194
- next =>
195
- up.request('/bar')
196
-
197
- next =>
198
- # See that an additional request was made
199
- expect(jasmine.Ajax.requests.count()).toEqual(2)
200
-
201
- describeCapability 'canInspectFormData', ->
202
-
203
- it "does not explode if the original request's { params } is a FormData object", asyncSpec (next) ->
204
- up.request('/foo', method: 'post', params: new FormData()) # POST requests are not cached
205
-
206
- next =>
207
- expect(jasmine.Ajax.requests.count()).toEqual(1)
208
- @respondWith
209
- responseHeaders:
210
- 'X-Up-Location': '/bar'
211
- 'X-Up-Method': 'GET'
212
-
213
- next =>
214
- @secondAjaxPromise = up.request('/bar')
215
-
216
- next.await =>
217
- promiseState(@secondAjaxPromise).then (result) ->
218
- # See that the promise was not rejected due to an internal error.
219
- expect(result.state).toEqual('pending')
220
-
221
-
222
- describe 'when the XHR object has a { responseURL } property', ->
223
-
224
- it 'sets the { url } property on the response object', (done) ->
225
- promise = up.request('/request-url#request-hash')
226
-
227
- u.task =>
228
- @respondWith
229
- responseURL: '/response-url'
230
-
231
- promise.then (response) ->
232
- expect(response.request.url).toMatchUrl('/request-url')
233
- expect(response.request.hash).toEqual('#request-hash')
234
- expect(response.url).toMatchUrl('/response-url')
235
- done()
236
-
237
- it 'considers a redirection URL an alias for the requested URL', asyncSpec (next) ->
238
- up.request('/foo')
239
-
240
- next =>
241
- expect(jasmine.Ajax.requests.count()).toEqual(1)
242
- @respondWith
243
- responseURL: '/bar'
244
-
245
- next =>
246
- up.request('/bar')
247
-
248
- next =>
249
- # See that the cached alias is used and no additional requests are made
250
- expect(jasmine.Ajax.requests.count()).toEqual(1)
251
-
252
- it 'does not considers a redirection URL an alias for the requested URL if the original request was never cached', asyncSpec (next) ->
253
- up.request('/foo', method: 'post') # POST requests are not cached
254
-
255
- next =>
256
- expect(jasmine.Ajax.requests.count()).toEqual(1)
257
- @respondWith
258
- responseURL: '/bar'
259
-
260
- next =>
261
- up.request('/bar')
262
-
263
- next =>
264
- # See that an additional request was made
265
- expect(jasmine.Ajax.requests.count()).toEqual(2)
266
-
267
- it 'does not considers a redirection URL an alias for the requested URL if the response returned a non-200 status code', asyncSpec (next) ->
268
- up.request('/foo')
269
-
270
- next =>
271
- expect(jasmine.Ajax.requests.count()).toEqual(1)
272
- @respondWith
273
- responseURL: '/bar'
274
- status: 500
275
-
276
- next =>
277
- up.request('/bar')
278
-
279
-
280
- describe 'CSRF', ->
281
-
282
- beforeEach ->
283
- up.protocol.config.csrfHeader = 'csrf-header'
284
- up.protocol.config.csrfToken = 'csrf-token'
285
-
286
- it 'sets a CSRF token in the header', asyncSpec (next) ->
287
- up.request('/path', method: 'post')
288
- next =>
289
- headers = @lastRequest().requestHeaders
290
- expect(headers['csrf-header']).toEqual('csrf-token')
291
-
292
- it 'does not add a CSRF token if there is none', asyncSpec (next) ->
293
- up.protocol.config.csrfToken = ''
294
- up.request('/path', method: 'post')
295
- next =>
296
- headers = @lastRequest().requestHeaders
297
- expect(headers['csrf-header']).toBeMissing()
298
-
299
- it 'does not add a CSRF token for GET requests', asyncSpec (next) ->
300
- up.request('/path', method: 'get')
301
- next =>
302
- headers = @lastRequest().requestHeaders
303
- expect(headers['csrf-header']).toBeMissing()
304
-
305
- it 'does not add a CSRF token when loading content from another domain', asyncSpec (next) ->
306
- up.request('http://other-domain.tld/path', method: 'post')
307
- next =>
308
- headers = @lastRequest().requestHeaders
309
- expect(headers['csrf-header']).toBeMissing()
310
-
311
- describe 'X-Requested-With header', ->
312
-
313
- it 'sets the header to "XMLHttpRequest" by default', asyncSpec (next) ->
314
- up.request('/path', method: 'post')
315
- next =>
316
- headers = @lastRequest().requestHeaders
317
- expect(headers['X-Requested-With']).toEqual('XMLHttpRequest')
318
-
319
- it 'does not overrride an existing X-Requested-With header', asyncSpec (next) ->
320
- up.request('/path', method: 'post', headers: { 'X-Requested-With': 'Love' })
321
- next =>
322
- headers = @lastRequest().requestHeaders
323
- expect(headers['X-Requested-With']).toEqual('Love')
324
-
325
- describe 'with { params } option', ->
326
-
327
- it "uses the given params as a non-GET request's payload", asyncSpec (next) ->
328
- givenParams = { 'foo-key': 'foo-value', 'bar-key': 'bar-value' }
329
- up.request(url: '/path', method: 'put', params: givenParams)
330
-
331
- next =>
332
- expect(@lastRequest().data()['foo-key']).toEqual(['foo-value'])
333
- expect(@lastRequest().data()['bar-key']).toEqual(['bar-value'])
334
-
335
- it "encodes the given params into the URL of a GET request", (done) ->
336
- givenParams = { 'foo-key': 'foo-value', 'bar-key': 'bar-value' }
337
- promise = up.request(url: '/path', method: 'get', params: givenParams)
338
-
339
- u.task =>
340
- expect(@lastRequest().url).toMatchUrl('/path?foo-key=foo-value&bar-key=bar-value')
341
- expect(@lastRequest().data()).toBeBlank()
342
-
343
- @respondWith('response-text')
344
-
345
- promise.then (response) ->
346
- # See that the response object has been updated by moving the data options
347
- # to the URL. This is important for up.fragment code that works on response.request.
348
- expect(response.request.url).toMatchUrl('/path?foo-key=foo-value&bar-key=bar-value')
349
- expect(response.request.params).toBeBlank()
350
- done()
351
-
352
- it 'caches server responses for the configured duration', asyncSpec (next) ->
353
- up.proxy.config.cacheExpiry = 200 # 1 second for test
354
-
355
- responses = []
356
- trackResponse = (response) -> responses.push(response.text)
357
-
358
- next =>
359
- up.request(url: '/foo').then(trackResponse)
360
- expect(jasmine.Ajax.requests.count()).toEqual(1)
361
-
362
- next.after (10), =>
363
- # Send the same request for the same path
364
- up.request(url: '/foo').then(trackResponse)
365
-
366
- # See that only a single network request was triggered
367
- expect(jasmine.Ajax.requests.count()).toEqual(1)
368
- expect(responses).toEqual([])
369
-
370
- next =>
371
- # Server responds once.
372
- @respondWith('foo')
373
-
374
- next =>
375
- # See that both requests have been fulfilled
376
- expect(responses).toEqual(['foo', 'foo'])
377
-
378
- next.after (200), =>
379
- # Send another request after another 3 minutes
380
- # The clock is now a total of 6 minutes after the first request,
381
- # exceeding the cache's retention time of 5 minutes.
382
- up.request(url: '/foo').then(trackResponse)
383
-
384
- # See that we have triggered a second request
385
- expect(jasmine.Ajax.requests.count()).toEqual(2)
386
-
387
- next =>
388
- @respondWith('bar')
389
-
390
- next =>
391
- expect(responses).toEqual(['foo', 'foo', 'bar'])
392
-
393
- it "does not cache responses if config.cacheExpiry is 0", asyncSpec (next) ->
394
- up.proxy.config.cacheExpiry = 0
395
- next => up.request(url: '/foo')
396
- next => up.request(url: '/foo')
397
- next => expect(jasmine.Ajax.requests.count()).toEqual(2)
398
-
399
- it "does not cache responses if config.cacheSize is 0", asyncSpec (next) ->
400
- up.proxy.config.cacheSize = 0
401
- next => up.request(url: '/foo')
402
- next => up.request(url: '/foo')
403
- next => expect(jasmine.Ajax.requests.count()).toEqual(2)
404
-
405
- it 'does not limit the number of cache entries if config.cacheSize is undefined'
406
-
407
- it 'never discards old cache entries if config.cacheExpiry is undefined'
408
-
409
- it 'respects a config.cacheSize setting', asyncSpec (next) ->
410
- up.proxy.config.cacheSize = 2
411
- next => up.request(url: '/foo')
412
- next => up.request(url: '/bar')
413
- next => up.request(url: '/baz')
414
- next => up.request(url: '/foo')
415
- next => expect(jasmine.Ajax.requests.count()).toEqual(4)
416
-
417
- it "doesn't reuse responses when asked for the same path, but different selectors", asyncSpec (next) ->
418
- next => up.request(url: '/path', target: '.a')
419
- next => up.request(url: '/path', target: '.b')
420
- next => expect(jasmine.Ajax.requests.count()).toEqual(2)
421
-
422
- it "doesn't reuse responses when asked for the same path, but different params", asyncSpec (next) ->
423
- next => up.request(url: '/path', params: { query: 'foo' })
424
- next => up.request(url: '/path', params: { query: 'bar' })
425
- next => expect(jasmine.Ajax.requests.count()).toEqual(2)
426
-
427
- it "reuses a response for an 'html' selector when asked for the same path and any other selector", asyncSpec (next) ->
428
- next => up.request(url: '/path', target: 'html')
429
- next => up.request(url: '/path', target: 'body')
430
- next => up.request(url: '/path', target: 'p')
431
- next => up.request(url: '/path', target: '.klass')
432
- next => expect(jasmine.Ajax.requests.count()).toEqual(1)
433
-
434
- it "reuses a response for a 'body' selector when asked for the same path and any other selector other than 'html'", asyncSpec (next) ->
435
- next => up.request(url: '/path', target: 'body')
436
- next => up.request(url: '/path', target: 'p')
437
- next => up.request(url: '/path', target: '.klass')
438
- next => expect(jasmine.Ajax.requests.count()).toEqual(1)
439
-
440
- it "doesn't reuse a response for a 'body' selector when asked for the same path but an 'html' selector", asyncSpec (next) ->
441
- next => up.request(url: '/path', target: 'body')
442
- next => up.request(url: '/path', target: 'html')
443
- next => expect(jasmine.Ajax.requests.count()).toEqual(2)
444
-
445
- it "doesn't reuse responses for different paths", asyncSpec (next) ->
446
- next => up.request(url: '/foo')
447
- next => up.request(url: '/bar')
448
- next => expect(jasmine.Ajax.requests.count()).toEqual(2)
449
-
450
- u.each ['GET', 'HEAD', 'OPTIONS'], (method) ->
451
-
452
- it "caches #{method} requests", asyncSpec (next) ->
453
- next => up.request(url: '/foo', method: method)
454
- next => up.request(url: '/foo', method: method)
455
- next => expect(jasmine.Ajax.requests.count()).toEqual(1)
456
-
457
- it "does not cache #{method} requests with { cache: false }", asyncSpec (next) ->
458
- next => up.request(url: '/foo', method: method, cache: false)
459
- next => up.request(url: '/foo', method: method, cache: false)
460
- next => expect(jasmine.Ajax.requests.count()).toEqual(2)
461
-
462
- u.each ['POST', 'PUT', 'DELETE'], (method) ->
463
-
464
- it "does not cache #{method} requests", asyncSpec (next) ->
465
- next => up.request(url: '/foo', method: method)
466
- next => up.request(url: '/foo', method: method)
467
- next => expect(jasmine.Ajax.requests.count()).toEqual(2)
468
-
469
- it 'does not cache responses with a non-200 status code', asyncSpec (next) ->
470
- next => up.request(url: '/foo')
471
- next => @respondWith(status: 500, contentType: 'text/html', responseText: 'foo')
472
- next => up.request(url: '/foo')
473
- next => expect(jasmine.Ajax.requests.count()).toEqual(2)
474
-
475
- describe 'with config.wrapMethods set', ->
476
-
477
- it 'should be set by default', ->
478
- expect(up.proxy.config.wrapMethods).toBePresent()
479
-
480
- u.each ['GET', 'POST', 'HEAD', 'OPTIONS'], (method) ->
481
-
482
- it "does not change the method of a #{method} request", asyncSpec (next) ->
483
- up.request(url: '/foo', method: method)
484
-
485
- next =>
486
- request = @lastRequest()
487
- expect(request.method).toEqual(method)
488
- expect(request.data()['_method']).toBeUndefined()
489
-
490
- u.each ['PUT', 'PATCH', 'DELETE'], (method) ->
491
-
492
- it "turns a #{method} request into a POST request and sends the actual method as a { _method } param to prevent unexpected redirect behavior (https://makandracards.com/makandra/38347)", asyncSpec (next) ->
493
- up.request(url: '/foo', method: method)
494
-
495
- next =>
496
- request = @lastRequest()
497
- expect(request.method).toEqual('POST')
498
- expect(request.data()['_method']).toEqual([method])
499
- # expect(request.data()['foo']).toEqual('bar')
500
-
501
- describe 'with config.maxRequests set', ->
502
-
503
- beforeEach ->
504
- @oldMaxRequests = up.proxy.config.maxRequests
505
- up.proxy.config.maxRequests = 1
506
-
507
- afterEach ->
508
- up.proxy.config.maxRequests = @oldMaxRequests
509
-
510
- it 'limits the number of concurrent requests', asyncSpec (next) ->
511
- responses = []
512
- trackResponse = (response) -> responses.push(response.text)
513
-
514
- next =>
515
- up.request(url: '/foo').then(trackResponse)
516
- up.request(url: '/bar').then(trackResponse)
517
-
518
- next =>
519
- expect(jasmine.Ajax.requests.count()).toEqual(1) # only one request was made
520
-
521
- next =>
522
- @respondWith('first response', request: jasmine.Ajax.requests.at(0))
523
-
524
- next =>
525
- expect(responses).toEqual ['first response']
526
- expect(jasmine.Ajax.requests.count()).toEqual(2) # a second request was made
527
-
528
- next =>
529
- @respondWith('second response', request: jasmine.Ajax.requests.at(1))
530
-
531
- next =>
532
- expect(responses).toEqual ['first response', 'second response']
533
-
534
- it 'ignores preloading for the request limit', asyncSpec (next) ->
535
- next => up.request(url: '/foo', preload: true)
536
- next => up.request(url: '/bar')
537
- next => expect(jasmine.Ajax.requests.count()).toEqual(2)
538
- next => up.request(url: '/bar')
539
- next => expect(jasmine.Ajax.requests.count()).toEqual(2)
540
-
541
- describe 'up:proxy:load event', ->
542
-
543
- it 'emits an up:proxy:load event before the request touches the network', asyncSpec (next) ->
544
- listener = jasmine.createSpy('listener')
545
- up.on 'up:proxy:load', listener
546
- up.request('/bar')
547
-
548
- next =>
549
- expect(jasmine.Ajax.requests.count()).toEqual(1)
550
-
551
- partialRequest = jasmine.objectContaining(
552
- method: 'GET',
553
- url: jasmine.stringMatching('/bar')
554
- )
555
- partialEvent = jasmine.objectContaining(request: partialRequest)
556
-
557
- expect(listener).toHaveBeenCalledWith(partialEvent, jasmine.anything(), jasmine.anything())
558
-
559
- it 'allows up:proxy:load listeners to prevent the request (useful to cancel all requests when stopping a test scenario)', (done) ->
560
- listener = jasmine.createSpy('listener').and.callFake (event) ->
561
- expect(jasmine.Ajax.requests.count()).toEqual(0)
562
- event.preventDefault()
563
-
564
- up.on 'up:proxy:load', listener
565
-
566
- promise = up.request('/bar')
567
-
568
- u.task ->
569
- expect(listener).toHaveBeenCalled()
570
- expect(jasmine.Ajax.requests.count()).toEqual(0)
571
-
572
- promiseState(promise).then (result) ->
573
- expect(result.state).toEqual('rejected')
574
- expect(result.value).toBeError(/prevented/i)
575
- done()
576
-
577
- it 'does not block the queue when a request was prevented', (done) ->
578
- up.proxy.config.maxRequests = 1
579
-
580
- listener = jasmine.createSpy('listener').and.callFake (event) ->
581
- # only prevent the first request
582
- if event.request.url.indexOf('/path1') >= 0
583
- event.preventDefault()
584
-
585
- up.on 'up:proxy:load', listener
586
-
587
- promise1 = up.request('/path1')
588
- promise2 = up.request('/path2')
589
-
590
- u.task =>
591
- expect(listener.calls.count()).toBe(2)
592
- expect(jasmine.Ajax.requests.count()).toEqual(1)
593
- expect(@lastRequest().url).toMatchUrl('/path2')
594
- done()
595
-
596
- it 'allows up:proxy:load listeners to manipulate the request headers', (done) ->
597
- listener = (event) ->
598
- event.request.headers['X-From-Listener'] = 'foo'
599
-
600
- up.on 'up:proxy:load', listener
601
-
602
- up.request('/path1')
603
-
604
- u.task =>
605
- expect(@lastRequest().requestHeaders['X-From-Listener']).toEqual('foo')
606
- done()
607
-
608
- describe 'up:proxy:slow and up:proxy:recover events', ->
609
-
610
- beforeEach ->
611
- up.proxy.config.slowDelay = 0
612
- @events = []
613
- u.each ['up:proxy:load', 'up:proxy:loaded', 'up:proxy:slow', 'up:proxy:recover', 'up:proxy:fatal'], (eventName) =>
614
- up.on eventName, =>
615
- @events.push eventName
616
-
617
- it 'emits an up:proxy:slow event if the server takes too long to respond'
618
-
619
- it 'does not emit an up:proxy:slow event if preloading', asyncSpec (next) ->
620
- next =>
621
- # A request for preloading preloading purposes
622
- # doesn't make us busy.
623
- up.request(url: '/foo', preload: true)
624
-
625
- next =>
626
- expect(@events).toEqual([
627
- 'up:proxy:load'
628
- ])
629
- expect(up.proxy.isBusy()).toBe(false)
630
-
631
- next =>
632
- # The same request with preloading does trigger up:proxy:slow.
633
- up.request(url: '/foo')
634
-
635
- next =>
636
- expect(@events).toEqual([
637
- 'up:proxy:load',
638
- 'up:proxy:slow'
639
- ])
640
- expect(up.proxy.isBusy()).toBe(true)
641
-
642
- next =>
643
- # The response resolves both promises and makes
644
- # the proxy idle again.
645
- jasmine.Ajax.requests.at(0).respondWith
646
- status: 200
647
- contentType: 'text/html'
648
- responseText: 'foo'
649
-
650
- next =>
651
- expect(@events).toEqual([
652
- 'up:proxy:load',
653
- 'up:proxy:slow',
654
- 'up:proxy:loaded',
655
- 'up:proxy:recover'
656
- ])
657
- expect(up.proxy.isBusy()).toBe(false)
658
-
659
- it 'can delay the up:proxy:slow event to prevent flickering of spinners', asyncSpec (next) ->
660
- next =>
661
- up.proxy.config.slowDelay = 100
662
- up.request(url: '/foo')
663
-
664
- next =>
665
- expect(@events).toEqual([
666
- 'up:proxy:load'
667
- ])
668
-
669
- next.after 50, =>
670
- expect(@events).toEqual([
671
- 'up:proxy:load'
672
- ])
673
-
674
- next.after 60, =>
675
- expect(@events).toEqual([
676
- 'up:proxy:load',
677
- 'up:proxy:slow'
678
- ])
679
-
680
- next =>
681
- jasmine.Ajax.requests.at(0).respondWith
682
- status: 200
683
- contentType: 'text/html'
684
- responseText: 'foo'
685
-
686
- next =>
687
- expect(@events).toEqual([
688
- 'up:proxy:load',
689
- 'up:proxy:slow',
690
- 'up:proxy:loaded',
691
- 'up:proxy:recover'
692
- ])
693
-
694
- it 'does not emit up:proxy:recover if a delayed up:proxy:slow was never emitted due to a fast response', asyncSpec (next) ->
695
- next =>
696
- up.proxy.config.slowDelay = 200
697
- up.request(url: '/foo')
698
-
699
- next =>
700
- expect(@events).toEqual([
701
- 'up:proxy:load'
702
- ])
703
-
704
- next.after 100, =>
705
- jasmine.Ajax.requests.at(0).respondWith
706
- status: 200
707
- contentType: 'text/html'
708
- responseText: 'foo'
709
-
710
- next.after 250, =>
711
- expect(@events).toEqual([
712
- 'up:proxy:load',
713
- 'up:proxy:loaded'
714
- ])
715
-
716
- it 'emits up:proxy:recover if a request returned but failed with an error code', asyncSpec (next) ->
717
- next =>
718
- up.request(url: '/foo')
719
-
720
- next =>
721
- expect(@events).toEqual([
722
- 'up:proxy:load',
723
- 'up:proxy:slow'
724
- ])
725
-
726
- next =>
727
- jasmine.Ajax.requests.at(0).respondWith
728
- status: 500
729
- contentType: 'text/html'
730
- responseText: 'something went wrong'
731
-
732
- next =>
733
- expect(@events).toEqual([
734
- 'up:proxy:load',
735
- 'up:proxy:slow',
736
- 'up:proxy:loaded',
737
- 'up:proxy:recover'
738
- ])
739
-
740
-
741
- it 'emits up:proxy:recover if a request returned but failed fatally', asyncSpec (next) ->
742
- up.proxy.config.slowDelay = 10
743
-
744
- next =>
745
- up.request(url: '/foo', timeout: 75)
746
-
747
- next.after 50, =>
748
- expect(@events).toEqual([
749
- 'up:proxy:load',
750
- 'up:proxy:slow'
751
- ])
752
-
753
- next =>
754
- jasmine.clock().install() # required by responseTimeout()
755
- @lastRequest().responseTimeout()
756
-
757
- next =>
758
- expect(@events).toEqual([
759
- 'up:proxy:load',
760
- 'up:proxy:slow',
761
- 'up:proxy:fatal',
762
- 'up:proxy:recover'
763
- ])
764
-
765
-
766
- describe 'up.ajax', ->
767
-
768
- it 'fulfills to the response text in order to match the $.ajax() API as good as possible', (done) ->
769
- promise = up.ajax('/url')
770
-
771
- u.timer 100, =>
772
- @respondWith('response-text')
773
-
774
- promise.then (text) ->
775
- expect(text).toEqual('response-text')
776
-
777
- done()
778
-
779
- describe 'up.proxy.preload', ->
780
-
781
- describeCapability 'canPushState', ->
782
-
783
- beforeEach ->
784
- @requestTarget = => @lastRequest().requestHeaders['X-Up-Target']
785
-
786
- it "loads and caches the given link's destination", asyncSpec (next) ->
787
- $fixture('.target')
788
- $link = $fixture('a[href="/path"][up-target=".target"]')
789
-
790
- up.proxy.preload($link)
791
-
792
- next =>
793
- cachedPromise = up.proxy.get(url: '/path', target: '.target')
794
- expect(u.isPromise(cachedPromise)).toBe(true)
795
-
796
- it "does not load a link whose method has side-effects", (done) ->
797
- $fixture('.target')
798
- $link = $fixture('a[href="/path"][up-target=".target"][data-method="post"]')
799
- preloadPromise = up.proxy.preload($link)
800
-
801
- promiseState(preloadPromise).then (result) ->
802
- expect(result.state).toEqual('rejected')
803
- expect(up.proxy.get(url: '/path', target: '.target')).toBeUndefined()
804
- done()
805
-
806
- it 'accepts options', asyncSpec (next) ->
807
- $fixture('.target')
808
- $link = $fixture('a[href="/path"][up-target=".target"]')
809
- up.proxy.preload($link, url: '/options-path')
810
-
811
- next =>
812
- cachedPromise = up.proxy.get(url: '/options-path', target: '.target')
813
- expect(u.isPromise(cachedPromise)).toBe(true)
814
-
815
- describe 'for an [up-target] link', ->
816
-
817
- it 'includes the [up-target] selector as an X-Up-Target header if the targeted element is currently on the page', asyncSpec (next) ->
818
- $fixture('.target')
819
- $link = $fixture('a[href="/path"][up-target=".target"]')
820
- up.proxy.preload($link)
821
- next => expect(@requestTarget()).toEqual('.target')
822
-
823
- it 'replaces the [up-target] selector as with a fallback and uses that as an X-Up-Target header if the targeted element is not currently on the page', asyncSpec (next) ->
824
- $link = $fixture('a[href="/path"][up-target=".target"]')
825
- up.proxy.preload($link)
826
- # The default fallback would usually be `body`, but in Jasmine specs we change
827
- # it to protect the test runner during failures.
828
- next => expect(@requestTarget()).toEqual('.default-fallback')
829
-
830
- it 'calls up.request() with a { preload: true } option so it bypasses the concurrency limit', asyncSpec (next) ->
831
- requestSpy = spyOn(up, 'request')
832
-
833
- $link = $fixture('a[href="/path"][up-target=".target"]')
834
- up.proxy.preload($link)
835
-
836
- next =>
837
- expect(requestSpy).toHaveBeenCalledWith(jasmine.objectContaining(preload: true))
838
-
839
- describe 'for an [up-modal] link', ->
840
-
841
- beforeEach ->
842
- up.motion.config.enabled = false
843
-
844
- it 'includes the [up-modal] selector as an X-Up-Target header and does not replace it with a fallback, since the modal frame always exists', asyncSpec (next) ->
845
- $link = $fixture('a[href="/path"][up-modal=".target"]')
846
- up.proxy.preload($link)
847
- next => expect(@requestTarget()).toEqual('.target')
848
-
849
- it 'does not create a modal frame', asyncSpec (next) ->
850
- $link = $fixture('a[href="/path"][up-modal=".target"]')
851
- up.proxy.preload($link)
852
- next =>
853
- expect('.up-modal').not.toBeAttached()
854
-
855
- it 'does not emit an up:modal:open event', asyncSpec (next) ->
856
- $link = $fixture('a[href="/path"][up-modal=".target"]')
857
- openListener = jasmine.createSpy('listener')
858
- up.on('up:modal:open', openListener)
859
- up.proxy.preload($link)
860
- next =>
861
- expect(openListener).not.toHaveBeenCalled()
862
-
863
- it 'does not close a currently open modal', asyncSpec (next) ->
864
- $link = $fixture('a[href="/path"][up-modal=".target"]')
865
- closeListener = jasmine.createSpy('listener')
866
- up.on('up:modal:close', closeListener)
867
-
868
- up.modal.extract('.content', '<div class="content">Modal content</div>')
869
-
870
- next =>
871
- expect('.up-modal .content').toBeAttached()
872
-
873
- next =>
874
- up.proxy.preload($link)
875
-
876
- next =>
877
- expect('.up-modal .content').toBeAttached()
878
- expect(closeListener).not.toHaveBeenCalled()
879
-
880
- next =>
881
- up.modal.close()
882
-
883
- next =>
884
- expect('.up-modal .content').not.toBeAttached()
885
- expect(closeListener).toHaveBeenCalled()
886
-
887
- it 'does not prevent the opening of other modals while the request is still pending', asyncSpec (next) ->
888
- $link = $fixture('a[href="/path"][up-modal=".target"]')
889
- up.proxy.preload($link)
890
-
891
- next =>
892
- up.modal.extract('.content', '<div class="content">Modal content</div>')
893
-
894
- next =>
895
- expect('.up-modal .content').toBeAttached()
896
-
897
- it 'calls up.request() with a { preload: true } option so it bypasses the concurrency limit', asyncSpec (next) ->
898
- requestSpy = spyOn(up, 'request')
899
-
900
- $link = $fixture('a[href="/path"][up-modal=".target"]')
901
- up.proxy.preload($link)
902
-
903
- next =>
904
- expect(requestSpy).toHaveBeenCalledWith(jasmine.objectContaining(preload: true))
905
-
906
- describe 'for an [up-popup] link', ->
907
-
908
- beforeEach ->
909
- up.motion.config.enabled = false
910
-
911
- it 'includes the [up-popup] selector as an X-Up-Target header and does not replace it with a fallback, since the popup frame always exists', asyncSpec (next) ->
912
- $link = $fixture('a[href="/path"][up-popup=".target"]')
913
- up.proxy.preload($link)
914
- next => expect(@requestTarget()).toEqual('.target')
915
-
916
-
917
- it 'does not create a popup frame', asyncSpec (next) ->
918
- $link = $fixture('a[href="/path"][up-popup=".target"]')
919
- up.proxy.preload($link)
920
- next =>
921
- expect('.up-popup').not.toBeAttached()
922
-
923
- it 'does not emit an up:popup:open event', asyncSpec (next) ->
924
- $link = $fixture('a[href="/path"][up-popup=".target"]')
925
- openListener = jasmine.createSpy('listener')
926
- up.on('up:popup:open', openListener)
927
- up.proxy.preload($link)
928
- next =>
929
- expect(openListener).not.toHaveBeenCalled()
930
-
931
- it 'does not close a currently open popup', asyncSpec (next) ->
932
- $link = $fixture('a[href="/path"][up-popup=".target"]')
933
- closeListener = jasmine.createSpy('listener')
934
- up.on('up:popup:close', closeListener)
935
-
936
- $existingAnchor = $fixture('.existing-anchor')
937
- up.popup.attach($existingAnchor, target: '.content', html: '<div class="content">popup content</div>')
938
-
939
- next =>
940
- expect('.up-popup .content').toBeAttached()
941
-
942
- next =>
943
- up.proxy.preload($link)
944
-
945
- next =>
946
- expect('.up-popup .content').toBeAttached()
947
- expect(closeListener).not.toHaveBeenCalled()
948
-
949
- next =>
950
- up.popup.close()
951
-
952
- next =>
953
- expect('.up-popup .content').not.toBeAttached()
954
- expect(closeListener).toHaveBeenCalled()
955
-
956
- it 'does not prevent the opening of other popups while the request is still pending', asyncSpec (next) ->
957
- $link = $fixture('a[href="/path"][up-popup=".target"]')
958
- up.proxy.preload($link)
959
-
960
- next =>
961
- $anchor = $fixture('.existing-anchor')
962
- up.popup.attach($anchor, target: '.content', html: '<div class="content">popup content</div>')
963
-
964
- next =>
965
- expect('.up-popup .content').toBeAttached()
966
-
967
- it 'calls up.request() with a { preload: true } option so it bypasses the concurrency limit', asyncSpec (next) ->
968
- requestSpy = spyOn(up, 'request')
969
-
970
- $link = $fixture('a[href="/path"][up-popup=".target"]')
971
- up.proxy.preload($link)
972
-
973
- next =>
974
- expect(requestSpy).toHaveBeenCalledWith(jasmine.objectContaining(preload: true))
975
-
976
- describeFallback 'canPushState', ->
977
-
978
- it "does nothing", asyncSpec (next) ->
979
- $fixture('.target')
980
- $link = $fixture('a[href="/path"][up-target=".target"]')
981
- up.proxy.preload($link)
982
- next =>
983
- expect(jasmine.Ajax.requests.count()).toBe(0)
984
-
985
- describe 'up.proxy.get', ->
986
-
987
- it 'returns an existing cache entry for the given request', ->
988
- promise1 = up.request(url: '/foo', params: { key: 'value' })
989
- promise2 = up.proxy.get(url: '/foo', params: { key: 'value' })
990
- expect(promise1).toBe(promise2)
991
-
992
- it 'returns undefined if the given request is not cached', ->
993
- promise = up.proxy.get(url: '/foo', params: { key: 'value' })
994
- expect(promise).toBeUndefined()
995
-
996
- describeCapability 'canInspectFormData', ->
997
-
998
- it "returns undefined if the given request's { params } is a FormData object", ->
999
- promise = up.proxy.get(url: '/foo', params: new FormData())
1000
- expect(promise).toBeUndefined()
1001
-
1002
- describe 'up.proxy.set', ->
1003
-
1004
- it 'should have tests'
1005
-
1006
- describe 'up.proxy.alias', ->
1007
-
1008
- it 'uses an existing cache entry for another request (used in case of redirects)'
1009
-
1010
- describe 'up.proxy.remove', ->
1011
-
1012
- it 'removes the cache entry for the given request'
1013
-
1014
- it 'does nothing if the given request is not cached'
1015
-
1016
- describeCapability 'canInspectFormData', ->
1017
-
1018
- it 'does not crash when passed a request with FormData (bugfix)', ->
1019
- removal = -> up.proxy.remove(url: '/path', params: new FormData())
1020
- expect(removal).not.toThrowError()
1021
-
1022
- describe 'up.proxy.clear', ->
1023
-
1024
- it 'removes all cache entries'
1025
-
1026
- describe 'unobtrusive behavior', ->
1027
-
1028
- describe '[up-preload]', ->
1029
-
1030
- it 'preloads the link destination when hovering, after a delay', asyncSpec (next) ->
1031
- up.proxy.config.preloadDelay = 100
1032
-
1033
- $fixture('.target').text('old text')
1034
-
1035
- $link = $fixture('a[href="/foo"][up-target=".target"][up-preload]')
1036
- up.hello($link)
1037
-
1038
- Trigger.hoverSequence($link)
1039
-
1040
- next.after 50, =>
1041
- # It's still too early
1042
- expect(jasmine.Ajax.requests.count()).toEqual(0)
1043
-
1044
- next.after 75, =>
1045
- expect(jasmine.Ajax.requests.count()).toEqual(1)
1046
- expect(@lastRequest().url).toMatchUrl('/foo')
1047
- expect(@lastRequest()).toHaveRequestMethod('GET')
1048
- expect(@lastRequest().requestHeaders['X-Up-Target']).toEqual('.target')
1049
-
1050
- @respondWith """
1051
- <div class="target">
1052
- new text
1053
- </div>
1054
- """
1055
-
1056
- next =>
1057
- # We only preloaded, so the target isn't replaced yet.
1058
- expect('.target').toHaveText('old text')
1059
-
1060
- Trigger.clickSequence($link)
1061
-
1062
- next =>
1063
- # No additional request has been sent since we already preloaded
1064
- expect(jasmine.Ajax.requests.count()).toEqual(1)
1065
-
1066
- # The target is replaced instantly
1067
- expect('.target').toHaveText('new text')
1068
-
1069
- it 'does not send a request if the user stops hovering before the delay is over', asyncSpec (next) ->
1070
- up.proxy.config.preloadDelay = 100
1071
-
1072
- $fixture('.target').text('old text')
1073
-
1074
- $link = $fixture('a[href="/foo"][up-target=".target"][up-preload]')
1075
- up.hello($link)
1076
-
1077
- Trigger.hoverSequence($link)
1078
-
1079
- next.after 40, =>
1080
- # It's still too early
1081
- expect(jasmine.Ajax.requests.count()).toEqual(0)
1082
-
1083
- Trigger.unhoverSequence($link)
1084
-
1085
- next.after 90, =>
1086
- expect(jasmine.Ajax.requests.count()).toEqual(0)
1087
-
1088
- it 'does not cache a failed response', asyncSpec (next) ->
1089
- up.proxy.config.preloadDelay = 0
1090
-
1091
- $fixture('.target').text('old text')
1092
-
1093
- $link = $fixture('a[href="/foo"][up-target=".target"][up-preload]')
1094
- up.hello($link)
1095
-
1096
- Trigger.hoverSequence($link)
1097
-
1098
- next.after 50, =>
1099
- expect(jasmine.Ajax.requests.count()).toEqual(1)
1100
-
1101
- @respondWith
1102
- status: 500
1103
- responseText: """
1104
- <div class="target">
1105
- new text
1106
- </div>
1107
- """
1108
-
1109
- next =>
1110
- # We only preloaded, so the target isn't replaced yet.
1111
- expect('.target').toHaveText('old text')
1112
-
1113
- Trigger.click($link)
1114
-
1115
- next =>
1116
- # Since the preloading failed, we send another request
1117
- expect(jasmine.Ajax.requests.count()).toEqual(2)
1118
-
1119
- # Since there isn't anyone who could handle the rejection inside
1120
- # the event handler, our handler mutes the rejection.
1121
- expect(window).not.toHaveUnhandledRejections() if REJECTION_EVENTS_SUPPORTED
1122
-
1123
- it 'triggers a separate AJAX request when hovered multiple times and the cache expires between hovers', asyncSpec (next) ->
1124
- up.proxy.config.cacheExpiry = 100
1125
- up.proxy.config.preloadDelay = 0
1126
-
1127
- $element = $fixture('a[href="/foo"][up-preload]')
1128
- up.hello($element)
1129
-
1130
- Trigger.hoverSequence($element)
1131
-
1132
- next.after 10, =>
1133
- expect(jasmine.Ajax.requests.count()).toEqual(1)
1134
-
1135
- next.after 10, =>
1136
- Trigger.hoverSequence($element)
1137
-
1138
- next.after 10, =>
1139
- expect(jasmine.Ajax.requests.count()).toEqual(1)
1140
-
1141
- next.after 150, =>
1142
- Trigger.hoverSequence($element)
1143
-
1144
- next.after 30, =>
1145
- expect(jasmine.Ajax.requests.count()).toEqual(2)