riojs 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +24 -0
  3. data/VERSION +1 -0
  4. data/bin/rio +5 -0
  5. data/generators/rio_app/USAGE +19 -0
  6. data/generators/rio_app/rio_app_generator.rb +40 -0
  7. data/generators/rio_app/templates/app.build +10 -0
  8. data/generators/rio_app/templates/app.css +0 -0
  9. data/generators/rio_app/templates/app.js +20 -0
  10. data/generators/rio_app/templates/app_view.html.erb +19 -0
  11. data/generators/rio_app/templates/fixture.js +4 -0
  12. data/generators/rio_app/templates/rio.html.erb +18 -0
  13. data/generators/rio_app/templates/rio_controller.rb +2 -0
  14. data/generators/rio_app/templates/spec.js +7 -0
  15. data/generators/rio_component/USAGE +13 -0
  16. data/generators/rio_component/rio_component_generator.rb +16 -0
  17. data/generators/rio_component/templates/component.css +0 -0
  18. data/generators/rio_component/templates/component.js +11 -0
  19. data/generators/rio_component/templates/fixture.js +3 -0
  20. data/generators/rio_component/templates/spec.js +6 -0
  21. data/generators/rio_model/USAGE +12 -0
  22. data/generators/rio_model/rio_model_generator.rb +21 -0
  23. data/generators/rio_model/templates/fixture.js +3 -0
  24. data/generators/rio_model/templates/model.js +9 -0
  25. data/generators/rio_model/templates/spec.js +6 -0
  26. data/generators/rio_page/USAGE +14 -0
  27. data/generators/rio_page/rio_page_generator.rb +16 -0
  28. data/generators/rio_page/templates/fixture.js +3 -0
  29. data/generators/rio_page/templates/page.css +12 -0
  30. data/generators/rio_page/templates/page.js +12 -0
  31. data/generators/rio_page/templates/page.jst +64 -0
  32. data/generators/rio_page/templates/spec.js +6 -0
  33. data/generators/rio_resource/USAGE +20 -0
  34. data/generators/rio_resource/rio_resource_generator.rb +10 -0
  35. data/generators/rio_resource/templates/controller.rb +3 -0
  36. data/init.rb +4 -0
  37. data/install/config/juggernaut_hosts.yml +18 -0
  38. data/install/lib/tasks/rio.rake +1 -0
  39. data/install/script/rio_server +37 -0
  40. data/lib/rio/autospec.rb +86 -0
  41. data/lib/rio/install.rb +90 -0
  42. data/lib/rio/juggernaut.rb +212 -0
  43. data/lib/rio/path.rb +3 -0
  44. data/lib/rio/rio_compressor.rb +219 -0
  45. data/lib/rio/rio_file_controller.rb +16 -0
  46. data/lib/rio/rio_on_rails.rb +586 -0
  47. data/lib/rio/rio_proxy_controller.rb +60 -0
  48. data/lib/rio/rio_push_controller.rb +48 -0
  49. data/lib/rio/rio_routes.rb +24 -0
  50. data/lib/rio/rio_spec_controller.rb +70 -0
  51. data/lib/riojs.rb +14 -0
  52. data/lib/tasks/rio.rb +63 -0
  53. data/public/images/background-chiffon.png +0 -0
  54. data/public/images/button-gradient-overlay-down.png +0 -0
  55. data/public/images/button-gradient-overlay.png +0 -0
  56. data/public/images/icons/add.png +0 -0
  57. data/public/images/icons/error-big.png +0 -0
  58. data/public/images/icons/warning-big.png +0 -0
  59. data/public/images/rio-logo-big.png +0 -0
  60. data/public/images/rio-logo.png +0 -0
  61. data/public/images/splitter-handle-horizontal.png +0 -0
  62. data/public/images/splitter-handle-vertical.png +0 -0
  63. data/public/images/tab-bar-gradient-overlay.png +0 -0
  64. data/public/images/title-gradient-overlay.png +0 -0
  65. data/public/images/trash.gif +0 -0
  66. data/public/javascripts/components/accordion.js +144 -0
  67. data/public/javascripts/components/alert_box.js +59 -0
  68. data/public/javascripts/components/base.js +47 -0
  69. data/public/javascripts/components/box.js +63 -0
  70. data/public/javascripts/components/button.js +98 -0
  71. data/public/javascripts/components/checkbox.js +44 -0
  72. data/public/javascripts/components/container.js +265 -0
  73. data/public/javascripts/components/grid_view.js +107 -0
  74. data/public/javascripts/components/image.js +19 -0
  75. data/public/javascripts/components/input.js +171 -0
  76. data/public/javascripts/components/label.js +15 -0
  77. data/public/javascripts/components/lightbox.js +160 -0
  78. data/public/javascripts/components/link.js +43 -0
  79. data/public/javascripts/components/list_item.js +44 -0
  80. data/public/javascripts/components/list_view.js +192 -0
  81. data/public/javascripts/components/marquee.js +131 -0
  82. data/public/javascripts/components/menu.js +89 -0
  83. data/public/javascripts/components/notification.js +75 -0
  84. data/public/javascripts/components/overlay.js +134 -0
  85. data/public/javascripts/components/panel.js +146 -0
  86. data/public/javascripts/components/radio.js +46 -0
  87. data/public/javascripts/components/splitter.js +65 -0
  88. data/public/javascripts/components/tab_bar.js +64 -0
  89. data/public/javascripts/components/tab_panel.js +57 -0
  90. data/public/javascripts/components/textarea.js +223 -0
  91. data/public/javascripts/components/toggle_button.js +22 -0
  92. data/public/javascripts/components/tooltip.js +80 -0
  93. data/public/javascripts/lib/application.js +482 -0
  94. data/public/javascripts/lib/attr.js +760 -0
  95. data/public/javascripts/lib/benchmark.js +235 -0
  96. data/public/javascripts/lib/blank.html +39 -0
  97. data/public/javascripts/lib/boot.js +300 -0
  98. data/public/javascripts/lib/clipboard.js +96 -0
  99. data/public/javascripts/lib/collection_entity.js +46 -0
  100. data/public/javascripts/lib/component.js +129 -0
  101. data/public/javascripts/lib/console.js +75 -0
  102. data/public/javascripts/lib/console/apps/console.build +43 -0
  103. data/public/javascripts/lib/console/apps/console.js +28 -0
  104. data/public/javascripts/lib/console/blank.html +39 -0
  105. data/public/javascripts/lib/console/components/benchmark.js +196 -0
  106. data/public/javascripts/lib/console/components/console.js +352 -0
  107. data/public/javascripts/lib/console/components/dependencies_list.js +17 -0
  108. data/public/javascripts/lib/console/components/docs.js +66 -0
  109. data/public/javascripts/lib/console/components/playground.js +30 -0
  110. data/public/javascripts/lib/console/console.html +27 -0
  111. data/public/javascripts/lib/console/console_commands.js +287 -0
  112. data/public/javascripts/lib/console/console_commands.js.rej +21 -0
  113. data/public/javascripts/lib/console/console_mixin.js +22 -0
  114. data/public/javascripts/lib/console/docs/files.html +579 -0
  115. data/public/javascripts/lib/console/docs/index.html +323 -0
  116. data/public/javascripts/lib/console/docs/symbols/Object.html +291 -0
  117. data/public/javascripts/lib/console/docs/symbols/_global_.html +413 -0
  118. data/public/javascripts/lib/console/docs/symbols/rio.AIM.html +490 -0
  119. data/public/javascripts/lib/console/docs/symbols/rio.Application.html +841 -0
  120. data/public/javascripts/lib/console/docs/symbols/rio.Attr.html +1075 -0
  121. data/public/javascripts/lib/console/docs/symbols/rio.Binding.html +272 -0
  122. data/public/javascripts/lib/console/docs/symbols/rio.Component.html +419 -0
  123. data/public/javascripts/lib/console/docs/symbols/rio.Cookie.html +543 -0
  124. data/public/javascripts/lib/console/docs/symbols/rio.DelayedTask#initialize.html +270 -0
  125. data/public/javascripts/lib/console/docs/symbols/rio.DelayedTask.html +391 -0
  126. data/public/javascripts/lib/console/docs/symbols/rio.JsTemplate.html +271 -0
  127. data/public/javascripts/lib/console/docs/symbols/rio.Juggernaut.html +329 -0
  128. data/public/javascripts/lib/console/docs/symbols/rio.Model.html +822 -0
  129. data/public/javascripts/lib/console/docs/symbols/rio.Page.html +383 -0
  130. data/public/javascripts/lib/console/docs/symbols/rio.Template.html +328 -0
  131. data/public/javascripts/lib/console/docs/symbols/rio.Utils.html +617 -0
  132. data/public/javascripts/lib/console/docs/symbols/rio.html +506 -0
  133. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_components_base.js.html +54 -0
  134. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_application.js.html +490 -0
  135. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_attr.js.html +768 -0
  136. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_boot.js.html +308 -0
  137. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_clipboard.js.html +103 -0
  138. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_collection_entity.js.html +53 -0
  139. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_component.js.html +137 -0
  140. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_cookie.js.html +81 -0
  141. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_delayed_task.js.html +68 -0
  142. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_file.js.html +80 -0
  143. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_flash_detect.js.html +129 -0
  144. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_form.js.html +95 -0
  145. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_id.js.html +50 -0
  146. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_inflector.js.html +167 -0
  147. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_js_template.js.html +283 -0
  148. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_juggernaut.js.html +303 -0
  149. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_key_map.js.html +68 -0
  150. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_layout_manager.js.html +175 -0
  151. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_log.js.html +17 -0
  152. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_model.js.html +1074 -0
  153. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_page.js.html +246 -0
  154. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_parameters.js.html +66 -0
  155. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_protohack.js.html +305 -0
  156. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_push.js.html +12 -0
  157. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_rsh.js.html +659 -0
  158. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_swfobject.js.html +12 -0
  159. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_tag.js.html +60 -0
  160. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_template.js.html +64 -0
  161. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_theme.js.html +105 -0
  162. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_undo.js.html +142 -0
  163. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_utils.js.html +87 -0
  164. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_yaml.js.html +88 -0
  165. data/public/javascripts/lib/console/file-small.png +0 -0
  166. data/public/javascripts/lib/console/green-circle.png +0 -0
  167. data/public/javascripts/lib/console/loading.gif +0 -0
  168. data/public/javascripts/lib/console/pages/console_page.js +149 -0
  169. data/public/javascripts/lib/console/pages/console_page.jst +27 -0
  170. data/public/javascripts/lib/console/red-circle.png +0 -0
  171. data/public/javascripts/lib/cookie.js +74 -0
  172. data/public/javascripts/lib/delayed_task.js +61 -0
  173. data/public/javascripts/lib/dependencies.js +76 -0
  174. data/public/javascripts/lib/environment.js +30 -0
  175. data/public/javascripts/lib/event.simulate.js +137 -0
  176. data/public/javascripts/lib/expressinstall.swf +0 -0
  177. data/public/javascripts/lib/file.js +72 -0
  178. data/public/javascripts/lib/flash_detect.js +122 -0
  179. data/public/javascripts/lib/flashembed.min.js +16 -0
  180. data/public/javascripts/lib/form.js +88 -0
  181. data/public/javascripts/lib/id.js +43 -0
  182. data/public/javascripts/lib/inflector.js +160 -0
  183. data/public/javascripts/lib/instrumenter.js +106 -0
  184. data/public/javascripts/lib/js_template.js +275 -0
  185. data/public/javascripts/lib/jslint.js +4950 -0
  186. data/public/javascripts/lib/juggernaut.js +295 -0
  187. data/public/javascripts/lib/juggernaut.swf +0 -0
  188. data/public/javascripts/lib/key_map.js +60 -0
  189. data/public/javascripts/lib/layout_manager.js +167 -0
  190. data/public/javascripts/lib/model.js +1067 -0
  191. data/public/javascripts/lib/page.js +238 -0
  192. data/public/javascripts/lib/parameters.js +59 -0
  193. data/public/javascripts/lib/png_fix.js +75 -0
  194. data/public/javascripts/lib/protohack.js +297 -0
  195. data/public/javascripts/lib/push.js +5 -0
  196. data/public/javascripts/lib/rio.build +28 -0
  197. data/public/javascripts/lib/rio_development.build +5 -0
  198. data/public/javascripts/lib/rio_lint.js +66 -0
  199. data/public/javascripts/lib/rsh.js +651 -0
  200. data/public/javascripts/lib/spec.js +545 -0
  201. data/public/javascripts/lib/spec_runner.js +242 -0
  202. data/public/javascripts/lib/swfobject.js +5 -0
  203. data/public/javascripts/lib/tag.js +52 -0
  204. data/public/javascripts/lib/undo.js +134 -0
  205. data/public/javascripts/lib/utils.js +80 -0
  206. data/public/javascripts/lib/yaml.js +80 -0
  207. data/public/javascripts/pages/playground_page.js +15 -0
  208. data/public/javascripts/prototype/builder.js +146 -0
  209. data/public/javascripts/prototype/controls.js +1004 -0
  210. data/public/javascripts/prototype/dragdrop.js +1030 -0
  211. data/public/javascripts/prototype/effects.js +1137 -0
  212. data/public/javascripts/prototype/prototype.js +4320 -0
  213. data/public/javascripts/prototype/slider.js +283 -0
  214. data/public/javascripts/prototype/sound.js +67 -0
  215. data/public/javascripts/specs/components/box_spec.js +6 -0
  216. data/public/javascripts/specs/components/checkbox_spec.js +26 -0
  217. data/public/javascripts/specs/components/container_spec.js +6 -0
  218. data/public/javascripts/specs/components/input_spec.js +71 -0
  219. data/public/javascripts/specs/components/panel_spec.js +6 -0
  220. data/public/javascripts/specs/components/radio_spec.js +40 -0
  221. data/public/javascripts/specs/fixtures/components/box.js +3 -0
  222. data/public/javascripts/specs/fixtures/components/checkbox.js +9 -0
  223. data/public/javascripts/specs/fixtures/components/container.js +3 -0
  224. data/public/javascripts/specs/fixtures/components/input.js +12 -0
  225. data/public/javascripts/specs/fixtures/components/menu.js +19 -0
  226. data/public/javascripts/specs/fixtures/components/menu_item.js +18 -0
  227. data/public/javascripts/specs/fixtures/components/radio.js +11 -0
  228. data/public/javascripts/specs/lib/application_spec.js +281 -0
  229. data/public/javascripts/specs/lib/attr_spec.js +1514 -0
  230. data/public/javascripts/specs/lib/benchmark_spec.js +361 -0
  231. data/public/javascripts/specs/lib/collection_entity_spec.js +131 -0
  232. data/public/javascripts/specs/lib/component_spec.js +86 -0
  233. data/public/javascripts/specs/lib/form_spec.js +171 -0
  234. data/public/javascripts/specs/lib/id_spec.js +21 -0
  235. data/public/javascripts/specs/lib/instrumenter_spec.js +5 -0
  236. data/public/javascripts/specs/lib/js_template_spec.js +131 -0
  237. data/public/javascripts/specs/lib/key_map_spec.js +227 -0
  238. data/public/javascripts/specs/lib/model_spec.js +2268 -0
  239. data/public/javascripts/specs/lib/parameters_spec.js +94 -0
  240. data/public/javascripts/specs/lib/spec_spec.js +943 -0
  241. data/public/javascripts/specs/lib/undo_spec.js +105 -0
  242. data/public/javascripts/specs/lib/yaml_spec.js +127 -0
  243. data/public/sounds/basso.wav +0 -0
  244. data/public/sounds/purr.wav +0 -0
  245. data/public/stylesheets/components/accordion.css +24 -0
  246. data/public/stylesheets/components/alert_box.css +35 -0
  247. data/public/stylesheets/components/box.css +0 -0
  248. data/public/stylesheets/components/button.css +39 -0
  249. data/public/stylesheets/components/checkbox.css +9 -0
  250. data/public/stylesheets/components/container.css +3 -0
  251. data/public/stylesheets/components/grid_view.css +52 -0
  252. data/public/stylesheets/components/input.css +10 -0
  253. data/public/stylesheets/components/label.css +3 -0
  254. data/public/stylesheets/components/lightbox.css +31 -0
  255. data/public/stylesheets/components/link.css +4 -0
  256. data/public/stylesheets/components/list_view.css +23 -0
  257. data/public/stylesheets/components/marquee.css +29 -0
  258. data/public/stylesheets/components/menu.css +34 -0
  259. data/public/stylesheets/components/notification.css +52 -0
  260. data/public/stylesheets/components/overlay.css +8 -0
  261. data/public/stylesheets/components/panel.css +36 -0
  262. data/public/stylesheets/components/radio.css +9 -0
  263. data/public/stylesheets/components/splitter.css +35 -0
  264. data/public/stylesheets/components/tab_bar.css +59 -0
  265. data/public/stylesheets/components/tab_panel.css +15 -0
  266. data/public/stylesheets/components/textarea.css +11 -0
  267. data/public/stylesheets/components/tooltip.css +10 -0
  268. data/public/stylesheets/console.css +151 -0
  269. data/public/stylesheets/css_reset.css +55 -0
  270. metadata +343 -0
@@ -0,0 +1,94 @@
1
+ describe(rio.Parameters, {
2
+ beforeEach: function() {
3
+ this.parameters = new rio.Parameters({ arg: "value", anotherArg: 3 });
4
+ },
5
+
6
+ "should provide an ajax parameters representation": function() {
7
+ this.parameters.ajaxParameters().arg.shouldEqual("value");
8
+ this.parameters.ajaxParameters().another_arg.shouldEqual(3);
9
+ },
10
+
11
+ "should provide a condition function that determines if an Attr instance meets the parameters": function() {
12
+ var model = rio.Model.create({ attrReaders: ["arg", "anotherArg", "unrelatedArg"] });
13
+ var meetsConditions = new model({ arg: "value", anotherArg: 3, unrelatedArg: "asdfqwer" });
14
+ this.parameters.conditionFunction()(meetsConditions).shouldBeTrue();
15
+
16
+ var doesNotMeetConditions = new model({ arg: "asdf", anotherArg: 2, unrelatedArg: "asdfqwer" });
17
+ this.parameters.conditionFunction()(doesNotMeetConditions).shouldBeFalse();
18
+ },
19
+
20
+ "should provide a condition function that matches two id's by cacheKey": function() {
21
+ var model = rio.Model.create({
22
+ resource: "/model",
23
+ attrReaders: ["arg", "anotherArg", "unrelatedArg"]
24
+ });
25
+
26
+ var id = model.id();
27
+ var meetsConditions = new model({ arg: "value", anotherArg: id, unrelatedArg: "asdfqwer" });
28
+ var parameters = new rio.Parameters({ anotherArg: id }).conditionFunction()(meetsConditions).shouldBeTrue();
29
+ },
30
+
31
+ "should provide a condition function that matches one id against an integer": function() {
32
+ var model = rio.Model.create({
33
+ resource: "/model",
34
+ attrReaders: ["arg", "anotherArg", "unrelatedArg"]
35
+ });
36
+
37
+ var id = model.id();
38
+ id.reify(13);
39
+ var meetsConditions = new model({ arg: "value", anotherArg: id, unrelatedArg: "asdfqwer" });
40
+ var parameters = new rio.Parameters({ anotherArg: 13 }).conditionFunction()(meetsConditions).shouldBeTrue();
41
+ },
42
+
43
+ "should not stringify booleans": function() {
44
+ var p = new rio.Parameters({ something: true });
45
+ (typeof p.ajaxParameters().something).shouldEqual("boolean");
46
+ },
47
+
48
+ "with a 'not' parameter": {
49
+ beforeEach: function() {
50
+ this.parameters = new rio.Parameters({
51
+ arg: "value",
52
+ anotherArg: { not: 3 }
53
+ });
54
+ },
55
+
56
+ "should provide an ajax parameters representation": function() {
57
+ this.parameters.ajaxParameters().arg.shouldEqual("value");
58
+ (this.parameters.ajaxParameters().another_arg.not == 3).shouldBeTrue();
59
+ },
60
+
61
+ "should provide a condition function that determines if an Attr instance meets the parameters": function() {
62
+ var model = rio.Model.create({ attrReaders: ["arg", "anotherArg", "unrelatedArg"] });
63
+ var meetsConditions = new model({ arg: "value", anotherArg: 2, unrelatedArg: "asdfqwer" });
64
+ this.parameters.conditionFunction()(meetsConditions).shouldBeTrue();
65
+
66
+ var doesNotMeetConditions = new model({ arg: "value", anotherArg: 3, unrelatedArg: "asdfqwer" });
67
+ this.parameters.conditionFunction()(doesNotMeetConditions).shouldBeFalse();
68
+ }
69
+ },
70
+
71
+ "with nonAjaxParameters specified": {
72
+ beforeEach: function() {
73
+ this.parameters = new rio.Parameters({
74
+ arg: "value"
75
+ }, {
76
+ anotherArg: { not: 3 }
77
+ });
78
+ },
79
+
80
+ "should provide an ajax parameters representation not including the nonAjaxParameters": function() {
81
+ this.parameters.ajaxParameters().arg.shouldEqual("value");
82
+ shouldBeUndefined(this.parameters.ajaxParameters().another_arg);
83
+ },
84
+
85
+ "should provide a condition function that determines if an Attr instance meets the parameters including the nonAjaxParameters": function() {
86
+ var model = rio.Model.create({ attrReaders: ["arg", "anotherArg", "unrelatedArg"] });
87
+ var meetsConditions = new model({ arg: "value", anotherArg: 2, unrelatedArg: "asdfqwer" });
88
+ this.parameters.conditionFunction()(meetsConditions).shouldBeTrue();
89
+
90
+ var doesNotMeetConditions = new model({ arg: "value", anotherArg: 3, unrelatedArg: "asdfqwer" });
91
+ this.parameters.conditionFunction()(doesNotMeetConditions).shouldBeFalse();
92
+ }
93
+ }
94
+ });
@@ -0,0 +1,943 @@
1
+ describe(rio.Spec, {
2
+ "should add assertions for": {
3
+ "shouldEqual": {
4
+ builder: function() {
5
+ var specs = {};
6
+ [
7
+ { name: "String", yes: "asdf", no: "qwer" },
8
+ { name: "Boolean", yes: true, no: false },
9
+ { name: "Number", yes: 1, no: 2 },
10
+ { name: "Function", yes: Prototype.emptyFunction, no: function() {} },
11
+ { name: "Array", yes: [1, 2, 3], no: [3, 2, 1] },
12
+ { name: "Id", yes: new rio.Id(1), no: new rio.Id(2) }
13
+ ].each(function(data) {
14
+ specs["to " + data.name] = function() {
15
+ data.yes.shouldEqual(data.yes);
16
+ var failed;
17
+ try {
18
+ data.yes.shouldEqual(data.no);
19
+ } catch(e) {
20
+ failed = true;
21
+ }
22
+ failed.shouldBeTrue();
23
+ };
24
+ });
25
+ return specs;
26
+ }
27
+ },
28
+
29
+ "shouldNotEqual": {
30
+ builder: function() {
31
+ var specs = {};
32
+ [
33
+ { name: "String", yes: "asdf", no: "qwer" },
34
+ { name: "Boolean", yes: true, no: false },
35
+ { name: "Number", yes: 1, no: 2 },
36
+ { name: "Function", yes: Prototype.emptyFunction, no: function() {} },
37
+ { name: "Array", yes: [1, 2, 3], no: [3, 2, 1] },
38
+ { name: "Id", yes: new rio.Id(1), no: new rio.Id(2) }
39
+ ].each(function(data) {
40
+ specs["to " + data.name] = function() {
41
+ data.yes.shouldNotEqual(data.no);
42
+ var failed;
43
+ try {
44
+ data.yes.shouldNotEqual(data.yes);
45
+ } catch(e) {
46
+ failed = true;
47
+ }
48
+ failed.shouldBeTrue();
49
+ };
50
+ });
51
+ return specs;
52
+ }
53
+ },
54
+
55
+ "shouldBeTrue": {
56
+ builder: function() {
57
+ var specs = {};
58
+ [
59
+ { name: "String", yes: "asdf", no: "" },
60
+ { name: "Boolean", yes: true, no: false },
61
+ { name: "Number", yes: 1, no: 0 },
62
+ { name: "Function", yes: Prototype.emptyFunction },
63
+ { name: "Array", yes: [1, 2, 3] },
64
+ { name: "Id", yes: new rio.Id(1) }
65
+ ].each(function(data) {
66
+ specs["to " + data.name] = function() {
67
+ data.yes.shouldBeTrue();
68
+ var failed = false;
69
+
70
+ if (data.no) {
71
+ try {
72
+ data.no.shouldBeTrue();
73
+ } catch(e) {
74
+ failed = true;
75
+ }
76
+ failed.shouldEqual(true);
77
+ }
78
+ };
79
+ });
80
+ return specs;
81
+ }
82
+ },
83
+
84
+ "shouldNotBeTrue": {
85
+ builder: function() {
86
+ var specs = {};
87
+ [
88
+ { name: "String", yes: "", no: "asdf" },
89
+ { name: "Boolean", yes: false, no: true },
90
+ { name: "Number", yes: 0, no: 1 },
91
+ { name: "Function", no: Prototype.emptyFunction },
92
+ { name: "Array", no: [1, 2, 3] },
93
+ { name: "Id", no: new rio.Id(1) }
94
+ ].each(function(data) {
95
+ specs["to " + data.name] = function() {
96
+ if (data.yes) { data.yes.shouldNotBeTrue(); }
97
+
98
+ var failed = false;
99
+ try {
100
+ data.no.shouldNotBeTrue();
101
+ } catch(e) {
102
+ failed = true;
103
+ }
104
+ failed.shouldEqual(true);
105
+ };
106
+ });
107
+ return specs;
108
+ }
109
+ },
110
+
111
+ "shouldBeFalse": {
112
+ builder: function() {
113
+ var specs = {};
114
+ [
115
+ { name: "String", yes: "", no: "asdf" },
116
+ { name: "Boolean", yes: false, no: true },
117
+ { name: "Number", yes: 0, no: 1 },
118
+ { name: "Function", no: Prototype.emptyFunction },
119
+ { name: "Array", no: [1, 2, 3] },
120
+ { name: "Id", no: new rio.Id(1) }
121
+ ].each(function(data) {
122
+ specs["to " + data.name] = function() {
123
+ if (data.yes) { data.yes.shouldBeFalse(); }
124
+
125
+ var failed = false;
126
+ try {
127
+ data.no.shouldBeFalse();
128
+ } catch(e) {
129
+ failed = true;
130
+ }
131
+ failed.shouldEqual(true);
132
+ };
133
+ });
134
+ return specs;
135
+ }
136
+ },
137
+
138
+ "shouldStartWith to String": function() {
139
+ "hello world".shouldStartWith("hello");
140
+ var failed;
141
+ try {
142
+ "hello world".shouldStartWith("world");
143
+ } catch(e) {
144
+ failed = true;
145
+ }
146
+ failed.shouldBeTrue();
147
+ },
148
+
149
+ "shouldMatchWith to String": function() {
150
+ "hello world".shouldMatch(/.*lo world$/);
151
+ var failed;
152
+ try {
153
+ "hello world".shouldMatch(/^world/);
154
+ } catch(e) {
155
+ failed = true;
156
+ }
157
+ failed.shouldBeTrue();
158
+ },
159
+
160
+ "shouldInclude to Array": function() {
161
+ [1,2,3].shouldInclude(1);
162
+ var failed;
163
+ try {
164
+ [1,2,3].shouldInclude(4);
165
+ } catch(e) {
166
+ failed = true;
167
+ }
168
+ failed.shouldBeTrue();
169
+ },
170
+
171
+ "shouldNotInclude to Array": function() {
172
+ [1,2,3].shouldNotInclude(4);
173
+ var failed;
174
+ try {
175
+ [1,2,3].shouldNotInclude(1);
176
+ } catch(e) {
177
+ failed = true;
178
+ }
179
+ failed.shouldBeTrue();
180
+ },
181
+
182
+ "shouldBeEmpty to Array": function() {
183
+ [].shouldBeEmpty();
184
+ var failed;
185
+ try {
186
+ [1,2,3].shouldBeEmpty();
187
+ } catch(e) {
188
+ failed = true;
189
+ }
190
+ failed.shouldBeTrue();
191
+ },
192
+
193
+ "shouldNotBeEmpty to Array": function() {
194
+ [1,2,3].shouldNotBeEmpty();
195
+ var failed;
196
+ try {
197
+ [].shouldNotBeEmpty();
198
+ } catch(e) {
199
+ failed = true;
200
+ }
201
+ failed.shouldBeTrue();
202
+ },
203
+
204
+ "shouldEqual to Id that considers Id objects equal to their underlying integer value": function() {
205
+ new rio.Id(1).shouldEqual(1);
206
+ }
207
+ },
208
+
209
+ "should add mock expectations to Function for": {
210
+ "shouldBeCalled": function() {
211
+ var fcn = function() {}.shouldBeCalled();
212
+ fcn();
213
+ rio.mockManager.verifyAll();
214
+
215
+ (function() {}).shouldBeCalled();
216
+ var failed;
217
+ try {
218
+ rio.mockManager.verifyAll();
219
+ } catch(e) {
220
+ failed = true;
221
+ } finally {
222
+ rio.mockManager.releaseAll();
223
+ }
224
+ failed.shouldBeTrue();
225
+ },
226
+
227
+ "shouldBeCalled.once": function() {
228
+ var fcn = function() {}.shouldBeCalled().once();
229
+ fcn();
230
+ rio.mockManager.verifyAll();
231
+ rio.mockManager.releaseAll();
232
+
233
+ var fcn2 = function() {}.shouldBeCalled().once();
234
+ fcn2();
235
+ fcn2();
236
+ var failed;
237
+ try {
238
+ rio.mockManager.verifyAll();
239
+ } catch(e) {
240
+ failed = true;
241
+ } finally {
242
+ rio.mockManager.releaseAll();
243
+ }
244
+ failed.shouldBeTrue();
245
+ },
246
+
247
+ "shouldBeCalled.times": function() {
248
+ var fcn = function() {}.shouldBeCalled().times(2);
249
+ fcn();
250
+ fcn();
251
+ rio.mockManager.verifyAll();
252
+
253
+ var fcn2 = function() {}.shouldBeCalled().times(2);
254
+ fcn2();
255
+ var failed;
256
+ try {
257
+ rio.mockManager.verifyAll();
258
+ } catch(e) {
259
+ failed = true;
260
+ } finally {
261
+ rio.mockManager.releaseAll();
262
+ }
263
+ failed.shouldBeTrue();
264
+ },
265
+
266
+ "shouldNotBeCalled": function() {
267
+ (function() {}).shouldNotBeCalled();
268
+ rio.mockManager.verifyAll();
269
+
270
+ var fcn = function() {}.shouldNotBeCalled();
271
+ fcn();
272
+ var failed;
273
+ try {
274
+ rio.mockManager.verifyAll();
275
+ } catch(e) {
276
+ failed = true;
277
+ } finally {
278
+ rio.mockManager.releaseAll();
279
+ }
280
+ failed.shouldBeTrue();
281
+ }
282
+ },
283
+
284
+ "stubs": {
285
+ "should replace an object property with a function without a return value": function() {
286
+ var obj = { f: function() { return 1; }.shouldNotBeCalled() };
287
+ new rio.Stub(obj, "f");
288
+ shouldBeUndefined(obj.f());
289
+ },
290
+
291
+ "should replace the old property value after releasing the stub": function() {
292
+ var obj = { f: function() { return 1; }.shouldBeCalled() };
293
+ var s = new rio.Stub(obj, "f");
294
+ s.release();
295
+ obj.f().shouldEqual(1);
296
+ },
297
+
298
+ "should delete the property if it was undefined when stubbed": function() {
299
+ var obj = {};
300
+ var s = new rio.Stub(obj, "f");
301
+ s.release();
302
+ Object.keys(obj).shouldNotInclude("f");
303
+ },
304
+
305
+ "should allow a return value to be provided": function() {
306
+ var obj = { f: function() {} };
307
+ new rio.Stub(obj, "f").andReturn(12);
308
+ obj.f().shouldEqual(12);
309
+ },
310
+
311
+ "should allow a custom function to be called on the stub": function() {
312
+ var obj = { f: function() {} };
313
+ new rio.Stub(obj, "f").andDo(function(val) { return val + 1; }.shouldBeCalled());
314
+ obj.f(10).shouldEqual(11);
315
+ },
316
+
317
+ "should allow any value to be used as the stub": function() {
318
+ var obj = { f: function() {} };
319
+ new rio.Stub(obj, "f").withValue("hello");
320
+ obj.f.shouldEqual("hello");
321
+ },
322
+
323
+ "should provide concise syntax for adding a shouldBeCalled expectation to the stub": function() {
324
+ var obj = { f: function() {} };
325
+ new rio.Stub(obj, "f").shouldBeCalled();
326
+ obj.f();
327
+ rio.mockManager.verifyAll();
328
+
329
+ new rio.Stub(obj, "f").shouldBeCalled();
330
+ var failed;
331
+ try {
332
+ rio.mockManager.verifyAll();
333
+ } catch(e) {
334
+ failed = true;
335
+ } finally {
336
+ rio.mockManager.releaseAll();
337
+ }
338
+ failed.shouldBeTrue();
339
+ },
340
+
341
+ "should provide concise syntax for adding a shouldNotBeCalled expectation to the stub": function() {
342
+ var obj = { f: function() {} };
343
+ new rio.Stub(obj, "f").shouldNotBeCalled();
344
+ rio.mockManager.verifyAll();
345
+
346
+ new rio.Stub(obj, "f").shouldNotBeCalled();
347
+ obj.f();
348
+ var failed;
349
+ try {
350
+ rio.mockManager.verifyAll();
351
+ } catch(e) {
352
+ failed = true;
353
+ } finally {
354
+ rio.mockManager.releaseAll();
355
+ }
356
+ failed.shouldBeTrue();
357
+ },
358
+
359
+ "provide a StubManager that": {
360
+ beforeEach: function() {
361
+ this.stubManager = new rio.StubManager();
362
+ },
363
+
364
+ "should provide a stub method that creates stubs": function() {
365
+ var obj = { f: function() { return 1; }.shouldNotBeCalled() };
366
+ this.stubManager.stub(obj, "f");
367
+ shouldBeUndefined(obj.f());
368
+ },
369
+
370
+ "should provide a releaseAll method that releases the stubs it creates": function() {
371
+ var obj = { f: function() { return 1; }, g: function() { return 2; } };
372
+ this.stubManager.stub(obj, "f");
373
+ this.stubManager.stub(obj, "g");
374
+ this.stubManager.releaseAll();
375
+ obj.f().shouldEqual(1);
376
+ obj.g().shouldEqual(2);
377
+ }
378
+ }
379
+ },
380
+
381
+ "should provide a MockManager": {
382
+ beforeEach: function() {
383
+ this.mockManager = new rio.MockManager();
384
+ },
385
+
386
+ "that can collect expectations to be verified": function() {
387
+ this.mockManager.expect(function() {
388
+ return true;
389
+ });
390
+ this.mockManager.verifyAll();
391
+ this.mockManager.expect(function() {
392
+ return false;
393
+ });
394
+ var failed;
395
+ try {
396
+ this.mockManager.verifyAll();
397
+ } catch(e) {
398
+ failed = true;
399
+ }
400
+ failed.shouldBeTrue();
401
+ },
402
+
403
+ "that can release expectations": function() {
404
+ this.mockManager.expect(function() {
405
+ return false;
406
+ });
407
+ this.mockManager.releaseAll();
408
+ this.mockManager.verifyAll();
409
+ }
410
+ },
411
+
412
+ "#executeSpec": {
413
+ beforeEach: function() {
414
+ this.env = {
415
+ rio: rio,
416
+ Ajax: Ajax,
417
+ Function: { prototype: {} }
418
+ };
419
+ },
420
+
421
+ "should evaluate the spec": function() {
422
+ var specVal;
423
+ var doEval = function(spec) {
424
+ specVal = spec;
425
+ }.shouldBeCalled();
426
+ rio.Spec.executeSpec("'SPEC'", function() {}, this.env, {}, { addComponent: function() {} }, doEval);
427
+ specVal.shouldEqual("'SPEC'");
428
+ },
429
+
430
+ "should add spec values to the env": function() {
431
+ var envSpecPage, envDescribe, envStub, envPending, envFail, envInsertComponent, envFunctionActive, envShouldBeDefined, envShouldBeUndefined, envShouldEqual, envMockManager;
432
+ var doEval = function() {
433
+ envSpecPage = this.env.specPage;
434
+ envDescribe = this.env.describe;
435
+ envStub = this.env.stub;
436
+ envPending = this.env.pending;
437
+ envFail = this.env.fail;
438
+ envInsertComponent = this.env.insertComponent;
439
+ envFunctionActive = this.env.Function.prototype.active;
440
+ envShouldBeDefined = this.env.shouldBeDefined;
441
+ envShouldBeUndefined = this.env.shouldBeUndefined;
442
+ envShouldEqual = this.env.shouldEqual;
443
+ envMockManager = this.env.rio.mockManager;
444
+ }.bind(this);
445
+ rio.Spec.executeSpec("'SPEC'", function() {}, this.env, {}, { addComponent: function() {} }, doEval);
446
+ shouldBeDefined(envSpecPage);
447
+ Object.isFunction(envDescribe).shouldBeTrue();
448
+ Object.isFunction(envStub).shouldBeTrue();
449
+ envPending.shouldEqual("PENDING");
450
+ Object.isFunction(envFail).shouldBeTrue();
451
+ Object.isFunction(envInsertComponent).shouldBeTrue();
452
+ Object.isFunction(envFunctionActive).shouldBeTrue();
453
+ Object.isFunction(envShouldBeDefined).shouldBeTrue();
454
+ Object.isFunction(envShouldBeUndefined).shouldBeTrue();
455
+ Object.isFunction(envShouldEqual).shouldBeTrue();
456
+ shouldBeDefined(envMockManager);
457
+ },
458
+
459
+ "should only add spec values to the env temporarily": function() {
460
+ rio.Spec.executeSpec("'SPEC'", function() {}, this.env, {}, { addComponent: function() {} }, function() {});
461
+ shouldBeUndefined(this.env.specPage);
462
+ shouldBeUndefined(this.env.describe);
463
+ shouldBeUndefined(this.env.stub);
464
+ shouldBeUndefined(this.env.pending);
465
+ shouldBeUndefined(this.env.fail);
466
+ shouldBeUndefined(this.env.insertComponent);
467
+ shouldBeUndefined(this.env.Function.prototype.active);
468
+ shouldBeUndefined(this.env.shouldBeDefined);
469
+ shouldBeUndefined(this.env.shouldBeUndefined);
470
+ }
471
+ },
472
+
473
+ "#describe": {
474
+ beforeEach: function() {
475
+ this.specPage = {
476
+ reset: function() {},
477
+ addComponent: function() {}
478
+ };
479
+ this.output = [];
480
+ var stdout = function(message, className) {
481
+ this.output.push({ message: message, className: className });
482
+ }.bind(this);
483
+ this.context = {
484
+ examples: 0,
485
+ failures: 0,
486
+ pendings: 0
487
+ };
488
+ this.describe = function(cls, spec) {
489
+ var doEval = function() {
490
+ describe(cls, spec);
491
+ };
492
+ rio.Spec.executeSpec("", stdout, window, this.context, this.specPage, doEval);
493
+ }.bind(this);
494
+ },
495
+
496
+ "should run a spec and print the results": function() {
497
+ this.describe("Class", {
498
+ "should do nothing": function() {}
499
+ });
500
+ this.output.first().message.shouldEqual("- Class should do nothing");
501
+ this.output.first().className.shouldEqual("passed");
502
+ },
503
+
504
+ "should print results with className 'failed' if the spec fails": function() {
505
+ this.describe("Class", {
506
+ "should fail": function() {
507
+ "hello".shouldEqual("world");
508
+ }
509
+ });
510
+ this.output.first().message.shouldStartWith("- Class should fail");
511
+ this.output.first().className.shouldEqual("failed");
512
+ },
513
+
514
+ "should increase the context example counter with the number of specs that are run": function() {
515
+ this.describe("Class", {
516
+ "should be 1": function() {},
517
+ "should be 2": function() {},
518
+ "should be 3": function() {}
519
+ });
520
+ this.context.examples.shouldEqual(3);
521
+ },
522
+
523
+ "should increase the context failures counter with the number of specs that fail": function() {
524
+ this.describe("Class", {
525
+ "should be 1": function() { "hello".shouldEqual("world"); },
526
+ "should be 2": function() {},
527
+ "should be 3": function() { "hello".shouldEqual("world"); }
528
+ });
529
+ this.context.failures.shouldEqual(2);
530
+ },
531
+
532
+ "should run a spec and then release all of the stubs": function() {
533
+ var obj = { a: 1 };
534
+ this.describe("Class", {
535
+ "should do nothing": function() {
536
+ stub(obj, "a").withValue(2);
537
+ obj.a.shouldEqual(2);
538
+ }
539
+ });
540
+ this.context.failures.shouldEqual(0);
541
+ obj.a.shouldEqual(1);
542
+ },
543
+
544
+ "should run a spec and then reset the specPage": function() {
545
+ this.specPage.reset = function() {}.shouldBeCalled();
546
+ this.describe("Class", {
547
+ "should do nothing": function() {}
548
+ });
549
+ },
550
+
551
+ "should call an optional beforeEach method before each spec": function() {
552
+ var counter = 0;
553
+ var specNumber = 0;
554
+ this.describe("Class", {
555
+ beforeEach: function() {
556
+ counter = specNumber + 1;
557
+ }.shouldBeCalled().times(2),
558
+
559
+ "should do nothing": function() {
560
+ counter.shouldEqual(1);
561
+ specNumber++;
562
+ },
563
+
564
+ "should do nothing again": function() {
565
+ counter.shouldEqual(2);
566
+ }
567
+ });
568
+ this.context.failures.shouldEqual(0);
569
+ },
570
+
571
+ "should call an optional afterEach method after each spec": function() {
572
+ var counter = 0;
573
+ var specNumber = 0;
574
+ this.describe("Class", {
575
+ afterEach: function() {
576
+ counter = specNumber + 1;
577
+ }.shouldBeCalled().times(2),
578
+
579
+ "should do nothing": function() {
580
+ counter.shouldEqual(0);
581
+ specNumber++;
582
+ },
583
+
584
+ "should do nothing again": function() {
585
+ counter.shouldEqual(2);
586
+ }
587
+ });
588
+ this.context.failures.shouldEqual(0);
589
+ },
590
+
591
+ "should not run a spec if there are specs marked active and it is not": function() {
592
+ var called = false;
593
+ this.describe("Class", {
594
+ "should not get called": function() {
595
+ called = true;
596
+ },
597
+ "should be active": function() {}.active()
598
+ });
599
+ called.shouldBeFalse();
600
+ },
601
+
602
+ "should run active specs": function() {
603
+ var counter = 0;
604
+ this.describe("Class", {
605
+ "should not get called": function() {},
606
+ "should be active": function() { counter++; }.active(),
607
+ "should be active 2": function() { counter++; }.active()
608
+ });
609
+ counter.shouldEqual(2);
610
+ },
611
+
612
+ "should only keep track of active spec context statistics if provided": function() {
613
+ this.describe("Class", {
614
+ "should not get called": function() { "asdf".shouldEqual("qwer"); },
615
+ "should be active": function() { "asdf".shouldEqual("qwer"); }.active(),
616
+ "should be active 2": function() {}.active(),
617
+ "should be pending": pending
618
+ });
619
+ this.context.examples.shouldEqual(2);
620
+ this.context.pendings.shouldEqual(0);
621
+ this.context.failures.shouldEqual(1);
622
+ },
623
+
624
+ "should use an optional builder method to generate specs": function() {
625
+ this.describe("Class", {
626
+ builder: function() {
627
+ return {
628
+ "should be tall": function() {},
629
+ "should be wider than tall": function() {}
630
+ };
631
+ }
632
+ });
633
+ this.output.first().message.shouldEqual("- Class should be tall");
634
+ this.output.last().message.shouldEqual("- Class should be wider than tall");
635
+ },
636
+
637
+ "should temporarily remove the deferral of model transaction preparation": function() {
638
+ var projectModel = rio.Model.create("Project", {
639
+ resource: "/projects"
640
+ });
641
+ stub(rio.models, "Project").withValue(projectModel);
642
+
643
+ this.describe("Class", {
644
+ "should call executeTransaction": function() {
645
+ stub(projectModel, "executeTransaction").shouldBeCalled();
646
+ projectModel.prepareTransaction();
647
+ }
648
+ });
649
+ this.context.failures.shouldEqual(0);
650
+ },
651
+
652
+ "should mark new instances of existing models as __example": function() {
653
+ var projectModel = rio.Model.create("Project", {});
654
+ stub(rio.models, "Project").withValue(projectModel);
655
+
656
+ var project;
657
+ this.describe("Class", {
658
+ "should do nothing": function() {
659
+ project = new projectModel();
660
+ }
661
+ });
662
+ project.__example.shouldBeTrue();
663
+ },
664
+
665
+ "should not mark new instances of new models as __example": function() {
666
+
667
+ var project;
668
+ this.describe("Class", {
669
+ "should do nothing": function() {
670
+ var projectModel = rio.Model.create("Project", {});
671
+ stub(rio.models, "Project").withValue(projectModel);
672
+ project = new projectModel();
673
+ }
674
+ });
675
+ shouldBeUndefined(project.__example);
676
+ },
677
+
678
+ "for pending specs": {
679
+ "should print results with className 'pending'": function() {
680
+ this.describe("Class", {
681
+ "should be implemented after I drink a beer": pending
682
+ });
683
+ this.output.first().message.shouldEqual("- Class should be implemented after I drink a beer");
684
+ this.output.first().className.shouldEqual("pending");
685
+ },
686
+
687
+ "should increase the context examples counter": function() {
688
+ this.describe("Class", {
689
+ "should be implemented after I drink a beer": pending
690
+ });
691
+ this.context.examples.shouldEqual(1);
692
+ },
693
+
694
+ "should increase the context pendings counter": function() {
695
+ this.describe("Class", {
696
+ "should be implemented after I drink a beer": pending
697
+ });
698
+ this.context.pendings.shouldEqual(1);
699
+ }
700
+ },
701
+
702
+ "for nested specs": {
703
+ "should print results with a composite spec name": function() {
704
+ this.describe("Class", {
705
+ "with cheese": {
706
+ "should do nothing": function() {}
707
+ }
708
+ });
709
+ this.output.first().message.shouldEqual("- Class with cheese should do nothing");
710
+ },
711
+
712
+ "should call the before specs in outer-to-inner order": function() {
713
+ var counter = 0;
714
+ this.describe("Class", {
715
+ beforeEach: function() {
716
+ counter.shouldEqual(0);
717
+ counter++;
718
+ },
719
+
720
+ "with cheese": {
721
+ beforeEach: function() {
722
+ counter.shouldEqual(1);
723
+ counter++;
724
+ },
725
+
726
+ "should do nothing": function() {
727
+ counter.shouldEqual(2);
728
+ }
729
+ }
730
+ });
731
+ this.context.failures.shouldEqual(0);
732
+ },
733
+
734
+ "should call the after specs in inner-to-outer order": function() {
735
+ var counter = 0;
736
+ this.describe("Class", {
737
+ afterEach: function() {
738
+ counter.shouldEqual(2);
739
+ },
740
+
741
+ "with cheese": {
742
+ afterEach: function() {
743
+ counter.shouldEqual(1);
744
+ counter++;
745
+ },
746
+
747
+ "should do nothing": function() {
748
+ counter.shouldEqual(0);
749
+ counter++;
750
+ }
751
+ }
752
+ });
753
+ this.context.failures.shouldEqual(0);
754
+ }
755
+ },
756
+
757
+ "should provide a fixture-backed server proxy": {
758
+ beforeEach: function() {
759
+ stub(rio, "models").withValue({});
760
+ var projectModel = rio.Model.create("Project", {
761
+ resource: "/projects",
762
+ attrAccessors: ["id", "unit", "name"],
763
+ methods: {
764
+ parameters: function() { return ""; }
765
+ }
766
+ });
767
+
768
+ stub(rio.models, "Project").withValue(projectModel);
769
+
770
+ projectModel.setExamples({
771
+ project1: {
772
+ id: 1,
773
+ unit: 3,
774
+ name: "ABC"
775
+ },
776
+
777
+ project2: {
778
+ id: 2,
779
+ unit: 5,
780
+ name: "DEF"
781
+ },
782
+
783
+ project3: {
784
+ id: 3,
785
+ unit: 5,
786
+ name: "GHI"
787
+ }
788
+ });
789
+ },
790
+
791
+ "that feeds model.find": function() {
792
+ var found;
793
+ this.describe("Class", {
794
+ "should find a Project": function() {
795
+ found = rio.models.Project.find(1);
796
+ }
797
+ });
798
+ found.getId().shouldEqual(1);
799
+ found.getName().shouldEqual("ABC");
800
+ },
801
+
802
+ "that does not add anything to the identity cache": function() {
803
+ this.describe("Class", {
804
+ "should find a Project": function() {
805
+ var found = rio.models.Project.find(2);
806
+ (rio.models.Project.getFromCache(2) == found).shouldBeTrue();
807
+ }
808
+ });
809
+ this.context.failures.shouldEqual(0);
810
+ shouldBeUndefined(rio.models.Project.getFromCache(2));
811
+ },
812
+
813
+ "that feeds model.findAll": function() {
814
+ var results;
815
+ this.describe("Class", {
816
+ "should find all Projects": function() {
817
+ results = rio.models.Project.findAll({});
818
+ }
819
+ });
820
+ results.length.shouldEqual(3);
821
+ results[0].getId().shouldEqual(1);
822
+ results[0].getName().shouldEqual("ABC");
823
+ results[1].getId().shouldEqual(2);
824
+ results[1].getName().shouldEqual("DEF");
825
+ results[2].getId().shouldEqual(3);
826
+ results[2].getName().shouldEqual("GHI");
827
+ },
828
+
829
+ "that feeds model.findAll and honors parameters": function() {
830
+ var results;
831
+ this.describe("Class", {
832
+ "should find all Projects": function() {
833
+ results = rio.models.Project.findAll({ parameters: { unit: 5 } });
834
+ }
835
+ });
836
+ results.length.shouldEqual(2);
837
+ results[0].getId().shouldEqual(2);
838
+ results[0].getName().shouldEqual("DEF");
839
+ results[1].getId().shouldEqual(3);
840
+ results[1].getName().shouldEqual("GHI");
841
+ },
842
+
843
+ "that does not add anything to the collection entities": function() {
844
+ this.describe("Class", {
845
+ "should find a Project": function() {
846
+ var found = rio.models.Project.findAll({});
847
+ Object.values(rio.models.Project._collectionEntities).first().shouldEqual(found);
848
+ }
849
+ });
850
+ this.context.failures.shouldEqual(0);
851
+ Object.values(rio.models.Project._collectionEntities).shouldBeEmpty();
852
+ },
853
+
854
+ "that prevents synchronicity of finders from creating infinite loops in model initializers": function() {
855
+ var thingModel = rio.Model.create("Thing", {
856
+ resource: "/things",
857
+ attrAccessors: ["id", "name"],
858
+ methods: {
859
+ initialize: function() {
860
+ rio.models.Thing.findAll({
861
+ onSuccess: function(results) {
862
+ this.allThings = results;
863
+ }.bind(this)
864
+ });
865
+ }
866
+ }
867
+ });
868
+ stub(rio.models, "Thing").withValue(thingModel);
869
+
870
+ thingModel.setExamples({
871
+ thing1: {
872
+ id: 1,
873
+ name: "ABC"
874
+ },
875
+
876
+ thing2: {
877
+ id: 2,
878
+ name: "DEF"
879
+ }
880
+ });
881
+
882
+ var thing;
883
+ this.describe("Class", {
884
+ "should not stack overflow": function() {
885
+ preloadFixtures();
886
+
887
+ thing = thingModel.find(1);
888
+ }
889
+ });
890
+ this.context.failures.shouldEqual(0);
891
+ thing.allThings.length.shouldEqual(2);
892
+ },
893
+
894
+ "that uses the identityCache to feed calls to model.example": function() {
895
+ this.describe("Class", {
896
+ "should feed identity cache": function() {
897
+ (rio.models.Project.find(1) == rio.models.Project.example("project1")).shouldBeTrue();
898
+ (rio.models.Project.example("project1") == rio.models.Project.example("project1")).shouldBeTrue();
899
+ }
900
+ });
901
+ this.context.failures.shouldEqual(0);
902
+ },
903
+
904
+ "that be able to preloads the fixtures": function() {
905
+ this.describe("Class", {
906
+ "should preload": function() {
907
+ preloadFixtures();
908
+
909
+ rio.models.Project.getFromCache(rio.models.Project.id(1)).getName().shouldEqual("ABC");
910
+ rio.models.Project.getFromCache(rio.models.Project.id(2)).getName().shouldEqual("DEF");
911
+ rio.models.Project.getFromCache(rio.models.Project.id(3)).getName().shouldEqual("GHI");
912
+ }
913
+ });
914
+ this.context.failures.shouldEqual(0);
915
+ },
916
+
917
+ "that reloads the fixtures between each spec": function() {
918
+ this.describe("Class", {
919
+ "should preload": function() {
920
+ try {
921
+ preloadFixtures();
922
+ } catch(e) {
923
+ rio.warn(e);
924
+ }
925
+
926
+ rio.models.Project.example("project1").setName("ASDF");
927
+ },
928
+
929
+ "should preload again": function() {
930
+ preloadFixtures();
931
+
932
+ rio.models.Project.example("project1").getName().shouldEqual("ABC");
933
+ }
934
+ });
935
+ this.context.failures.shouldEqual(0);
936
+ }
937
+ }
938
+ }
939
+
940
+ });
941
+
942
+
943
+