praxis 0.19.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/CHANGELOG.md +16 -0
  4. data/lib/api_browser/Gruntfile.js +125 -16
  5. data/lib/api_browser/app/index.html +5 -1
  6. data/lib/api_browser/app/js/directives/fixed_if_fits.js +28 -17
  7. data/lib/api_browser/app/js/directives/highlight.js +14 -0
  8. data/lib/api_browser/app/js/directives/request_examples.js +29 -0
  9. data/lib/api_browser/app/js/factories/Documentation.js +6 -0
  10. data/lib/api_browser/app/js/factories/Example.js +47 -0
  11. data/lib/api_browser/app/js/factories/prepare_template.js +15 -0
  12. data/lib/api_browser/app/js/factories/template_for.js +2 -12
  13. data/lib/api_browser/app/sass/modules/_sidebar.scss +2 -0
  14. data/lib/api_browser/app/views/action.html +6 -24
  15. data/lib/api_browser/app/views/examples/general.html +26 -0
  16. data/lib/api_browser/{bower.json → bower_template.json} +13 -3
  17. data/lib/api_browser/package.json +3 -1
  18. data/lib/praxis/application.rb +2 -0
  19. data/lib/praxis/docs/generator.rb +4 -2
  20. data/lib/praxis/extensions/field_selection/field_selector.rb +1 -0
  21. data/lib/praxis/media_type.rb +1 -1
  22. data/lib/praxis/plugin.rb +4 -0
  23. data/lib/praxis/plugin_concern.rb +2 -1
  24. data/lib/praxis/tasks/api_docs.rb +9 -2
  25. data/lib/praxis/version.rb +1 -1
  26. data/praxis.gemspec +2 -2
  27. data/spec/praxis/action_definition_spec.rb +26 -1
  28. data/spec/praxis/extensions/field_selection/field_selector_spec.rb +4 -0
  29. data/spec/praxis/media_type_spec.rb +4 -3
  30. data/spec/support/spec_media_types.rb +5 -1
  31. metadata +12 -242
  32. data/lib/api_browser/app/bower_components/angular-mocks/.bower.json +0 -19
  33. data/lib/api_browser/app/bower_components/angular-mocks/README.md +0 -63
  34. data/lib/api_browser/app/bower_components/angular-mocks/angular-mocks.js +0 -2452
  35. data/lib/api_browser/app/bower_components/angular-mocks/bower.json +0 -9
  36. data/lib/api_browser/app/bower_components/angular-mocks/ngAnimateMock.js +0 -2
  37. data/lib/api_browser/app/bower_components/angular-mocks/ngMock.js +0 -2
  38. data/lib/api_browser/app/bower_components/angular-mocks/ngMockE2E.js +0 -2
  39. data/lib/api_browser/app/bower_components/angular-mocks/package.json +0 -27
  40. data/lib/api_browser/app/bower_components/angular-sanitize/.bower.json +0 -19
  41. data/lib/api_browser/app/bower_components/angular-sanitize/README.md +0 -68
  42. data/lib/api_browser/app/bower_components/angular-sanitize/angular-sanitize.js +0 -683
  43. data/lib/api_browser/app/bower_components/angular-sanitize/angular-sanitize.min.js +0 -16
  44. data/lib/api_browser/app/bower_components/angular-sanitize/angular-sanitize.min.js.map +0 -8
  45. data/lib/api_browser/app/bower_components/angular-sanitize/bower.json +0 -9
  46. data/lib/api_browser/app/bower_components/angular-sanitize/index.js +0 -2
  47. data/lib/api_browser/app/bower_components/angular-sanitize/package.json +0 -26
  48. data/lib/api_browser/app/bower_components/angular-ui-bootstrap-bower/.bower.json +0 -31
  49. data/lib/api_browser/app/bower_components/angular-ui-bootstrap-bower/bower.json +0 -19
  50. data/lib/api_browser/app/bower_components/angular-ui-bootstrap-bower/ui-bootstrap-csp.css +0 -6
  51. data/lib/api_browser/app/bower_components/angular-ui-bootstrap-bower/ui-bootstrap-tpls.js +0 -4840
  52. data/lib/api_browser/app/bower_components/angular-ui-bootstrap-bower/ui-bootstrap-tpls.min.js +0 -10
  53. data/lib/api_browser/app/bower_components/angular-ui-bootstrap-bower/ui-bootstrap.js +0 -4461
  54. data/lib/api_browser/app/bower_components/angular-ui-bootstrap-bower/ui-bootstrap.min.js +0 -9
  55. data/lib/api_browser/app/bower_components/angular-ui-router/.bower.json +0 -33
  56. data/lib/api_browser/app/bower_components/angular-ui-router/CHANGELOG.md +0 -228
  57. data/lib/api_browser/app/bower_components/angular-ui-router/CONTRIBUTING.md +0 -65
  58. data/lib/api_browser/app/bower_components/angular-ui-router/LICENSE +0 -21
  59. data/lib/api_browser/app/bower_components/angular-ui-router/README.md +0 -245
  60. data/lib/api_browser/app/bower_components/angular-ui-router/api/angular-ui-router.d.ts +0 -126
  61. data/lib/api_browser/app/bower_components/angular-ui-router/bower.json +0 -23
  62. data/lib/api_browser/app/bower_components/angular-ui-router/release/angular-ui-router.js +0 -4370
  63. data/lib/api_browser/app/bower_components/angular-ui-router/release/angular-ui-router.min.js +0 -7
  64. data/lib/api_browser/app/bower_components/angular-ui-router/src/common.js +0 -292
  65. data/lib/api_browser/app/bower_components/angular-ui-router/src/resolve.js +0 -252
  66. data/lib/api_browser/app/bower_components/angular-ui-router/src/state.js +0 -1465
  67. data/lib/api_browser/app/bower_components/angular-ui-router/src/stateDirectives.js +0 -285
  68. data/lib/api_browser/app/bower_components/angular-ui-router/src/stateFilters.js +0 -39
  69. data/lib/api_browser/app/bower_components/angular-ui-router/src/templateFactory.js +0 -110
  70. data/lib/api_browser/app/bower_components/angular-ui-router/src/urlMatcherFactory.js +0 -1050
  71. data/lib/api_browser/app/bower_components/angular-ui-router/src/urlRouter.js +0 -427
  72. data/lib/api_browser/app/bower_components/angular-ui-router/src/view.js +0 -71
  73. data/lib/api_browser/app/bower_components/angular-ui-router/src/viewDirective.js +0 -303
  74. data/lib/api_browser/app/bower_components/angular-ui-router/src/viewScroll.js +0 -52
  75. data/lib/api_browser/app/bower_components/angular/.bower.json +0 -17
  76. data/lib/api_browser/app/bower_components/angular/README.md +0 -64
  77. data/lib/api_browser/app/bower_components/angular/angular-csp.css +0 -21
  78. data/lib/api_browser/app/bower_components/angular/angular.js +0 -28133
  79. data/lib/api_browser/app/bower_components/angular/angular.min.js +0 -289
  80. data/lib/api_browser/app/bower_components/angular/angular.min.js.gzip +0 -0
  81. data/lib/api_browser/app/bower_components/angular/angular.min.js.map +0 -8
  82. data/lib/api_browser/app/bower_components/angular/bower.json +0 -8
  83. data/lib/api_browser/app/bower_components/angular/index.js +0 -2
  84. data/lib/api_browser/app/bower_components/angular/package.json +0 -25
  85. data/lib/api_browser/app/bower_components/bootstrap-sass/.bower.json +0 -41
  86. data/lib/api_browser/app/bower_components/bootstrap-sass/CHANGELOG.md +0 -108
  87. data/lib/api_browser/app/bower_components/bootstrap-sass/CONTRIBUTING.md +0 -79
  88. data/lib/api_browser/app/bower_components/bootstrap-sass/README.md +0 -218
  89. data/lib/api_browser/app/bower_components/bootstrap-sass/bower.json +0 -22
  90. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/fonts/bootstrap/glyphicons-halflings-regular.eot +0 -0
  91. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/fonts/bootstrap/glyphicons-halflings-regular.svg +0 -229
  92. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/fonts/bootstrap/glyphicons-halflings-regular.ttf +0 -0
  93. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/fonts/bootstrap/glyphicons-halflings-regular.woff +0 -0
  94. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/javascripts/bootstrap.js +0 -12
  95. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/javascripts/bootstrap/affix.js +0 -126
  96. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/javascripts/bootstrap/alert.js +0 -98
  97. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/javascripts/bootstrap/button.js +0 -115
  98. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/javascripts/bootstrap/carousel.js +0 -217
  99. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/javascripts/bootstrap/collapse.js +0 -179
  100. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/javascripts/bootstrap/dropdown.js +0 -154
  101. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/javascripts/bootstrap/modal.js +0 -246
  102. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/javascripts/bootstrap/popover.js +0 -117
  103. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/javascripts/bootstrap/scrollspy.js +0 -158
  104. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/javascripts/bootstrap/tab.js +0 -135
  105. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/javascripts/bootstrap/tooltip.js +0 -386
  106. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/javascripts/bootstrap/transition.js +0 -56
  107. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap.scss +0 -1
  108. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_alerts.scss +0 -67
  109. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_badges.scss +0 -51
  110. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_breadcrumbs.scss +0 -23
  111. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_button-groups.scss +0 -227
  112. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_buttons.scss +0 -155
  113. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_carousel.scss +0 -232
  114. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_close.scss +0 -35
  115. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_code.scss +0 -53
  116. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_component-animations.scss +0 -29
  117. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_dropdowns.scss +0 -188
  118. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_forms.scss +0 -374
  119. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_glyphicons.scss +0 -237
  120. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_grid.scss +0 -79
  121. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_input-groups.scss +0 -136
  122. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_jumbotron.scss +0 -46
  123. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_labels.scss +0 -64
  124. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_list-group.scss +0 -88
  125. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_media.scss +0 -56
  126. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_mixins.scss +0 -848
  127. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_modals.scss +0 -129
  128. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_navbar.scss +0 -616
  129. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_navs.scss +0 -242
  130. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_normalize.scss +0 -406
  131. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_pager.scss +0 -55
  132. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_pagination.scss +0 -85
  133. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_panels.scss +0 -182
  134. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_popovers.scss +0 -133
  135. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_print.scss +0 -105
  136. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_progress-bars.scss +0 -80
  137. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_responsive-utilities.scss +0 -198
  138. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_scaffolding.scss +0 -119
  139. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_tables.scss +0 -231
  140. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_theme.scss +0 -247
  141. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_thumbnails.scss +0 -38
  142. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_tooltip.scss +0 -95
  143. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_type.scss +0 -281
  144. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_utilities.scss +0 -56
  145. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_variables.scss +0 -646
  146. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_wells.scss +0 -29
  147. data/lib/api_browser/app/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap/bootstrap.scss +0 -49
  148. data/lib/api_browser/app/bower_components/jquery/.bower.json +0 -38
  149. data/lib/api_browser/app/bower_components/jquery/MIT-LICENSE.txt +0 -21
  150. data/lib/api_browser/app/bower_components/jquery/bower.json +0 -27
  151. data/lib/api_browser/app/bower_components/jquery/dist/jquery.js +0 -9190
  152. data/lib/api_browser/app/bower_components/jquery/dist/jquery.min.js +0 -5
  153. data/lib/api_browser/app/bower_components/jquery/dist/jquery.min.map +0 -1
  154. data/lib/api_browser/app/bower_components/jquery/src/ajax.js +0 -806
  155. data/lib/api_browser/app/bower_components/jquery/src/ajax/jsonp.js +0 -89
  156. data/lib/api_browser/app/bower_components/jquery/src/ajax/load.js +0 -75
  157. data/lib/api_browser/app/bower_components/jquery/src/ajax/parseJSON.js +0 -13
  158. data/lib/api_browser/app/bower_components/jquery/src/ajax/parseXML.js +0 -28
  159. data/lib/api_browser/app/bower_components/jquery/src/ajax/script.js +0 -64
  160. data/lib/api_browser/app/bower_components/jquery/src/ajax/var/nonce.js +0 -5
  161. data/lib/api_browser/app/bower_components/jquery/src/ajax/var/rquery.js +0 -3
  162. data/lib/api_browser/app/bower_components/jquery/src/ajax/xhr.js +0 -135
  163. data/lib/api_browser/app/bower_components/jquery/src/attributes.js +0 -11
  164. data/lib/api_browser/app/bower_components/jquery/src/attributes/attr.js +0 -143
  165. data/lib/api_browser/app/bower_components/jquery/src/attributes/classes.js +0 -158
  166. data/lib/api_browser/app/bower_components/jquery/src/attributes/prop.js +0 -96
  167. data/lib/api_browser/app/bower_components/jquery/src/attributes/support.js +0 -35
  168. data/lib/api_browser/app/bower_components/jquery/src/attributes/val.js +0 -163
  169. data/lib/api_browser/app/bower_components/jquery/src/callbacks.js +0 -205
  170. data/lib/api_browser/app/bower_components/jquery/src/core.js +0 -498
  171. data/lib/api_browser/app/bower_components/jquery/src/core/access.js +0 -60
  172. data/lib/api_browser/app/bower_components/jquery/src/core/init.js +0 -123
  173. data/lib/api_browser/app/bower_components/jquery/src/core/parseHTML.js +0 -39
  174. data/lib/api_browser/app/bower_components/jquery/src/core/ready.js +0 -97
  175. data/lib/api_browser/app/bower_components/jquery/src/core/var/rsingleTag.js +0 -4
  176. data/lib/api_browser/app/bower_components/jquery/src/css.js +0 -451
  177. data/lib/api_browser/app/bower_components/jquery/src/css/addGetHookIf.js +0 -24
  178. data/lib/api_browser/app/bower_components/jquery/src/css/curCSS.js +0 -57
  179. data/lib/api_browser/app/bower_components/jquery/src/css/defaultDisplay.js +0 -70
  180. data/lib/api_browser/app/bower_components/jquery/src/css/hiddenVisibleSelectors.js +0 -15
  181. data/lib/api_browser/app/bower_components/jquery/src/css/support.js +0 -91
  182. data/lib/api_browser/app/bower_components/jquery/src/css/swap.js +0 -28
  183. data/lib/api_browser/app/bower_components/jquery/src/css/var/cssExpand.js +0 -3
  184. data/lib/api_browser/app/bower_components/jquery/src/css/var/getStyles.js +0 -5
  185. data/lib/api_browser/app/bower_components/jquery/src/css/var/isHidden.js +0 -13
  186. data/lib/api_browser/app/bower_components/jquery/src/css/var/rmargin.js +0 -3
  187. data/lib/api_browser/app/bower_components/jquery/src/css/var/rnumnonpx.js +0 -5
  188. data/lib/api_browser/app/bower_components/jquery/src/data.js +0 -179
  189. data/lib/api_browser/app/bower_components/jquery/src/data/Data.js +0 -181
  190. data/lib/api_browser/app/bower_components/jquery/src/data/accepts.js +0 -20
  191. data/lib/api_browser/app/bower_components/jquery/src/data/var/data_priv.js +0 -5
  192. data/lib/api_browser/app/bower_components/jquery/src/data/var/data_user.js +0 -5
  193. data/lib/api_browser/app/bower_components/jquery/src/deferred.js +0 -149
  194. data/lib/api_browser/app/bower_components/jquery/src/deprecated.js +0 -13
  195. data/lib/api_browser/app/bower_components/jquery/src/dimensions.js +0 -50
  196. data/lib/api_browser/app/bower_components/jquery/src/effects.js +0 -649
  197. data/lib/api_browser/app/bower_components/jquery/src/effects/Tween.js +0 -114
  198. data/lib/api_browser/app/bower_components/jquery/src/effects/animatedSelector.js +0 -13
  199. data/lib/api_browser/app/bower_components/jquery/src/event.js +0 -868
  200. data/lib/api_browser/app/bower_components/jquery/src/event/alias.js +0 -39
  201. data/lib/api_browser/app/bower_components/jquery/src/event/support.js +0 -9
  202. data/lib/api_browser/app/bower_components/jquery/src/exports/amd.js +0 -24
  203. data/lib/api_browser/app/bower_components/jquery/src/exports/global.js +0 -32
  204. data/lib/api_browser/app/bower_components/jquery/src/intro.js +0 -44
  205. data/lib/api_browser/app/bower_components/jquery/src/jquery.js +0 -36
  206. data/lib/api_browser/app/bower_components/jquery/src/manipulation.js +0 -582
  207. data/lib/api_browser/app/bower_components/jquery/src/manipulation/_evalUrl.js +0 -18
  208. data/lib/api_browser/app/bower_components/jquery/src/manipulation/support.js +0 -31
  209. data/lib/api_browser/app/bower_components/jquery/src/manipulation/var/rcheckableType.js +0 -3
  210. data/lib/api_browser/app/bower_components/jquery/src/offset.js +0 -204
  211. data/lib/api_browser/app/bower_components/jquery/src/outro.js +0 -1
  212. data/lib/api_browser/app/bower_components/jquery/src/queue.js +0 -142
  213. data/lib/api_browser/app/bower_components/jquery/src/queue/delay.js +0 -22
  214. data/lib/api_browser/app/bower_components/jquery/src/selector-native.js +0 -172
  215. data/lib/api_browser/app/bower_components/jquery/src/selector-sizzle.js +0 -14
  216. data/lib/api_browser/app/bower_components/jquery/src/selector.js +0 -1
  217. data/lib/api_browser/app/bower_components/jquery/src/serialize.js +0 -111
  218. data/lib/api_browser/app/bower_components/jquery/src/sizzle/dist/sizzle.js +0 -2044
  219. data/lib/api_browser/app/bower_components/jquery/src/sizzle/dist/sizzle.min.js +0 -3
  220. data/lib/api_browser/app/bower_components/jquery/src/sizzle/dist/sizzle.min.map +0 -1
  221. data/lib/api_browser/app/bower_components/jquery/src/traversing.js +0 -200
  222. data/lib/api_browser/app/bower_components/jquery/src/traversing/findFilter.js +0 -100
  223. data/lib/api_browser/app/bower_components/jquery/src/traversing/var/rneedsContext.js +0 -6
  224. data/lib/api_browser/app/bower_components/jquery/src/var/arr.js +0 -3
  225. data/lib/api_browser/app/bower_components/jquery/src/var/class2type.js +0 -4
  226. data/lib/api_browser/app/bower_components/jquery/src/var/concat.js +0 -5
  227. data/lib/api_browser/app/bower_components/jquery/src/var/hasOwn.js +0 -5
  228. data/lib/api_browser/app/bower_components/jquery/src/var/indexOf.js +0 -5
  229. data/lib/api_browser/app/bower_components/jquery/src/var/pnum.js +0 -3
  230. data/lib/api_browser/app/bower_components/jquery/src/var/push.js +0 -5
  231. data/lib/api_browser/app/bower_components/jquery/src/var/rnotwhite.js +0 -3
  232. data/lib/api_browser/app/bower_components/jquery/src/var/slice.js +0 -5
  233. data/lib/api_browser/app/bower_components/jquery/src/var/strundefined.js +0 -3
  234. data/lib/api_browser/app/bower_components/jquery/src/var/support.js +0 -4
  235. data/lib/api_browser/app/bower_components/jquery/src/var/toString.js +0 -5
  236. data/lib/api_browser/app/bower_components/jquery/src/wrap.js +0 -78
  237. data/lib/api_browser/app/bower_components/lodash/.bower.json +0 -30
  238. data/lib/api_browser/app/bower_components/lodash/LICENSE.txt +0 -22
  239. data/lib/api_browser/app/bower_components/lodash/bower.json +0 -20
  240. data/lib/api_browser/app/bower_components/lodash/lodash.js +0 -12235
  241. data/lib/api_browser/app/bower_components/lodash/lodash.min.js +0 -98
  242. data/lib/api_browser/app/bower_components/showdown/.bower.json +0 -39
  243. data/lib/api_browser/app/bower_components/showdown/.jshintignore +0 -2
  244. data/lib/api_browser/app/bower_components/showdown/.travis.yml +0 -8
  245. data/lib/api_browser/app/bower_components/showdown/Gruntfile.js +0 -100
  246. data/lib/api_browser/app/bower_components/showdown/README.md +0 -317
  247. data/lib/api_browser/app/bower_components/showdown/bower.json +0 -26
  248. data/lib/api_browser/app/bower_components/showdown/compressed/Showdown.js +0 -1606
  249. data/lib/api_browser/app/bower_components/showdown/compressed/Showdown.js.map +0 -1
  250. data/lib/api_browser/app/bower_components/showdown/compressed/Showdown.min.js +0 -2
  251. data/lib/api_browser/app/bower_components/showdown/compressed/extensions/github.min.js +0 -2
  252. data/lib/api_browser/app/bower_components/showdown/compressed/extensions/github.min.js.map +0 -1
  253. data/lib/api_browser/app/bower_components/showdown/compressed/extensions/prettify.min.js +0 -2
  254. data/lib/api_browser/app/bower_components/showdown/compressed/extensions/prettify.min.js.map +0 -1
  255. data/lib/api_browser/app/bower_components/showdown/compressed/extensions/table.min.js +0 -2
  256. data/lib/api_browser/app/bower_components/showdown/compressed/extensions/table.min.js.map +0 -1
  257. data/lib/api_browser/app/bower_components/showdown/compressed/extensions/twitter.min.js +0 -2
  258. data/lib/api_browser/app/bower_components/showdown/compressed/extensions/twitter.min.js.map +0 -1
  259. data/lib/api_browser/app/bower_components/showdown/license.txt +0 -34
  260. data/lib/api_browser/app/bower_components/showdown/package.json +0 -47
  261. data/lib/api_browser/app/bower_components/showdown/src/extensions/github.js +0 -25
  262. data/lib/api_browser/app/bower_components/showdown/src/extensions/prettify.js +0 -29
  263. data/lib/api_browser/app/bower_components/showdown/src/extensions/table.js +0 -106
  264. data/lib/api_browser/app/bower_components/showdown/src/extensions/twitter.js +0 -42
  265. data/lib/api_browser/app/bower_components/showdown/src/ng-showdown.js +0 -150
  266. data/lib/api_browser/app/bower_components/showdown/src/showdown.js +0 -1454
@@ -1,19 +0,0 @@
1
- {
2
- "name": "angular-mocks",
3
- "version": "1.4.0",
4
- "main": "./angular-mocks.js",
5
- "ignore": [],
6
- "dependencies": {
7
- "angular": "1.4.0"
8
- },
9
- "homepage": "https://github.com/angular/bower-angular-mocks",
10
- "_release": "1.4.0",
11
- "_resolution": {
12
- "type": "version",
13
- "tag": "v1.4.0",
14
- "commit": "5a7f9f0bad5da4314df7f638fcaf330ff864cae2"
15
- },
16
- "_source": "git://github.com/angular/bower-angular-mocks.git",
17
- "_target": "~1.4.0",
18
- "_originalSource": "angular-mocks"
19
- }
@@ -1,63 +0,0 @@
1
- # packaged angular-mocks
2
-
3
- This repo is for distribution on `npm` and `bower`. The source for this module is in the
4
- [main AngularJS repo](https://github.com/angular/angular.js/tree/master/src/ngMock).
5
- Please file issues and pull requests against that repo.
6
-
7
- ## Install
8
-
9
- You can install this package either with `npm` or with `bower`.
10
-
11
- ### npm
12
-
13
- ```shell
14
- npm install angular-mocks
15
- ```
16
-
17
- You can `require` ngMock modules:
18
-
19
- ```js
20
- var angular = require('angular');
21
- angular.module('myMod', [
22
- require('angular-animate'),
23
- require('angular-mocks/ngMock')
24
- require('angular-mocks/ngAnimateMock')
25
- ]);
26
- ```
27
-
28
- ### bower
29
-
30
- ```shell
31
- bower install angular-mocks
32
- ```
33
-
34
- The mocks are then available at `bower_components/angular-mocks/angular-mocks.js`.
35
-
36
- ## Documentation
37
-
38
- Documentation is available on the
39
- [AngularJS docs site](https://docs.angularjs.org/guide/unit-testing).
40
-
41
- ## License
42
-
43
- The MIT License
44
-
45
- Copyright (c) 2010-2015 Google, Inc. http://angularjs.org
46
-
47
- Permission is hereby granted, free of charge, to any person obtaining a copy
48
- of this software and associated documentation files (the "Software"), to deal
49
- in the Software without restriction, including without limitation the rights
50
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
51
- copies of the Software, and to permit persons to whom the Software is
52
- furnished to do so, subject to the following conditions:
53
-
54
- The above copyright notice and this permission notice shall be included in
55
- all copies or substantial portions of the Software.
56
-
57
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
58
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
59
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
60
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
61
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
62
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
63
- THE SOFTWARE.
@@ -1,2452 +0,0 @@
1
- /**
2
- * @license AngularJS v1.4.0
3
- * (c) 2010-2015 Google, Inc. http://angularjs.org
4
- * License: MIT
5
- */
6
- (function(window, angular, undefined) {
7
-
8
- 'use strict';
9
-
10
- /**
11
- * @ngdoc object
12
- * @name angular.mock
13
- * @description
14
- *
15
- * Namespace from 'angular-mocks.js' which contains testing related code.
16
- */
17
- angular.mock = {};
18
-
19
- /**
20
- * ! This is a private undocumented service !
21
- *
22
- * @name $browser
23
- *
24
- * @description
25
- * This service is a mock implementation of {@link ng.$browser}. It provides fake
26
- * implementation for commonly used browser apis that are hard to test, e.g. setTimeout, xhr,
27
- * cookies, etc...
28
- *
29
- * The api of this service is the same as that of the real {@link ng.$browser $browser}, except
30
- * that there are several helper methods available which can be used in tests.
31
- */
32
- angular.mock.$BrowserProvider = function() {
33
- this.$get = function() {
34
- return new angular.mock.$Browser();
35
- };
36
- };
37
-
38
- angular.mock.$Browser = function() {
39
- var self = this;
40
-
41
- this.isMock = true;
42
- self.$$url = "http://server/";
43
- self.$$lastUrl = self.$$url; // used by url polling fn
44
- self.pollFns = [];
45
-
46
- // TODO(vojta): remove this temporary api
47
- self.$$completeOutstandingRequest = angular.noop;
48
- self.$$incOutstandingRequestCount = angular.noop;
49
-
50
-
51
- // register url polling fn
52
-
53
- self.onUrlChange = function(listener) {
54
- self.pollFns.push(
55
- function() {
56
- if (self.$$lastUrl !== self.$$url || self.$$state !== self.$$lastState) {
57
- self.$$lastUrl = self.$$url;
58
- self.$$lastState = self.$$state;
59
- listener(self.$$url, self.$$state);
60
- }
61
- }
62
- );
63
-
64
- return listener;
65
- };
66
-
67
- self.$$applicationDestroyed = angular.noop;
68
- self.$$checkUrlChange = angular.noop;
69
-
70
- self.deferredFns = [];
71
- self.deferredNextId = 0;
72
-
73
- self.defer = function(fn, delay) {
74
- delay = delay || 0;
75
- self.deferredFns.push({time:(self.defer.now + delay), fn:fn, id: self.deferredNextId});
76
- self.deferredFns.sort(function(a, b) { return a.time - b.time;});
77
- return self.deferredNextId++;
78
- };
79
-
80
-
81
- /**
82
- * @name $browser#defer.now
83
- *
84
- * @description
85
- * Current milliseconds mock time.
86
- */
87
- self.defer.now = 0;
88
-
89
-
90
- self.defer.cancel = function(deferId) {
91
- var fnIndex;
92
-
93
- angular.forEach(self.deferredFns, function(fn, index) {
94
- if (fn.id === deferId) fnIndex = index;
95
- });
96
-
97
- if (fnIndex !== undefined) {
98
- self.deferredFns.splice(fnIndex, 1);
99
- return true;
100
- }
101
-
102
- return false;
103
- };
104
-
105
-
106
- /**
107
- * @name $browser#defer.flush
108
- *
109
- * @description
110
- * Flushes all pending requests and executes the defer callbacks.
111
- *
112
- * @param {number=} number of milliseconds to flush. See {@link #defer.now}
113
- */
114
- self.defer.flush = function(delay) {
115
- if (angular.isDefined(delay)) {
116
- self.defer.now += delay;
117
- } else {
118
- if (self.deferredFns.length) {
119
- self.defer.now = self.deferredFns[self.deferredFns.length - 1].time;
120
- } else {
121
- throw new Error('No deferred tasks to be flushed');
122
- }
123
- }
124
-
125
- while (self.deferredFns.length && self.deferredFns[0].time <= self.defer.now) {
126
- self.deferredFns.shift().fn();
127
- }
128
- };
129
-
130
- self.$$baseHref = '/';
131
- self.baseHref = function() {
132
- return this.$$baseHref;
133
- };
134
- };
135
- angular.mock.$Browser.prototype = {
136
-
137
- /**
138
- * @name $browser#poll
139
- *
140
- * @description
141
- * run all fns in pollFns
142
- */
143
- poll: function poll() {
144
- angular.forEach(this.pollFns, function(pollFn) {
145
- pollFn();
146
- });
147
- },
148
-
149
- url: function(url, replace, state) {
150
- if (angular.isUndefined(state)) {
151
- state = null;
152
- }
153
- if (url) {
154
- this.$$url = url;
155
- // Native pushState serializes & copies the object; simulate it.
156
- this.$$state = angular.copy(state);
157
- return this;
158
- }
159
-
160
- return this.$$url;
161
- },
162
-
163
- state: function() {
164
- return this.$$state;
165
- },
166
-
167
- notifyWhenNoOutstandingRequests: function(fn) {
168
- fn();
169
- }
170
- };
171
-
172
-
173
- /**
174
- * @ngdoc provider
175
- * @name $exceptionHandlerProvider
176
- *
177
- * @description
178
- * Configures the mock implementation of {@link ng.$exceptionHandler} to rethrow or to log errors
179
- * passed to the `$exceptionHandler`.
180
- */
181
-
182
- /**
183
- * @ngdoc service
184
- * @name $exceptionHandler
185
- *
186
- * @description
187
- * Mock implementation of {@link ng.$exceptionHandler} that rethrows or logs errors passed
188
- * to it. See {@link ngMock.$exceptionHandlerProvider $exceptionHandlerProvider} for configuration
189
- * information.
190
- *
191
- *
192
- * ```js
193
- * describe('$exceptionHandlerProvider', function() {
194
- *
195
- * it('should capture log messages and exceptions', function() {
196
- *
197
- * module(function($exceptionHandlerProvider) {
198
- * $exceptionHandlerProvider.mode('log');
199
- * });
200
- *
201
- * inject(function($log, $exceptionHandler, $timeout) {
202
- * $timeout(function() { $log.log(1); });
203
- * $timeout(function() { $log.log(2); throw 'banana peel'; });
204
- * $timeout(function() { $log.log(3); });
205
- * expect($exceptionHandler.errors).toEqual([]);
206
- * expect($log.assertEmpty());
207
- * $timeout.flush();
208
- * expect($exceptionHandler.errors).toEqual(['banana peel']);
209
- * expect($log.log.logs).toEqual([[1], [2], [3]]);
210
- * });
211
- * });
212
- * });
213
- * ```
214
- */
215
-
216
- angular.mock.$ExceptionHandlerProvider = function() {
217
- var handler;
218
-
219
- /**
220
- * @ngdoc method
221
- * @name $exceptionHandlerProvider#mode
222
- *
223
- * @description
224
- * Sets the logging mode.
225
- *
226
- * @param {string} mode Mode of operation, defaults to `rethrow`.
227
- *
228
- * - `log`: Sometimes it is desirable to test that an error is thrown, for this case the `log`
229
- * mode stores an array of errors in `$exceptionHandler.errors`, to allow later
230
- * assertion of them. See {@link ngMock.$log#assertEmpty assertEmpty()} and
231
- * {@link ngMock.$log#reset reset()}
232
- * - `rethrow`: If any errors are passed to the handler in tests, it typically means that there
233
- * is a bug in the application or test, so this mock will make these tests fail.
234
- * For any implementations that expect exceptions to be thrown, the `rethrow` mode
235
- * will also maintain a log of thrown errors.
236
- */
237
- this.mode = function(mode) {
238
-
239
- switch (mode) {
240
- case 'log':
241
- case 'rethrow':
242
- var errors = [];
243
- handler = function(e) {
244
- if (arguments.length == 1) {
245
- errors.push(e);
246
- } else {
247
- errors.push([].slice.call(arguments, 0));
248
- }
249
- if (mode === "rethrow") {
250
- throw e;
251
- }
252
- };
253
- handler.errors = errors;
254
- break;
255
- default:
256
- throw new Error("Unknown mode '" + mode + "', only 'log'/'rethrow' modes are allowed!");
257
- }
258
- };
259
-
260
- this.$get = function() {
261
- return handler;
262
- };
263
-
264
- this.mode('rethrow');
265
- };
266
-
267
-
268
- /**
269
- * @ngdoc service
270
- * @name $log
271
- *
272
- * @description
273
- * Mock implementation of {@link ng.$log} that gathers all logged messages in arrays
274
- * (one array per logging level). These arrays are exposed as `logs` property of each of the
275
- * level-specific log function, e.g. for level `error` the array is exposed as `$log.error.logs`.
276
- *
277
- */
278
- angular.mock.$LogProvider = function() {
279
- var debug = true;
280
-
281
- function concat(array1, array2, index) {
282
- return array1.concat(Array.prototype.slice.call(array2, index));
283
- }
284
-
285
- this.debugEnabled = function(flag) {
286
- if (angular.isDefined(flag)) {
287
- debug = flag;
288
- return this;
289
- } else {
290
- return debug;
291
- }
292
- };
293
-
294
- this.$get = function() {
295
- var $log = {
296
- log: function() { $log.log.logs.push(concat([], arguments, 0)); },
297
- warn: function() { $log.warn.logs.push(concat([], arguments, 0)); },
298
- info: function() { $log.info.logs.push(concat([], arguments, 0)); },
299
- error: function() { $log.error.logs.push(concat([], arguments, 0)); },
300
- debug: function() {
301
- if (debug) {
302
- $log.debug.logs.push(concat([], arguments, 0));
303
- }
304
- }
305
- };
306
-
307
- /**
308
- * @ngdoc method
309
- * @name $log#reset
310
- *
311
- * @description
312
- * Reset all of the logging arrays to empty.
313
- */
314
- $log.reset = function() {
315
- /**
316
- * @ngdoc property
317
- * @name $log#log.logs
318
- *
319
- * @description
320
- * Array of messages logged using {@link ng.$log#log `log()`}.
321
- *
322
- * @example
323
- * ```js
324
- * $log.log('Some Log');
325
- * var first = $log.log.logs.unshift();
326
- * ```
327
- */
328
- $log.log.logs = [];
329
- /**
330
- * @ngdoc property
331
- * @name $log#info.logs
332
- *
333
- * @description
334
- * Array of messages logged using {@link ng.$log#info `info()`}.
335
- *
336
- * @example
337
- * ```js
338
- * $log.info('Some Info');
339
- * var first = $log.info.logs.unshift();
340
- * ```
341
- */
342
- $log.info.logs = [];
343
- /**
344
- * @ngdoc property
345
- * @name $log#warn.logs
346
- *
347
- * @description
348
- * Array of messages logged using {@link ng.$log#warn `warn()`}.
349
- *
350
- * @example
351
- * ```js
352
- * $log.warn('Some Warning');
353
- * var first = $log.warn.logs.unshift();
354
- * ```
355
- */
356
- $log.warn.logs = [];
357
- /**
358
- * @ngdoc property
359
- * @name $log#error.logs
360
- *
361
- * @description
362
- * Array of messages logged using {@link ng.$log#error `error()`}.
363
- *
364
- * @example
365
- * ```js
366
- * $log.error('Some Error');
367
- * var first = $log.error.logs.unshift();
368
- * ```
369
- */
370
- $log.error.logs = [];
371
- /**
372
- * @ngdoc property
373
- * @name $log#debug.logs
374
- *
375
- * @description
376
- * Array of messages logged using {@link ng.$log#debug `debug()`}.
377
- *
378
- * @example
379
- * ```js
380
- * $log.debug('Some Error');
381
- * var first = $log.debug.logs.unshift();
382
- * ```
383
- */
384
- $log.debug.logs = [];
385
- };
386
-
387
- /**
388
- * @ngdoc method
389
- * @name $log#assertEmpty
390
- *
391
- * @description
392
- * Assert that all of the logging methods have no logged messages. If any messages are present,
393
- * an exception is thrown.
394
- */
395
- $log.assertEmpty = function() {
396
- var errors = [];
397
- angular.forEach(['error', 'warn', 'info', 'log', 'debug'], function(logLevel) {
398
- angular.forEach($log[logLevel].logs, function(log) {
399
- angular.forEach(log, function(logItem) {
400
- errors.push('MOCK $log (' + logLevel + '): ' + String(logItem) + '\n' +
401
- (logItem.stack || ''));
402
- });
403
- });
404
- });
405
- if (errors.length) {
406
- errors.unshift("Expected $log to be empty! Either a message was logged unexpectedly, or " +
407
- "an expected log message was not checked and removed:");
408
- errors.push('');
409
- throw new Error(errors.join('\n---------\n'));
410
- }
411
- };
412
-
413
- $log.reset();
414
- return $log;
415
- };
416
- };
417
-
418
-
419
- /**
420
- * @ngdoc service
421
- * @name $interval
422
- *
423
- * @description
424
- * Mock implementation of the $interval service.
425
- *
426
- * Use {@link ngMock.$interval#flush `$interval.flush(millis)`} to
427
- * move forward by `millis` milliseconds and trigger any functions scheduled to run in that
428
- * time.
429
- *
430
- * @param {function()} fn A function that should be called repeatedly.
431
- * @param {number} delay Number of milliseconds between each function call.
432
- * @param {number=} [count=0] Number of times to repeat. If not set, or 0, will repeat
433
- * indefinitely.
434
- * @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise
435
- * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
436
- * @param {...*=} Pass additional parameters to the executed function.
437
- * @returns {promise} A promise which will be notified on each iteration.
438
- */
439
- angular.mock.$IntervalProvider = function() {
440
- this.$get = ['$browser', '$rootScope', '$q', '$$q',
441
- function($browser, $rootScope, $q, $$q) {
442
- var repeatFns = [],
443
- nextRepeatId = 0,
444
- now = 0;
445
-
446
- var $interval = function(fn, delay, count, invokeApply) {
447
- var hasParams = arguments.length > 4,
448
- args = hasParams ? Array.prototype.slice.call(arguments, 4) : [],
449
- iteration = 0,
450
- skipApply = (angular.isDefined(invokeApply) && !invokeApply),
451
- deferred = (skipApply ? $$q : $q).defer(),
452
- promise = deferred.promise;
453
-
454
- count = (angular.isDefined(count)) ? count : 0;
455
- promise.then(null, null, (!hasParams) ? fn : function() {
456
- fn.apply(null, args);
457
- });
458
-
459
- promise.$$intervalId = nextRepeatId;
460
-
461
- function tick() {
462
- deferred.notify(iteration++);
463
-
464
- if (count > 0 && iteration >= count) {
465
- var fnIndex;
466
- deferred.resolve(iteration);
467
-
468
- angular.forEach(repeatFns, function(fn, index) {
469
- if (fn.id === promise.$$intervalId) fnIndex = index;
470
- });
471
-
472
- if (fnIndex !== undefined) {
473
- repeatFns.splice(fnIndex, 1);
474
- }
475
- }
476
-
477
- if (skipApply) {
478
- $browser.defer.flush();
479
- } else {
480
- $rootScope.$apply();
481
- }
482
- }
483
-
484
- repeatFns.push({
485
- nextTime:(now + delay),
486
- delay: delay,
487
- fn: tick,
488
- id: nextRepeatId,
489
- deferred: deferred
490
- });
491
- repeatFns.sort(function(a, b) { return a.nextTime - b.nextTime;});
492
-
493
- nextRepeatId++;
494
- return promise;
495
- };
496
- /**
497
- * @ngdoc method
498
- * @name $interval#cancel
499
- *
500
- * @description
501
- * Cancels a task associated with the `promise`.
502
- *
503
- * @param {promise} promise A promise from calling the `$interval` function.
504
- * @returns {boolean} Returns `true` if the task was successfully cancelled.
505
- */
506
- $interval.cancel = function(promise) {
507
- if (!promise) return false;
508
- var fnIndex;
509
-
510
- angular.forEach(repeatFns, function(fn, index) {
511
- if (fn.id === promise.$$intervalId) fnIndex = index;
512
- });
513
-
514
- if (fnIndex !== undefined) {
515
- repeatFns[fnIndex].deferred.reject('canceled');
516
- repeatFns.splice(fnIndex, 1);
517
- return true;
518
- }
519
-
520
- return false;
521
- };
522
-
523
- /**
524
- * @ngdoc method
525
- * @name $interval#flush
526
- * @description
527
- *
528
- * Runs interval tasks scheduled to be run in the next `millis` milliseconds.
529
- *
530
- * @param {number=} millis maximum timeout amount to flush up until.
531
- *
532
- * @return {number} The amount of time moved forward.
533
- */
534
- $interval.flush = function(millis) {
535
- now += millis;
536
- while (repeatFns.length && repeatFns[0].nextTime <= now) {
537
- var task = repeatFns[0];
538
- task.fn();
539
- task.nextTime += task.delay;
540
- repeatFns.sort(function(a, b) { return a.nextTime - b.nextTime;});
541
- }
542
- return millis;
543
- };
544
-
545
- return $interval;
546
- }];
547
- };
548
-
549
-
550
- /* jshint -W101 */
551
- /* The R_ISO8061_STR regex is never going to fit into the 100 char limit!
552
- * This directive should go inside the anonymous function but a bug in JSHint means that it would
553
- * not be enacted early enough to prevent the warning.
554
- */
555
- var R_ISO8061_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?:\:?(\d\d)(?:\:?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
556
-
557
- function jsonStringToDate(string) {
558
- var match;
559
- if (match = string.match(R_ISO8061_STR)) {
560
- var date = new Date(0),
561
- tzHour = 0,
562
- tzMin = 0;
563
- if (match[9]) {
564
- tzHour = toInt(match[9] + match[10]);
565
- tzMin = toInt(match[9] + match[11]);
566
- }
567
- date.setUTCFullYear(toInt(match[1]), toInt(match[2]) - 1, toInt(match[3]));
568
- date.setUTCHours(toInt(match[4] || 0) - tzHour,
569
- toInt(match[5] || 0) - tzMin,
570
- toInt(match[6] || 0),
571
- toInt(match[7] || 0));
572
- return date;
573
- }
574
- return string;
575
- }
576
-
577
- function toInt(str) {
578
- return parseInt(str, 10);
579
- }
580
-
581
- function padNumber(num, digits, trim) {
582
- var neg = '';
583
- if (num < 0) {
584
- neg = '-';
585
- num = -num;
586
- }
587
- num = '' + num;
588
- while (num.length < digits) num = '0' + num;
589
- if (trim) {
590
- num = num.substr(num.length - digits);
591
- }
592
- return neg + num;
593
- }
594
-
595
-
596
- /**
597
- * @ngdoc type
598
- * @name angular.mock.TzDate
599
- * @description
600
- *
601
- * *NOTE*: this is not an injectable instance, just a globally available mock class of `Date`.
602
- *
603
- * Mock of the Date type which has its timezone specified via constructor arg.
604
- *
605
- * The main purpose is to create Date-like instances with timezone fixed to the specified timezone
606
- * offset, so that we can test code that depends on local timezone settings without dependency on
607
- * the time zone settings of the machine where the code is running.
608
- *
609
- * @param {number} offset Offset of the *desired* timezone in hours (fractions will be honored)
610
- * @param {(number|string)} timestamp Timestamp representing the desired time in *UTC*
611
- *
612
- * @example
613
- * !!!! WARNING !!!!!
614
- * This is not a complete Date object so only methods that were implemented can be called safely.
615
- * To make matters worse, TzDate instances inherit stuff from Date via a prototype.
616
- *
617
- * We do our best to intercept calls to "unimplemented" methods, but since the list of methods is
618
- * incomplete we might be missing some non-standard methods. This can result in errors like:
619
- * "Date.prototype.foo called on incompatible Object".
620
- *
621
- * ```js
622
- * var newYearInBratislava = new TzDate(-1, '2009-12-31T23:00:00Z');
623
- * newYearInBratislava.getTimezoneOffset() => -60;
624
- * newYearInBratislava.getFullYear() => 2010;
625
- * newYearInBratislava.getMonth() => 0;
626
- * newYearInBratislava.getDate() => 1;
627
- * newYearInBratislava.getHours() => 0;
628
- * newYearInBratislava.getMinutes() => 0;
629
- * newYearInBratislava.getSeconds() => 0;
630
- * ```
631
- *
632
- */
633
- angular.mock.TzDate = function(offset, timestamp) {
634
- var self = new Date(0);
635
- if (angular.isString(timestamp)) {
636
- var tsStr = timestamp;
637
-
638
- self.origDate = jsonStringToDate(timestamp);
639
-
640
- timestamp = self.origDate.getTime();
641
- if (isNaN(timestamp)) {
642
- throw {
643
- name: "Illegal Argument",
644
- message: "Arg '" + tsStr + "' passed into TzDate constructor is not a valid date string"
645
- };
646
- }
647
- } else {
648
- self.origDate = new Date(timestamp);
649
- }
650
-
651
- var localOffset = new Date(timestamp).getTimezoneOffset();
652
- self.offsetDiff = localOffset * 60 * 1000 - offset * 1000 * 60 * 60;
653
- self.date = new Date(timestamp + self.offsetDiff);
654
-
655
- self.getTime = function() {
656
- return self.date.getTime() - self.offsetDiff;
657
- };
658
-
659
- self.toLocaleDateString = function() {
660
- return self.date.toLocaleDateString();
661
- };
662
-
663
- self.getFullYear = function() {
664
- return self.date.getFullYear();
665
- };
666
-
667
- self.getMonth = function() {
668
- return self.date.getMonth();
669
- };
670
-
671
- self.getDate = function() {
672
- return self.date.getDate();
673
- };
674
-
675
- self.getHours = function() {
676
- return self.date.getHours();
677
- };
678
-
679
- self.getMinutes = function() {
680
- return self.date.getMinutes();
681
- };
682
-
683
- self.getSeconds = function() {
684
- return self.date.getSeconds();
685
- };
686
-
687
- self.getMilliseconds = function() {
688
- return self.date.getMilliseconds();
689
- };
690
-
691
- self.getTimezoneOffset = function() {
692
- return offset * 60;
693
- };
694
-
695
- self.getUTCFullYear = function() {
696
- return self.origDate.getUTCFullYear();
697
- };
698
-
699
- self.getUTCMonth = function() {
700
- return self.origDate.getUTCMonth();
701
- };
702
-
703
- self.getUTCDate = function() {
704
- return self.origDate.getUTCDate();
705
- };
706
-
707
- self.getUTCHours = function() {
708
- return self.origDate.getUTCHours();
709
- };
710
-
711
- self.getUTCMinutes = function() {
712
- return self.origDate.getUTCMinutes();
713
- };
714
-
715
- self.getUTCSeconds = function() {
716
- return self.origDate.getUTCSeconds();
717
- };
718
-
719
- self.getUTCMilliseconds = function() {
720
- return self.origDate.getUTCMilliseconds();
721
- };
722
-
723
- self.getDay = function() {
724
- return self.date.getDay();
725
- };
726
-
727
- // provide this method only on browsers that already have it
728
- if (self.toISOString) {
729
- self.toISOString = function() {
730
- return padNumber(self.origDate.getUTCFullYear(), 4) + '-' +
731
- padNumber(self.origDate.getUTCMonth() + 1, 2) + '-' +
732
- padNumber(self.origDate.getUTCDate(), 2) + 'T' +
733
- padNumber(self.origDate.getUTCHours(), 2) + ':' +
734
- padNumber(self.origDate.getUTCMinutes(), 2) + ':' +
735
- padNumber(self.origDate.getUTCSeconds(), 2) + '.' +
736
- padNumber(self.origDate.getUTCMilliseconds(), 3) + 'Z';
737
- };
738
- }
739
-
740
- //hide all methods not implemented in this mock that the Date prototype exposes
741
- var unimplementedMethods = ['getUTCDay',
742
- 'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds',
743
- 'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear',
744
- 'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds',
745
- 'setYear', 'toDateString', 'toGMTString', 'toJSON', 'toLocaleFormat', 'toLocaleString',
746
- 'toLocaleTimeString', 'toSource', 'toString', 'toTimeString', 'toUTCString', 'valueOf'];
747
-
748
- angular.forEach(unimplementedMethods, function(methodName) {
749
- self[methodName] = function() {
750
- throw new Error("Method '" + methodName + "' is not implemented in the TzDate mock");
751
- };
752
- });
753
-
754
- return self;
755
- };
756
-
757
- //make "tzDateInstance instanceof Date" return true
758
- angular.mock.TzDate.prototype = Date.prototype;
759
- /* jshint +W101 */
760
-
761
- angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
762
-
763
- .config(['$provide', function($provide) {
764
-
765
- var reflowQueue = [];
766
- $provide.value('$$animateReflow', function(fn) {
767
- var index = reflowQueue.length;
768
- reflowQueue.push(fn);
769
- return function cancel() {
770
- reflowQueue.splice(index, 1);
771
- };
772
- });
773
-
774
- $provide.decorator('$animate', ['$delegate', '$$asyncCallback', '$timeout', '$browser', '$$rAF',
775
- function($delegate, $$asyncCallback, $timeout, $browser, $$rAF) {
776
- var animate = {
777
- queue: [],
778
- cancel: $delegate.cancel,
779
- enabled: $delegate.enabled,
780
- triggerCallbackEvents: function() {
781
- $$rAF.flush();
782
- $$asyncCallback.flush();
783
- },
784
- triggerCallbackPromise: function() {
785
- $timeout.flush(0);
786
- },
787
- triggerCallbacks: function() {
788
- this.triggerCallbackEvents();
789
- this.triggerCallbackPromise();
790
- },
791
- triggerReflow: function() {
792
- angular.forEach(reflowQueue, function(fn) {
793
- fn();
794
- });
795
- reflowQueue = [];
796
- }
797
- };
798
-
799
- angular.forEach(
800
- ['animate','enter','leave','move','addClass','removeClass','setClass'], function(method) {
801
- animate[method] = function() {
802
- animate.queue.push({
803
- event: method,
804
- element: arguments[0],
805
- options: arguments[arguments.length - 1],
806
- args: arguments
807
- });
808
- return $delegate[method].apply($delegate, arguments);
809
- };
810
- });
811
-
812
- return animate;
813
- }]);
814
-
815
- }]);
816
-
817
-
818
- /**
819
- * @ngdoc function
820
- * @name angular.mock.dump
821
- * @description
822
- *
823
- * *NOTE*: this is not an injectable instance, just a globally available function.
824
- *
825
- * Method for serializing common angular objects (scope, elements, etc..) into strings, useful for
826
- * debugging.
827
- *
828
- * This method is also available on window, where it can be used to display objects on debug
829
- * console.
830
- *
831
- * @param {*} object - any object to turn into string.
832
- * @return {string} a serialized string of the argument
833
- */
834
- angular.mock.dump = function(object) {
835
- return serialize(object);
836
-
837
- function serialize(object) {
838
- var out;
839
-
840
- if (angular.isElement(object)) {
841
- object = angular.element(object);
842
- out = angular.element('<div></div>');
843
- angular.forEach(object, function(element) {
844
- out.append(angular.element(element).clone());
845
- });
846
- out = out.html();
847
- } else if (angular.isArray(object)) {
848
- out = [];
849
- angular.forEach(object, function(o) {
850
- out.push(serialize(o));
851
- });
852
- out = '[ ' + out.join(', ') + ' ]';
853
- } else if (angular.isObject(object)) {
854
- if (angular.isFunction(object.$eval) && angular.isFunction(object.$apply)) {
855
- out = serializeScope(object);
856
- } else if (object instanceof Error) {
857
- out = object.stack || ('' + object.name + ': ' + object.message);
858
- } else {
859
- // TODO(i): this prevents methods being logged,
860
- // we should have a better way to serialize objects
861
- out = angular.toJson(object, true);
862
- }
863
- } else {
864
- out = String(object);
865
- }
866
-
867
- return out;
868
- }
869
-
870
- function serializeScope(scope, offset) {
871
- offset = offset || ' ';
872
- var log = [offset + 'Scope(' + scope.$id + '): {'];
873
- for (var key in scope) {
874
- if (Object.prototype.hasOwnProperty.call(scope, key) && !key.match(/^(\$|this)/)) {
875
- log.push(' ' + key + ': ' + angular.toJson(scope[key]));
876
- }
877
- }
878
- var child = scope.$$childHead;
879
- while (child) {
880
- log.push(serializeScope(child, offset + ' '));
881
- child = child.$$nextSibling;
882
- }
883
- log.push('}');
884
- return log.join('\n' + offset);
885
- }
886
- };
887
-
888
- /**
889
- * @ngdoc service
890
- * @name $httpBackend
891
- * @description
892
- * Fake HTTP backend implementation suitable for unit testing applications that use the
893
- * {@link ng.$http $http service}.
894
- *
895
- * *Note*: For fake HTTP backend implementation suitable for end-to-end testing or backend-less
896
- * development please see {@link ngMockE2E.$httpBackend e2e $httpBackend mock}.
897
- *
898
- * During unit testing, we want our unit tests to run quickly and have no external dependencies so
899
- * we don’t want to send [XHR](https://developer.mozilla.org/en/xmlhttprequest) or
900
- * [JSONP](http://en.wikipedia.org/wiki/JSONP) requests to a real server. All we really need is
901
- * to verify whether a certain request has been sent or not, or alternatively just let the
902
- * application make requests, respond with pre-trained responses and assert that the end result is
903
- * what we expect it to be.
904
- *
905
- * This mock implementation can be used to respond with static or dynamic responses via the
906
- * `expect` and `when` apis and their shortcuts (`expectGET`, `whenPOST`, etc).
907
- *
908
- * When an Angular application needs some data from a server, it calls the $http service, which
909
- * sends the request to a real server using $httpBackend service. With dependency injection, it is
910
- * easy to inject $httpBackend mock (which has the same API as $httpBackend) and use it to verify
911
- * the requests and respond with some testing data without sending a request to a real server.
912
- *
913
- * There are two ways to specify what test data should be returned as http responses by the mock
914
- * backend when the code under test makes http requests:
915
- *
916
- * - `$httpBackend.expect` - specifies a request expectation
917
- * - `$httpBackend.when` - specifies a backend definition
918
- *
919
- *
920
- * # Request Expectations vs Backend Definitions
921
- *
922
- * Request expectations provide a way to make assertions about requests made by the application and
923
- * to define responses for those requests. The test will fail if the expected requests are not made
924
- * or they are made in the wrong order.
925
- *
926
- * Backend definitions allow you to define a fake backend for your application which doesn't assert
927
- * if a particular request was made or not, it just returns a trained response if a request is made.
928
- * The test will pass whether or not the request gets made during testing.
929
- *
930
- *
931
- * <table class="table">
932
- * <tr><th width="220px"></th><th>Request expectations</th><th>Backend definitions</th></tr>
933
- * <tr>
934
- * <th>Syntax</th>
935
- * <td>.expect(...).respond(...)</td>
936
- * <td>.when(...).respond(...)</td>
937
- * </tr>
938
- * <tr>
939
- * <th>Typical usage</th>
940
- * <td>strict unit tests</td>
941
- * <td>loose (black-box) unit testing</td>
942
- * </tr>
943
- * <tr>
944
- * <th>Fulfills multiple requests</th>
945
- * <td>NO</td>
946
- * <td>YES</td>
947
- * </tr>
948
- * <tr>
949
- * <th>Order of requests matters</th>
950
- * <td>YES</td>
951
- * <td>NO</td>
952
- * </tr>
953
- * <tr>
954
- * <th>Request required</th>
955
- * <td>YES</td>
956
- * <td>NO</td>
957
- * </tr>
958
- * <tr>
959
- * <th>Response required</th>
960
- * <td>optional (see below)</td>
961
- * <td>YES</td>
962
- * </tr>
963
- * </table>
964
- *
965
- * In cases where both backend definitions and request expectations are specified during unit
966
- * testing, the request expectations are evaluated first.
967
- *
968
- * If a request expectation has no response specified, the algorithm will search your backend
969
- * definitions for an appropriate response.
970
- *
971
- * If a request didn't match any expectation or if the expectation doesn't have the response
972
- * defined, the backend definitions are evaluated in sequential order to see if any of them match
973
- * the request. The response from the first matched definition is returned.
974
- *
975
- *
976
- * # Flushing HTTP requests
977
- *
978
- * The $httpBackend used in production always responds to requests asynchronously. If we preserved
979
- * this behavior in unit testing, we'd have to create async unit tests, which are hard to write,
980
- * to follow and to maintain. But neither can the testing mock respond synchronously; that would
981
- * change the execution of the code under test. For this reason, the mock $httpBackend has a
982
- * `flush()` method, which allows the test to explicitly flush pending requests. This preserves
983
- * the async api of the backend, while allowing the test to execute synchronously.
984
- *
985
- *
986
- * # Unit testing with mock $httpBackend
987
- * The following code shows how to setup and use the mock backend when unit testing a controller.
988
- * First we create the controller under test:
989
- *
990
- ```js
991
- // The module code
992
- angular
993
- .module('MyApp', [])
994
- .controller('MyController', MyController);
995
-
996
- // The controller code
997
- function MyController($scope, $http) {
998
- var authToken;
999
-
1000
- $http.get('/auth.py').success(function(data, status, headers) {
1001
- authToken = headers('A-Token');
1002
- $scope.user = data;
1003
- });
1004
-
1005
- $scope.saveMessage = function(message) {
1006
- var headers = { 'Authorization': authToken };
1007
- $scope.status = 'Saving...';
1008
-
1009
- $http.post('/add-msg.py', message, { headers: headers } ).success(function(response) {
1010
- $scope.status = '';
1011
- }).error(function() {
1012
- $scope.status = 'ERROR!';
1013
- });
1014
- };
1015
- }
1016
- ```
1017
- *
1018
- * Now we setup the mock backend and create the test specs:
1019
- *
1020
- ```js
1021
- // testing controller
1022
- describe('MyController', function() {
1023
- var $httpBackend, $rootScope, createController, authRequestHandler;
1024
-
1025
- // Set up the module
1026
- beforeEach(module('MyApp'));
1027
-
1028
- beforeEach(inject(function($injector) {
1029
- // Set up the mock http service responses
1030
- $httpBackend = $injector.get('$httpBackend');
1031
- // backend definition common for all tests
1032
- authRequestHandler = $httpBackend.when('GET', '/auth.py')
1033
- .respond({userId: 'userX'}, {'A-Token': 'xxx'});
1034
-
1035
- // Get hold of a scope (i.e. the root scope)
1036
- $rootScope = $injector.get('$rootScope');
1037
- // The $controller service is used to create instances of controllers
1038
- var $controller = $injector.get('$controller');
1039
-
1040
- createController = function() {
1041
- return $controller('MyController', {'$scope' : $rootScope });
1042
- };
1043
- }));
1044
-
1045
-
1046
- afterEach(function() {
1047
- $httpBackend.verifyNoOutstandingExpectation();
1048
- $httpBackend.verifyNoOutstandingRequest();
1049
- });
1050
-
1051
-
1052
- it('should fetch authentication token', function() {
1053
- $httpBackend.expectGET('/auth.py');
1054
- var controller = createController();
1055
- $httpBackend.flush();
1056
- });
1057
-
1058
-
1059
- it('should fail authentication', function() {
1060
-
1061
- // Notice how you can change the response even after it was set
1062
- authRequestHandler.respond(401, '');
1063
-
1064
- $httpBackend.expectGET('/auth.py');
1065
- var controller = createController();
1066
- $httpBackend.flush();
1067
- expect($rootScope.status).toBe('Failed...');
1068
- });
1069
-
1070
-
1071
- it('should send msg to server', function() {
1072
- var controller = createController();
1073
- $httpBackend.flush();
1074
-
1075
- // now you don’t care about the authentication, but
1076
- // the controller will still send the request and
1077
- // $httpBackend will respond without you having to
1078
- // specify the expectation and response for this request
1079
-
1080
- $httpBackend.expectPOST('/add-msg.py', 'message content').respond(201, '');
1081
- $rootScope.saveMessage('message content');
1082
- expect($rootScope.status).toBe('Saving...');
1083
- $httpBackend.flush();
1084
- expect($rootScope.status).toBe('');
1085
- });
1086
-
1087
-
1088
- it('should send auth header', function() {
1089
- var controller = createController();
1090
- $httpBackend.flush();
1091
-
1092
- $httpBackend.expectPOST('/add-msg.py', undefined, function(headers) {
1093
- // check if the header was send, if it wasn't the expectation won't
1094
- // match the request and the test will fail
1095
- return headers['Authorization'] == 'xxx';
1096
- }).respond(201, '');
1097
-
1098
- $rootScope.saveMessage('whatever');
1099
- $httpBackend.flush();
1100
- });
1101
- });
1102
- ```
1103
- */
1104
- angular.mock.$HttpBackendProvider = function() {
1105
- this.$get = ['$rootScope', '$timeout', createHttpBackendMock];
1106
- };
1107
-
1108
- /**
1109
- * General factory function for $httpBackend mock.
1110
- * Returns instance for unit testing (when no arguments specified):
1111
- * - passing through is disabled
1112
- * - auto flushing is disabled
1113
- *
1114
- * Returns instance for e2e testing (when `$delegate` and `$browser` specified):
1115
- * - passing through (delegating request to real backend) is enabled
1116
- * - auto flushing is enabled
1117
- *
1118
- * @param {Object=} $delegate Real $httpBackend instance (allow passing through if specified)
1119
- * @param {Object=} $browser Auto-flushing enabled if specified
1120
- * @return {Object} Instance of $httpBackend mock
1121
- */
1122
- function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
1123
- var definitions = [],
1124
- expectations = [],
1125
- responses = [],
1126
- responsesPush = angular.bind(responses, responses.push),
1127
- copy = angular.copy;
1128
-
1129
- function createResponse(status, data, headers, statusText) {
1130
- if (angular.isFunction(status)) return status;
1131
-
1132
- return function() {
1133
- return angular.isNumber(status)
1134
- ? [status, data, headers, statusText]
1135
- : [200, status, data, headers];
1136
- };
1137
- }
1138
-
1139
- // TODO(vojta): change params to: method, url, data, headers, callback
1140
- function $httpBackend(method, url, data, callback, headers, timeout, withCredentials) {
1141
- var xhr = new MockXhr(),
1142
- expectation = expectations[0],
1143
- wasExpected = false;
1144
-
1145
- function prettyPrint(data) {
1146
- return (angular.isString(data) || angular.isFunction(data) || data instanceof RegExp)
1147
- ? data
1148
- : angular.toJson(data);
1149
- }
1150
-
1151
- function wrapResponse(wrapped) {
1152
- if (!$browser && timeout) {
1153
- timeout.then ? timeout.then(handleTimeout) : $timeout(handleTimeout, timeout);
1154
- }
1155
-
1156
- return handleResponse;
1157
-
1158
- function handleResponse() {
1159
- var response = wrapped.response(method, url, data, headers);
1160
- xhr.$$respHeaders = response[2];
1161
- callback(copy(response[0]), copy(response[1]), xhr.getAllResponseHeaders(),
1162
- copy(response[3] || ''));
1163
- }
1164
-
1165
- function handleTimeout() {
1166
- for (var i = 0, ii = responses.length; i < ii; i++) {
1167
- if (responses[i] === handleResponse) {
1168
- responses.splice(i, 1);
1169
- callback(-1, undefined, '');
1170
- break;
1171
- }
1172
- }
1173
- }
1174
- }
1175
-
1176
- if (expectation && expectation.match(method, url)) {
1177
- if (!expectation.matchData(data)) {
1178
- throw new Error('Expected ' + expectation + ' with different data\n' +
1179
- 'EXPECTED: ' + prettyPrint(expectation.data) + '\nGOT: ' + data);
1180
- }
1181
-
1182
- if (!expectation.matchHeaders(headers)) {
1183
- throw new Error('Expected ' + expectation + ' with different headers\n' +
1184
- 'EXPECTED: ' + prettyPrint(expectation.headers) + '\nGOT: ' +
1185
- prettyPrint(headers));
1186
- }
1187
-
1188
- expectations.shift();
1189
-
1190
- if (expectation.response) {
1191
- responses.push(wrapResponse(expectation));
1192
- return;
1193
- }
1194
- wasExpected = true;
1195
- }
1196
-
1197
- var i = -1, definition;
1198
- while ((definition = definitions[++i])) {
1199
- if (definition.match(method, url, data, headers || {})) {
1200
- if (definition.response) {
1201
- // if $browser specified, we do auto flush all requests
1202
- ($browser ? $browser.defer : responsesPush)(wrapResponse(definition));
1203
- } else if (definition.passThrough) {
1204
- $delegate(method, url, data, callback, headers, timeout, withCredentials);
1205
- } else throw new Error('No response defined !');
1206
- return;
1207
- }
1208
- }
1209
- throw wasExpected ?
1210
- new Error('No response defined !') :
1211
- new Error('Unexpected request: ' + method + ' ' + url + '\n' +
1212
- (expectation ? 'Expected ' + expectation : 'No more request expected'));
1213
- }
1214
-
1215
- /**
1216
- * @ngdoc method
1217
- * @name $httpBackend#when
1218
- * @description
1219
- * Creates a new backend definition.
1220
- *
1221
- * @param {string} method HTTP method.
1222
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1223
- * and returns true if the url matches the current definition.
1224
- * @param {(string|RegExp|function(string))=} data HTTP request body or function that receives
1225
- * data string and returns true if the data is as expected.
1226
- * @param {(Object|function(Object))=} headers HTTP headers or function that receives http header
1227
- * object and returns true if the headers match the current definition.
1228
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1229
- * request is handled. You can save this object for later use and invoke `respond` again in
1230
- * order to change how a matched request is handled.
1231
- *
1232
- * - respond –
1233
- * `{function([status,] data[, headers, statusText])
1234
- * | function(function(method, url, data, headers)}`
1235
- * – The respond method takes a set of static data to be returned or a function that can
1236
- * return an array containing response status (number), response data (string), response
1237
- * headers (Object), and the text for the status (string). The respond method returns the
1238
- * `requestHandler` object for possible overrides.
1239
- */
1240
- $httpBackend.when = function(method, url, data, headers) {
1241
- var definition = new MockHttpExpectation(method, url, data, headers),
1242
- chain = {
1243
- respond: function(status, data, headers, statusText) {
1244
- definition.passThrough = undefined;
1245
- definition.response = createResponse(status, data, headers, statusText);
1246
- return chain;
1247
- }
1248
- };
1249
-
1250
- if ($browser) {
1251
- chain.passThrough = function() {
1252
- definition.response = undefined;
1253
- definition.passThrough = true;
1254
- return chain;
1255
- };
1256
- }
1257
-
1258
- definitions.push(definition);
1259
- return chain;
1260
- };
1261
-
1262
- /**
1263
- * @ngdoc method
1264
- * @name $httpBackend#whenGET
1265
- * @description
1266
- * Creates a new backend definition for GET requests. For more info see `when()`.
1267
- *
1268
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1269
- * and returns true if the url matches the current definition.
1270
- * @param {(Object|function(Object))=} headers HTTP headers.
1271
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1272
- * request is handled. You can save this object for later use and invoke `respond` again in
1273
- * order to change how a matched request is handled.
1274
- */
1275
-
1276
- /**
1277
- * @ngdoc method
1278
- * @name $httpBackend#whenHEAD
1279
- * @description
1280
- * Creates a new backend definition for HEAD requests. For more info see `when()`.
1281
- *
1282
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1283
- * and returns true if the url matches the current definition.
1284
- * @param {(Object|function(Object))=} headers HTTP headers.
1285
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1286
- * request is handled. You can save this object for later use and invoke `respond` again in
1287
- * order to change how a matched request is handled.
1288
- */
1289
-
1290
- /**
1291
- * @ngdoc method
1292
- * @name $httpBackend#whenDELETE
1293
- * @description
1294
- * Creates a new backend definition for DELETE requests. For more info see `when()`.
1295
- *
1296
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1297
- * and returns true if the url matches the current definition.
1298
- * @param {(Object|function(Object))=} headers HTTP headers.
1299
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1300
- * request is handled. You can save this object for later use and invoke `respond` again in
1301
- * order to change how a matched request is handled.
1302
- */
1303
-
1304
- /**
1305
- * @ngdoc method
1306
- * @name $httpBackend#whenPOST
1307
- * @description
1308
- * Creates a new backend definition for POST requests. For more info see `when()`.
1309
- *
1310
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1311
- * and returns true if the url matches the current definition.
1312
- * @param {(string|RegExp|function(string))=} data HTTP request body or function that receives
1313
- * data string and returns true if the data is as expected.
1314
- * @param {(Object|function(Object))=} headers HTTP headers.
1315
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1316
- * request is handled. You can save this object for later use and invoke `respond` again in
1317
- * order to change how a matched request is handled.
1318
- */
1319
-
1320
- /**
1321
- * @ngdoc method
1322
- * @name $httpBackend#whenPUT
1323
- * @description
1324
- * Creates a new backend definition for PUT requests. For more info see `when()`.
1325
- *
1326
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1327
- * and returns true if the url matches the current definition.
1328
- * @param {(string|RegExp|function(string))=} data HTTP request body or function that receives
1329
- * data string and returns true if the data is as expected.
1330
- * @param {(Object|function(Object))=} headers HTTP headers.
1331
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1332
- * request is handled. You can save this object for later use and invoke `respond` again in
1333
- * order to change how a matched request is handled.
1334
- */
1335
-
1336
- /**
1337
- * @ngdoc method
1338
- * @name $httpBackend#whenJSONP
1339
- * @description
1340
- * Creates a new backend definition for JSONP requests. For more info see `when()`.
1341
- *
1342
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1343
- * and returns true if the url matches the current definition.
1344
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1345
- * request is handled. You can save this object for later use and invoke `respond` again in
1346
- * order to change how a matched request is handled.
1347
- */
1348
- createShortMethods('when');
1349
-
1350
-
1351
- /**
1352
- * @ngdoc method
1353
- * @name $httpBackend#expect
1354
- * @description
1355
- * Creates a new request expectation.
1356
- *
1357
- * @param {string} method HTTP method.
1358
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1359
- * and returns true if the url matches the current definition.
1360
- * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that
1361
- * receives data string and returns true if the data is as expected, or Object if request body
1362
- * is in JSON format.
1363
- * @param {(Object|function(Object))=} headers HTTP headers or function that receives http header
1364
- * object and returns true if the headers match the current expectation.
1365
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1366
- * request is handled. You can save this object for later use and invoke `respond` again in
1367
- * order to change how a matched request is handled.
1368
- *
1369
- * - respond –
1370
- * `{function([status,] data[, headers, statusText])
1371
- * | function(function(method, url, data, headers)}`
1372
- * – The respond method takes a set of static data to be returned or a function that can
1373
- * return an array containing response status (number), response data (string), response
1374
- * headers (Object), and the text for the status (string). The respond method returns the
1375
- * `requestHandler` object for possible overrides.
1376
- */
1377
- $httpBackend.expect = function(method, url, data, headers) {
1378
- var expectation = new MockHttpExpectation(method, url, data, headers),
1379
- chain = {
1380
- respond: function(status, data, headers, statusText) {
1381
- expectation.response = createResponse(status, data, headers, statusText);
1382
- return chain;
1383
- }
1384
- };
1385
-
1386
- expectations.push(expectation);
1387
- return chain;
1388
- };
1389
-
1390
-
1391
- /**
1392
- * @ngdoc method
1393
- * @name $httpBackend#expectGET
1394
- * @description
1395
- * Creates a new request expectation for GET requests. For more info see `expect()`.
1396
- *
1397
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1398
- * and returns true if the url matches the current definition.
1399
- * @param {Object=} headers HTTP headers.
1400
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1401
- * request is handled. You can save this object for later use and invoke `respond` again in
1402
- * order to change how a matched request is handled. See #expect for more info.
1403
- */
1404
-
1405
- /**
1406
- * @ngdoc method
1407
- * @name $httpBackend#expectHEAD
1408
- * @description
1409
- * Creates a new request expectation for HEAD requests. For more info see `expect()`.
1410
- *
1411
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1412
- * and returns true if the url matches the current definition.
1413
- * @param {Object=} headers HTTP headers.
1414
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1415
- * request is handled. You can save this object for later use and invoke `respond` again in
1416
- * order to change how a matched request is handled.
1417
- */
1418
-
1419
- /**
1420
- * @ngdoc method
1421
- * @name $httpBackend#expectDELETE
1422
- * @description
1423
- * Creates a new request expectation for DELETE requests. For more info see `expect()`.
1424
- *
1425
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1426
- * and returns true if the url matches the current definition.
1427
- * @param {Object=} headers HTTP headers.
1428
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1429
- * request is handled. You can save this object for later use and invoke `respond` again in
1430
- * order to change how a matched request is handled.
1431
- */
1432
-
1433
- /**
1434
- * @ngdoc method
1435
- * @name $httpBackend#expectPOST
1436
- * @description
1437
- * Creates a new request expectation for POST requests. For more info see `expect()`.
1438
- *
1439
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1440
- * and returns true if the url matches the current definition.
1441
- * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that
1442
- * receives data string and returns true if the data is as expected, or Object if request body
1443
- * is in JSON format.
1444
- * @param {Object=} headers HTTP headers.
1445
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1446
- * request is handled. You can save this object for later use and invoke `respond` again in
1447
- * order to change how a matched request is handled.
1448
- */
1449
-
1450
- /**
1451
- * @ngdoc method
1452
- * @name $httpBackend#expectPUT
1453
- * @description
1454
- * Creates a new request expectation for PUT requests. For more info see `expect()`.
1455
- *
1456
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1457
- * and returns true if the url matches the current definition.
1458
- * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that
1459
- * receives data string and returns true if the data is as expected, or Object if request body
1460
- * is in JSON format.
1461
- * @param {Object=} headers HTTP headers.
1462
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1463
- * request is handled. You can save this object for later use and invoke `respond` again in
1464
- * order to change how a matched request is handled.
1465
- */
1466
-
1467
- /**
1468
- * @ngdoc method
1469
- * @name $httpBackend#expectPATCH
1470
- * @description
1471
- * Creates a new request expectation for PATCH requests. For more info see `expect()`.
1472
- *
1473
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1474
- * and returns true if the url matches the current definition.
1475
- * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that
1476
- * receives data string and returns true if the data is as expected, or Object if request body
1477
- * is in JSON format.
1478
- * @param {Object=} headers HTTP headers.
1479
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1480
- * request is handled. You can save this object for later use and invoke `respond` again in
1481
- * order to change how a matched request is handled.
1482
- */
1483
-
1484
- /**
1485
- * @ngdoc method
1486
- * @name $httpBackend#expectJSONP
1487
- * @description
1488
- * Creates a new request expectation for JSONP requests. For more info see `expect()`.
1489
- *
1490
- * @param {string|RegExp|function(string)} url HTTP url or function that receives an url
1491
- * and returns true if the url matches the current definition.
1492
- * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1493
- * request is handled. You can save this object for later use and invoke `respond` again in
1494
- * order to change how a matched request is handled.
1495
- */
1496
- createShortMethods('expect');
1497
-
1498
-
1499
- /**
1500
- * @ngdoc method
1501
- * @name $httpBackend#flush
1502
- * @description
1503
- * Flushes all pending requests using the trained responses.
1504
- *
1505
- * @param {number=} count Number of responses to flush (in the order they arrived). If undefined,
1506
- * all pending requests will be flushed. If there are no pending requests when the flush method
1507
- * is called an exception is thrown (as this typically a sign of programming error).
1508
- */
1509
- $httpBackend.flush = function(count, digest) {
1510
- if (digest !== false) $rootScope.$digest();
1511
- if (!responses.length) throw new Error('No pending request to flush !');
1512
-
1513
- if (angular.isDefined(count) && count !== null) {
1514
- while (count--) {
1515
- if (!responses.length) throw new Error('No more pending request to flush !');
1516
- responses.shift()();
1517
- }
1518
- } else {
1519
- while (responses.length) {
1520
- responses.shift()();
1521
- }
1522
- }
1523
- $httpBackend.verifyNoOutstandingExpectation(digest);
1524
- };
1525
-
1526
-
1527
- /**
1528
- * @ngdoc method
1529
- * @name $httpBackend#verifyNoOutstandingExpectation
1530
- * @description
1531
- * Verifies that all of the requests defined via the `expect` api were made. If any of the
1532
- * requests were not made, verifyNoOutstandingExpectation throws an exception.
1533
- *
1534
- * Typically, you would call this method following each test case that asserts requests using an
1535
- * "afterEach" clause.
1536
- *
1537
- * ```js
1538
- * afterEach($httpBackend.verifyNoOutstandingExpectation);
1539
- * ```
1540
- */
1541
- $httpBackend.verifyNoOutstandingExpectation = function(digest) {
1542
- if (digest !== false) $rootScope.$digest();
1543
- if (expectations.length) {
1544
- throw new Error('Unsatisfied requests: ' + expectations.join(', '));
1545
- }
1546
- };
1547
-
1548
-
1549
- /**
1550
- * @ngdoc method
1551
- * @name $httpBackend#verifyNoOutstandingRequest
1552
- * @description
1553
- * Verifies that there are no outstanding requests that need to be flushed.
1554
- *
1555
- * Typically, you would call this method following each test case that asserts requests using an
1556
- * "afterEach" clause.
1557
- *
1558
- * ```js
1559
- * afterEach($httpBackend.verifyNoOutstandingRequest);
1560
- * ```
1561
- */
1562
- $httpBackend.verifyNoOutstandingRequest = function() {
1563
- if (responses.length) {
1564
- throw new Error('Unflushed requests: ' + responses.length);
1565
- }
1566
- };
1567
-
1568
-
1569
- /**
1570
- * @ngdoc method
1571
- * @name $httpBackend#resetExpectations
1572
- * @description
1573
- * Resets all request expectations, but preserves all backend definitions. Typically, you would
1574
- * call resetExpectations during a multiple-phase test when you want to reuse the same instance of
1575
- * $httpBackend mock.
1576
- */
1577
- $httpBackend.resetExpectations = function() {
1578
- expectations.length = 0;
1579
- responses.length = 0;
1580
- };
1581
-
1582
- return $httpBackend;
1583
-
1584
-
1585
- function createShortMethods(prefix) {
1586
- angular.forEach(['GET', 'DELETE', 'JSONP', 'HEAD'], function(method) {
1587
- $httpBackend[prefix + method] = function(url, headers) {
1588
- return $httpBackend[prefix](method, url, undefined, headers);
1589
- };
1590
- });
1591
-
1592
- angular.forEach(['PUT', 'POST', 'PATCH'], function(method) {
1593
- $httpBackend[prefix + method] = function(url, data, headers) {
1594
- return $httpBackend[prefix](method, url, data, headers);
1595
- };
1596
- });
1597
- }
1598
- }
1599
-
1600
- function MockHttpExpectation(method, url, data, headers) {
1601
-
1602
- this.data = data;
1603
- this.headers = headers;
1604
-
1605
- this.match = function(m, u, d, h) {
1606
- if (method != m) return false;
1607
- if (!this.matchUrl(u)) return false;
1608
- if (angular.isDefined(d) && !this.matchData(d)) return false;
1609
- if (angular.isDefined(h) && !this.matchHeaders(h)) return false;
1610
- return true;
1611
- };
1612
-
1613
- this.matchUrl = function(u) {
1614
- if (!url) return true;
1615
- if (angular.isFunction(url.test)) return url.test(u);
1616
- if (angular.isFunction(url)) return url(u);
1617
- return url == u;
1618
- };
1619
-
1620
- this.matchHeaders = function(h) {
1621
- if (angular.isUndefined(headers)) return true;
1622
- if (angular.isFunction(headers)) return headers(h);
1623
- return angular.equals(headers, h);
1624
- };
1625
-
1626
- this.matchData = function(d) {
1627
- if (angular.isUndefined(data)) return true;
1628
- if (data && angular.isFunction(data.test)) return data.test(d);
1629
- if (data && angular.isFunction(data)) return data(d);
1630
- if (data && !angular.isString(data)) {
1631
- return angular.equals(angular.fromJson(angular.toJson(data)), angular.fromJson(d));
1632
- }
1633
- return data == d;
1634
- };
1635
-
1636
- this.toString = function() {
1637
- return method + ' ' + url;
1638
- };
1639
- }
1640
-
1641
- function createMockXhr() {
1642
- return new MockXhr();
1643
- }
1644
-
1645
- function MockXhr() {
1646
-
1647
- // hack for testing $http, $httpBackend
1648
- MockXhr.$$lastInstance = this;
1649
-
1650
- this.open = function(method, url, async) {
1651
- this.$$method = method;
1652
- this.$$url = url;
1653
- this.$$async = async;
1654
- this.$$reqHeaders = {};
1655
- this.$$respHeaders = {};
1656
- };
1657
-
1658
- this.send = function(data) {
1659
- this.$$data = data;
1660
- };
1661
-
1662
- this.setRequestHeader = function(key, value) {
1663
- this.$$reqHeaders[key] = value;
1664
- };
1665
-
1666
- this.getResponseHeader = function(name) {
1667
- // the lookup must be case insensitive,
1668
- // that's why we try two quick lookups first and full scan last
1669
- var header = this.$$respHeaders[name];
1670
- if (header) return header;
1671
-
1672
- name = angular.lowercase(name);
1673
- header = this.$$respHeaders[name];
1674
- if (header) return header;
1675
-
1676
- header = undefined;
1677
- angular.forEach(this.$$respHeaders, function(headerVal, headerName) {
1678
- if (!header && angular.lowercase(headerName) == name) header = headerVal;
1679
- });
1680
- return header;
1681
- };
1682
-
1683
- this.getAllResponseHeaders = function() {
1684
- var lines = [];
1685
-
1686
- angular.forEach(this.$$respHeaders, function(value, key) {
1687
- lines.push(key + ': ' + value);
1688
- });
1689
- return lines.join('\n');
1690
- };
1691
-
1692
- this.abort = angular.noop;
1693
- }
1694
-
1695
-
1696
- /**
1697
- * @ngdoc service
1698
- * @name $timeout
1699
- * @description
1700
- *
1701
- * This service is just a simple decorator for {@link ng.$timeout $timeout} service
1702
- * that adds a "flush" and "verifyNoPendingTasks" methods.
1703
- */
1704
-
1705
- angular.mock.$TimeoutDecorator = ['$delegate', '$browser', function($delegate, $browser) {
1706
-
1707
- /**
1708
- * @ngdoc method
1709
- * @name $timeout#flush
1710
- * @description
1711
- *
1712
- * Flushes the queue of pending tasks.
1713
- *
1714
- * @param {number=} delay maximum timeout amount to flush up until
1715
- */
1716
- $delegate.flush = function(delay) {
1717
- $browser.defer.flush(delay);
1718
- };
1719
-
1720
- /**
1721
- * @ngdoc method
1722
- * @name $timeout#verifyNoPendingTasks
1723
- * @description
1724
- *
1725
- * Verifies that there are no pending tasks that need to be flushed.
1726
- */
1727
- $delegate.verifyNoPendingTasks = function() {
1728
- if ($browser.deferredFns.length) {
1729
- throw new Error('Deferred tasks to flush (' + $browser.deferredFns.length + '): ' +
1730
- formatPendingTasksAsString($browser.deferredFns));
1731
- }
1732
- };
1733
-
1734
- function formatPendingTasksAsString(tasks) {
1735
- var result = [];
1736
- angular.forEach(tasks, function(task) {
1737
- result.push('{id: ' + task.id + ', ' + 'time: ' + task.time + '}');
1738
- });
1739
-
1740
- return result.join(', ');
1741
- }
1742
-
1743
- return $delegate;
1744
- }];
1745
-
1746
- angular.mock.$RAFDecorator = ['$delegate', function($delegate) {
1747
- var queue = [];
1748
- var rafFn = function(fn) {
1749
- var index = queue.length;
1750
- queue.push(fn);
1751
- return function() {
1752
- queue.splice(index, 1);
1753
- };
1754
- };
1755
-
1756
- rafFn.supported = $delegate.supported;
1757
-
1758
- rafFn.flush = function() {
1759
- if (queue.length === 0) {
1760
- throw new Error('No rAF callbacks present');
1761
- }
1762
-
1763
- var length = queue.length;
1764
- for (var i = 0; i < length; i++) {
1765
- queue[i]();
1766
- }
1767
-
1768
- queue = queue.slice(i);
1769
- };
1770
-
1771
- return rafFn;
1772
- }];
1773
-
1774
- angular.mock.$AsyncCallbackDecorator = ['$delegate', function($delegate) {
1775
- var callbacks = [];
1776
- var addFn = function(fn) {
1777
- callbacks.push(fn);
1778
- };
1779
- addFn.flush = function() {
1780
- angular.forEach(callbacks, function(fn) {
1781
- fn();
1782
- });
1783
- callbacks = [];
1784
- };
1785
- return addFn;
1786
- }];
1787
-
1788
- /**
1789
- *
1790
- */
1791
- angular.mock.$RootElementProvider = function() {
1792
- this.$get = function() {
1793
- return angular.element('<div ng-app></div>');
1794
- };
1795
- };
1796
-
1797
- /**
1798
- * @ngdoc service
1799
- * @name $controller
1800
- * @description
1801
- * A decorator for {@link ng.$controller} with additional `bindings` parameter, useful when testing
1802
- * controllers of directives that use {@link $compile#-bindtocontroller- `bindToController`}.
1803
- *
1804
- *
1805
- * ## Example
1806
- *
1807
- * ```js
1808
- *
1809
- * // Directive definition ...
1810
- *
1811
- * myMod.directive('myDirective', {
1812
- * controller: 'MyDirectiveController',
1813
- * bindToController: {
1814
- * name: '@'
1815
- * }
1816
- * });
1817
- *
1818
- *
1819
- * // Controller definition ...
1820
- *
1821
- * myMod.controller('MyDirectiveController', ['log', function($log) {
1822
- * $log.info(this.name);
1823
- * })];
1824
- *
1825
- *
1826
- * // In a test ...
1827
- *
1828
- * describe('myDirectiveController', function() {
1829
- * it('should write the bound name to the log', inject(function($controller, $log) {
1830
- * var ctrl = $controller('MyDirective', { /* no locals &#42;/ }, { name: 'Clark Kent' });
1831
- * expect(ctrl.name).toEqual('Clark Kent');
1832
- * expect($log.info.logs).toEqual(['Clark Kent']);
1833
- * });
1834
- * });
1835
- *
1836
- * ```
1837
- *
1838
- * @param {Function|string} constructor If called with a function then it's considered to be the
1839
- * controller constructor function. Otherwise it's considered to be a string which is used
1840
- * to retrieve the controller constructor using the following steps:
1841
- *
1842
- * * check if a controller with given name is registered via `$controllerProvider`
1843
- * * check if evaluating the string on the current scope returns a constructor
1844
- * * if $controllerProvider#allowGlobals, check `window[constructor]` on the global
1845
- * `window` object (not recommended)
1846
- *
1847
- * The string can use the `controller as property` syntax, where the controller instance is published
1848
- * as the specified property on the `scope`; the `scope` must be injected into `locals` param for this
1849
- * to work correctly.
1850
- *
1851
- * @param {Object} locals Injection locals for Controller.
1852
- * @param {Object=} bindings Properties to add to the controller before invoking the constructor. This is used
1853
- * to simulate the `bindToController` feature and simplify certain kinds of tests.
1854
- * @return {Object} Instance of given controller.
1855
- */
1856
- angular.mock.$ControllerDecorator = ['$delegate', function($delegate) {
1857
- return function(expression, locals, later, ident) {
1858
- if (later && typeof later === 'object') {
1859
- var create = $delegate(expression, locals, true, ident);
1860
- angular.extend(create.instance, later);
1861
- return create();
1862
- }
1863
- return $delegate(expression, locals, later, ident);
1864
- };
1865
- }];
1866
-
1867
-
1868
- /**
1869
- * @ngdoc module
1870
- * @name ngMock
1871
- * @packageName angular-mocks
1872
- * @description
1873
- *
1874
- * # ngMock
1875
- *
1876
- * The `ngMock` module provides support to inject and mock Angular services into unit tests.
1877
- * In addition, ngMock also extends various core ng services such that they can be
1878
- * inspected and controlled in a synchronous manner within test code.
1879
- *
1880
- *
1881
- * <div doc-module-components="ngMock"></div>
1882
- *
1883
- */
1884
- angular.module('ngMock', ['ng']).provider({
1885
- $browser: angular.mock.$BrowserProvider,
1886
- $exceptionHandler: angular.mock.$ExceptionHandlerProvider,
1887
- $log: angular.mock.$LogProvider,
1888
- $interval: angular.mock.$IntervalProvider,
1889
- $httpBackend: angular.mock.$HttpBackendProvider,
1890
- $rootElement: angular.mock.$RootElementProvider
1891
- }).config(['$provide', function($provide) {
1892
- $provide.decorator('$timeout', angular.mock.$TimeoutDecorator);
1893
- $provide.decorator('$$rAF', angular.mock.$RAFDecorator);
1894
- $provide.decorator('$$asyncCallback', angular.mock.$AsyncCallbackDecorator);
1895
- $provide.decorator('$rootScope', angular.mock.$RootScopeDecorator);
1896
- $provide.decorator('$controller', angular.mock.$ControllerDecorator);
1897
- }]);
1898
-
1899
- /**
1900
- * @ngdoc module
1901
- * @name ngMockE2E
1902
- * @module ngMockE2E
1903
- * @packageName angular-mocks
1904
- * @description
1905
- *
1906
- * The `ngMockE2E` is an angular module which contains mocks suitable for end-to-end testing.
1907
- * Currently there is only one mock present in this module -
1908
- * the {@link ngMockE2E.$httpBackend e2e $httpBackend} mock.
1909
- */
1910
- angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
1911
- $provide.decorator('$httpBackend', angular.mock.e2e.$httpBackendDecorator);
1912
- }]);
1913
-
1914
- /**
1915
- * @ngdoc service
1916
- * @name $httpBackend
1917
- * @module ngMockE2E
1918
- * @description
1919
- * Fake HTTP backend implementation suitable for end-to-end testing or backend-less development of
1920
- * applications that use the {@link ng.$http $http service}.
1921
- *
1922
- * *Note*: For fake http backend implementation suitable for unit testing please see
1923
- * {@link ngMock.$httpBackend unit-testing $httpBackend mock}.
1924
- *
1925
- * This implementation can be used to respond with static or dynamic responses via the `when` api
1926
- * and its shortcuts (`whenGET`, `whenPOST`, etc) and optionally pass through requests to the
1927
- * real $httpBackend for specific requests (e.g. to interact with certain remote apis or to fetch
1928
- * templates from a webserver).
1929
- *
1930
- * As opposed to unit-testing, in an end-to-end testing scenario or in scenario when an application
1931
- * is being developed with the real backend api replaced with a mock, it is often desirable for
1932
- * certain category of requests to bypass the mock and issue a real http request (e.g. to fetch
1933
- * templates or static files from the webserver). To configure the backend with this behavior
1934
- * use the `passThrough` request handler of `when` instead of `respond`.
1935
- *
1936
- * Additionally, we don't want to manually have to flush mocked out requests like we do during unit
1937
- * testing. For this reason the e2e $httpBackend flushes mocked out requests
1938
- * automatically, closely simulating the behavior of the XMLHttpRequest object.
1939
- *
1940
- * To setup the application to run with this http backend, you have to create a module that depends
1941
- * on the `ngMockE2E` and your application modules and defines the fake backend:
1942
- *
1943
- * ```js
1944
- * myAppDev = angular.module('myAppDev', ['myApp', 'ngMockE2E']);
1945
- * myAppDev.run(function($httpBackend) {
1946
- * phones = [{name: 'phone1'}, {name: 'phone2'}];
1947
- *
1948
- * // returns the current list of phones
1949
- * $httpBackend.whenGET('/phones').respond(phones);
1950
- *
1951
- * // adds a new phone to the phones array
1952
- * $httpBackend.whenPOST('/phones').respond(function(method, url, data) {
1953
- * var phone = angular.fromJson(data);
1954
- * phones.push(phone);
1955
- * return [200, phone, {}];
1956
- * });
1957
- * $httpBackend.whenGET(/^\/templates\//).passThrough();
1958
- * //...
1959
- * });
1960
- * ```
1961
- *
1962
- * Afterwards, bootstrap your app with this new module.
1963
- */
1964
-
1965
- /**
1966
- * @ngdoc method
1967
- * @name $httpBackend#when
1968
- * @module ngMockE2E
1969
- * @description
1970
- * Creates a new backend definition.
1971
- *
1972
- * @param {string} method HTTP method.
1973
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
1974
- * and returns true if the url matches the current definition.
1975
- * @param {(string|RegExp)=} data HTTP request body.
1976
- * @param {(Object|function(Object))=} headers HTTP headers or function that receives http header
1977
- * object and returns true if the headers match the current definition.
1978
- * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1979
- * control how a matched request is handled. You can save this object for later use and invoke
1980
- * `respond` or `passThrough` again in order to change how a matched request is handled.
1981
- *
1982
- * - respond –
1983
- * `{function([status,] data[, headers, statusText])
1984
- * | function(function(method, url, data, headers)}`
1985
- * – The respond method takes a set of static data to be returned or a function that can return
1986
- * an array containing response status (number), response data (string), response headers
1987
- * (Object), and the text for the status (string).
1988
- * - passThrough – `{function()}` – Any request matching a backend definition with
1989
- * `passThrough` handler will be passed through to the real backend (an XHR request will be made
1990
- * to the server.)
1991
- * - Both methods return the `requestHandler` object for possible overrides.
1992
- */
1993
-
1994
- /**
1995
- * @ngdoc method
1996
- * @name $httpBackend#whenGET
1997
- * @module ngMockE2E
1998
- * @description
1999
- * Creates a new backend definition for GET requests. For more info see `when()`.
2000
- *
2001
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
2002
- * and returns true if the url matches the current definition.
2003
- * @param {(Object|function(Object))=} headers HTTP headers.
2004
- * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
2005
- * control how a matched request is handled. You can save this object for later use and invoke
2006
- * `respond` or `passThrough` again in order to change how a matched request is handled.
2007
- */
2008
-
2009
- /**
2010
- * @ngdoc method
2011
- * @name $httpBackend#whenHEAD
2012
- * @module ngMockE2E
2013
- * @description
2014
- * Creates a new backend definition for HEAD requests. For more info see `when()`.
2015
- *
2016
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
2017
- * and returns true if the url matches the current definition.
2018
- * @param {(Object|function(Object))=} headers HTTP headers.
2019
- * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
2020
- * control how a matched request is handled. You can save this object for later use and invoke
2021
- * `respond` or `passThrough` again in order to change how a matched request is handled.
2022
- */
2023
-
2024
- /**
2025
- * @ngdoc method
2026
- * @name $httpBackend#whenDELETE
2027
- * @module ngMockE2E
2028
- * @description
2029
- * Creates a new backend definition for DELETE requests. For more info see `when()`.
2030
- *
2031
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
2032
- * and returns true if the url matches the current definition.
2033
- * @param {(Object|function(Object))=} headers HTTP headers.
2034
- * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
2035
- * control how a matched request is handled. You can save this object for later use and invoke
2036
- * `respond` or `passThrough` again in order to change how a matched request is handled.
2037
- */
2038
-
2039
- /**
2040
- * @ngdoc method
2041
- * @name $httpBackend#whenPOST
2042
- * @module ngMockE2E
2043
- * @description
2044
- * Creates a new backend definition for POST requests. For more info see `when()`.
2045
- *
2046
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
2047
- * and returns true if the url matches the current definition.
2048
- * @param {(string|RegExp)=} data HTTP request body.
2049
- * @param {(Object|function(Object))=} headers HTTP headers.
2050
- * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
2051
- * control how a matched request is handled. You can save this object for later use and invoke
2052
- * `respond` or `passThrough` again in order to change how a matched request is handled.
2053
- */
2054
-
2055
- /**
2056
- * @ngdoc method
2057
- * @name $httpBackend#whenPUT
2058
- * @module ngMockE2E
2059
- * @description
2060
- * Creates a new backend definition for PUT requests. For more info see `when()`.
2061
- *
2062
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
2063
- * and returns true if the url matches the current definition.
2064
- * @param {(string|RegExp)=} data HTTP request body.
2065
- * @param {(Object|function(Object))=} headers HTTP headers.
2066
- * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
2067
- * control how a matched request is handled. You can save this object for later use and invoke
2068
- * `respond` or `passThrough` again in order to change how a matched request is handled.
2069
- */
2070
-
2071
- /**
2072
- * @ngdoc method
2073
- * @name $httpBackend#whenPATCH
2074
- * @module ngMockE2E
2075
- * @description
2076
- * Creates a new backend definition for PATCH requests. For more info see `when()`.
2077
- *
2078
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
2079
- * and returns true if the url matches the current definition.
2080
- * @param {(string|RegExp)=} data HTTP request body.
2081
- * @param {(Object|function(Object))=} headers HTTP headers.
2082
- * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
2083
- * control how a matched request is handled. You can save this object for later use and invoke
2084
- * `respond` or `passThrough` again in order to change how a matched request is handled.
2085
- */
2086
-
2087
- /**
2088
- * @ngdoc method
2089
- * @name $httpBackend#whenJSONP
2090
- * @module ngMockE2E
2091
- * @description
2092
- * Creates a new backend definition for JSONP requests. For more info see `when()`.
2093
- *
2094
- * @param {string|RegExp|function(string)} url HTTP url or function that receives a url
2095
- * and returns true if the url matches the current definition.
2096
- * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
2097
- * control how a matched request is handled. You can save this object for later use and invoke
2098
- * `respond` or `passThrough` again in order to change how a matched request is handled.
2099
- */
2100
- angular.mock.e2e = {};
2101
- angular.mock.e2e.$httpBackendDecorator =
2102
- ['$rootScope', '$timeout', '$delegate', '$browser', createHttpBackendMock];
2103
-
2104
-
2105
- /**
2106
- * @ngdoc type
2107
- * @name $rootScope.Scope
2108
- * @module ngMock
2109
- * @description
2110
- * {@link ng.$rootScope.Scope Scope} type decorated with helper methods useful for testing. These
2111
- * methods are automatically available on any {@link ng.$rootScope.Scope Scope} instance when
2112
- * `ngMock` module is loaded.
2113
- *
2114
- * In addition to all the regular `Scope` methods, the following helper methods are available:
2115
- */
2116
- angular.mock.$RootScopeDecorator = ['$delegate', function($delegate) {
2117
-
2118
- var $rootScopePrototype = Object.getPrototypeOf($delegate);
2119
-
2120
- $rootScopePrototype.$countChildScopes = countChildScopes;
2121
- $rootScopePrototype.$countWatchers = countWatchers;
2122
-
2123
- return $delegate;
2124
-
2125
- // ------------------------------------------------------------------------------------------ //
2126
-
2127
- /**
2128
- * @ngdoc method
2129
- * @name $rootScope.Scope#$countChildScopes
2130
- * @module ngMock
2131
- * @description
2132
- * Counts all the direct and indirect child scopes of the current scope.
2133
- *
2134
- * The current scope is excluded from the count. The count includes all isolate child scopes.
2135
- *
2136
- * @returns {number} Total number of child scopes.
2137
- */
2138
- function countChildScopes() {
2139
- // jshint validthis: true
2140
- var count = 0; // exclude the current scope
2141
- var pendingChildHeads = [this.$$childHead];
2142
- var currentScope;
2143
-
2144
- while (pendingChildHeads.length) {
2145
- currentScope = pendingChildHeads.shift();
2146
-
2147
- while (currentScope) {
2148
- count += 1;
2149
- pendingChildHeads.push(currentScope.$$childHead);
2150
- currentScope = currentScope.$$nextSibling;
2151
- }
2152
- }
2153
-
2154
- return count;
2155
- }
2156
-
2157
-
2158
- /**
2159
- * @ngdoc method
2160
- * @name $rootScope.Scope#$countWatchers
2161
- * @module ngMock
2162
- * @description
2163
- * Counts all the watchers of direct and indirect child scopes of the current scope.
2164
- *
2165
- * The watchers of the current scope are included in the count and so are all the watchers of
2166
- * isolate child scopes.
2167
- *
2168
- * @returns {number} Total number of watchers.
2169
- */
2170
- function countWatchers() {
2171
- // jshint validthis: true
2172
- var count = this.$$watchers ? this.$$watchers.length : 0; // include the current scope
2173
- var pendingChildHeads = [this.$$childHead];
2174
- var currentScope;
2175
-
2176
- while (pendingChildHeads.length) {
2177
- currentScope = pendingChildHeads.shift();
2178
-
2179
- while (currentScope) {
2180
- count += currentScope.$$watchers ? currentScope.$$watchers.length : 0;
2181
- pendingChildHeads.push(currentScope.$$childHead);
2182
- currentScope = currentScope.$$nextSibling;
2183
- }
2184
- }
2185
-
2186
- return count;
2187
- }
2188
- }];
2189
-
2190
-
2191
- if (window.jasmine || window.mocha) {
2192
-
2193
- var currentSpec = null,
2194
- annotatedFunctions = [],
2195
- isSpecRunning = function() {
2196
- return !!currentSpec;
2197
- };
2198
-
2199
- angular.mock.$$annotate = angular.injector.$$annotate;
2200
- angular.injector.$$annotate = function(fn) {
2201
- if (typeof fn === 'function' && !fn.$inject) {
2202
- annotatedFunctions.push(fn);
2203
- }
2204
- return angular.mock.$$annotate.apply(this, arguments);
2205
- };
2206
-
2207
-
2208
- (window.beforeEach || window.setup)(function() {
2209
- annotatedFunctions = [];
2210
- currentSpec = this;
2211
- });
2212
-
2213
- (window.afterEach || window.teardown)(function() {
2214
- var injector = currentSpec.$injector;
2215
-
2216
- annotatedFunctions.forEach(function(fn) {
2217
- delete fn.$inject;
2218
- });
2219
-
2220
- angular.forEach(currentSpec.$modules, function(module) {
2221
- if (module && module.$$hashKey) {
2222
- module.$$hashKey = undefined;
2223
- }
2224
- });
2225
-
2226
- currentSpec.$injector = null;
2227
- currentSpec.$modules = null;
2228
- currentSpec = null;
2229
-
2230
- if (injector) {
2231
- injector.get('$rootElement').off();
2232
- }
2233
-
2234
- // clean up jquery's fragment cache
2235
- angular.forEach(angular.element.fragments, function(val, key) {
2236
- delete angular.element.fragments[key];
2237
- });
2238
-
2239
- MockXhr.$$lastInstance = null;
2240
-
2241
- angular.forEach(angular.callbacks, function(val, key) {
2242
- delete angular.callbacks[key];
2243
- });
2244
- angular.callbacks.counter = 0;
2245
- });
2246
-
2247
- /**
2248
- * @ngdoc function
2249
- * @name angular.mock.module
2250
- * @description
2251
- *
2252
- * *NOTE*: This function is also published on window for easy access.<br>
2253
- * *NOTE*: This function is declared ONLY WHEN running tests with jasmine or mocha
2254
- *
2255
- * This function registers a module configuration code. It collects the configuration information
2256
- * which will be used when the injector is created by {@link angular.mock.inject inject}.
2257
- *
2258
- * See {@link angular.mock.inject inject} for usage example
2259
- *
2260
- * @param {...(string|Function|Object)} fns any number of modules which are represented as string
2261
- * aliases or as anonymous module initialization functions. The modules are used to
2262
- * configure the injector. The 'ng' and 'ngMock' modules are automatically loaded. If an
2263
- * object literal is passed they will be registered as values in the module, the key being
2264
- * the module name and the value being what is returned.
2265
- */
2266
- window.module = angular.mock.module = function() {
2267
- var moduleFns = Array.prototype.slice.call(arguments, 0);
2268
- return isSpecRunning() ? workFn() : workFn;
2269
- /////////////////////
2270
- function workFn() {
2271
- if (currentSpec.$injector) {
2272
- throw new Error('Injector already created, can not register a module!');
2273
- } else {
2274
- var modules = currentSpec.$modules || (currentSpec.$modules = []);
2275
- angular.forEach(moduleFns, function(module) {
2276
- if (angular.isObject(module) && !angular.isArray(module)) {
2277
- modules.push(function($provide) {
2278
- angular.forEach(module, function(value, key) {
2279
- $provide.value(key, value);
2280
- });
2281
- });
2282
- } else {
2283
- modules.push(module);
2284
- }
2285
- });
2286
- }
2287
- }
2288
- };
2289
-
2290
- /**
2291
- * @ngdoc function
2292
- * @name angular.mock.inject
2293
- * @description
2294
- *
2295
- * *NOTE*: This function is also published on window for easy access.<br>
2296
- * *NOTE*: This function is declared ONLY WHEN running tests with jasmine or mocha
2297
- *
2298
- * The inject function wraps a function into an injectable function. The inject() creates new
2299
- * instance of {@link auto.$injector $injector} per test, which is then used for
2300
- * resolving references.
2301
- *
2302
- *
2303
- * ## Resolving References (Underscore Wrapping)
2304
- * Often, we would like to inject a reference once, in a `beforeEach()` block and reuse this
2305
- * in multiple `it()` clauses. To be able to do this we must assign the reference to a variable
2306
- * that is declared in the scope of the `describe()` block. Since we would, most likely, want
2307
- * the variable to have the same name of the reference we have a problem, since the parameter
2308
- * to the `inject()` function would hide the outer variable.
2309
- *
2310
- * To help with this, the injected parameters can, optionally, be enclosed with underscores.
2311
- * These are ignored by the injector when the reference name is resolved.
2312
- *
2313
- * For example, the parameter `_myService_` would be resolved as the reference `myService`.
2314
- * Since it is available in the function body as _myService_, we can then assign it to a variable
2315
- * defined in an outer scope.
2316
- *
2317
- * ```
2318
- * // Defined out reference variable outside
2319
- * var myService;
2320
- *
2321
- * // Wrap the parameter in underscores
2322
- * beforeEach( inject( function(_myService_){
2323
- * myService = _myService_;
2324
- * }));
2325
- *
2326
- * // Use myService in a series of tests.
2327
- * it('makes use of myService', function() {
2328
- * myService.doStuff();
2329
- * });
2330
- *
2331
- * ```
2332
- *
2333
- * See also {@link angular.mock.module angular.mock.module}
2334
- *
2335
- * ## Example
2336
- * Example of what a typical jasmine tests looks like with the inject method.
2337
- * ```js
2338
- *
2339
- * angular.module('myApplicationModule', [])
2340
- * .value('mode', 'app')
2341
- * .value('version', 'v1.0.1');
2342
- *
2343
- *
2344
- * describe('MyApp', function() {
2345
- *
2346
- * // You need to load modules that you want to test,
2347
- * // it loads only the "ng" module by default.
2348
- * beforeEach(module('myApplicationModule'));
2349
- *
2350
- *
2351
- * // inject() is used to inject arguments of all given functions
2352
- * it('should provide a version', inject(function(mode, version) {
2353
- * expect(version).toEqual('v1.0.1');
2354
- * expect(mode).toEqual('app');
2355
- * }));
2356
- *
2357
- *
2358
- * // The inject and module method can also be used inside of the it or beforeEach
2359
- * it('should override a version and test the new version is injected', function() {
2360
- * // module() takes functions or strings (module aliases)
2361
- * module(function($provide) {
2362
- * $provide.value('version', 'overridden'); // override version here
2363
- * });
2364
- *
2365
- * inject(function(version) {
2366
- * expect(version).toEqual('overridden');
2367
- * });
2368
- * });
2369
- * });
2370
- *
2371
- * ```
2372
- *
2373
- * @param {...Function} fns any number of functions which will be injected using the injector.
2374
- */
2375
-
2376
-
2377
-
2378
- var ErrorAddingDeclarationLocationStack = function(e, errorForStack) {
2379
- this.message = e.message;
2380
- this.name = e.name;
2381
- if (e.line) this.line = e.line;
2382
- if (e.sourceId) this.sourceId = e.sourceId;
2383
- if (e.stack && errorForStack)
2384
- this.stack = e.stack + '\n' + errorForStack.stack;
2385
- if (e.stackArray) this.stackArray = e.stackArray;
2386
- };
2387
- ErrorAddingDeclarationLocationStack.prototype.toString = Error.prototype.toString;
2388
-
2389
- window.inject = angular.mock.inject = function() {
2390
- var blockFns = Array.prototype.slice.call(arguments, 0);
2391
- var errorForStack = new Error('Declaration Location');
2392
- return isSpecRunning() ? workFn.call(currentSpec) : workFn;
2393
- /////////////////////
2394
- function workFn() {
2395
- var modules = currentSpec.$modules || [];
2396
- var strictDi = !!currentSpec.$injectorStrict;
2397
- modules.unshift('ngMock');
2398
- modules.unshift('ng');
2399
- var injector = currentSpec.$injector;
2400
- if (!injector) {
2401
- if (strictDi) {
2402
- // If strictDi is enabled, annotate the providerInjector blocks
2403
- angular.forEach(modules, function(moduleFn) {
2404
- if (typeof moduleFn === "function") {
2405
- angular.injector.$$annotate(moduleFn);
2406
- }
2407
- });
2408
- }
2409
- injector = currentSpec.$injector = angular.injector(modules, strictDi);
2410
- currentSpec.$injectorStrict = strictDi;
2411
- }
2412
- for (var i = 0, ii = blockFns.length; i < ii; i++) {
2413
- if (currentSpec.$injectorStrict) {
2414
- // If the injector is strict / strictDi, and the spec wants to inject using automatic
2415
- // annotation, then annotate the function here.
2416
- injector.annotate(blockFns[i]);
2417
- }
2418
- try {
2419
- /* jshint -W040 *//* Jasmine explicitly provides a `this` object when calling functions */
2420
- injector.invoke(blockFns[i] || angular.noop, this);
2421
- /* jshint +W040 */
2422
- } catch (e) {
2423
- if (e.stack && errorForStack) {
2424
- throw new ErrorAddingDeclarationLocationStack(e, errorForStack);
2425
- }
2426
- throw e;
2427
- } finally {
2428
- errorForStack = null;
2429
- }
2430
- }
2431
- }
2432
- };
2433
-
2434
-
2435
- angular.mock.inject.strictDi = function(value) {
2436
- value = arguments.length ? !!value : true;
2437
- return isSpecRunning() ? workFn() : workFn;
2438
-
2439
- function workFn() {
2440
- if (value !== currentSpec.$injectorStrict) {
2441
- if (currentSpec.$injector) {
2442
- throw new Error('Injector already created, can not modify strict annotations');
2443
- } else {
2444
- currentSpec.$injectorStrict = value;
2445
- }
2446
- }
2447
- }
2448
- };
2449
- }
2450
-
2451
-
2452
- })(window, window.angular);