zena 1.0.0.beta3 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (418) hide show
  1. data/History.txt +29 -0
  2. data/Rakefile +2 -0
  3. data/TODO_ZENA_1_0 +13 -23
  4. data/app/controllers/columns_controller.rb +1 -1
  5. data/app/controllers/comments_controller.rb +4 -3
  6. data/app/controllers/documents_controller.rb +8 -11
  7. data/app/controllers/nodes_controller.rb +39 -21
  8. data/app/controllers/users_controller.rb +8 -3
  9. data/app/controllers/versions_controller.rb +2 -2
  10. data/app/controllers/virtual_classes_controller.rb +17 -11
  11. data/app/helpers/documents_helper.rb +0 -3
  12. data/app/helpers/users_helper.rb +17 -0
  13. data/app/models/cache.rb +36 -31
  14. data/app/models/column.rb +48 -5
  15. data/app/models/comment.rb +14 -5
  16. data/app/models/data_entry.rb +2 -2
  17. data/app/models/document.rb +23 -33
  18. data/app/models/idx_nodes_datetime.rb +4 -0
  19. data/app/models/idx_nodes_float.rb +4 -0
  20. data/app/models/idx_project.rb +3 -0
  21. data/app/models/node.rb +372 -308
  22. data/app/models/page.rb +1 -31
  23. data/app/models/relation.rb +4 -4
  24. data/app/models/relation_proxy.rb +128 -17
  25. data/app/models/role.rb +27 -2
  26. data/app/models/site.rb +64 -56
  27. data/app/models/template.rb +11 -12
  28. data/app/models/text_document.rb +6 -7
  29. data/app/models/user.rb +95 -46
  30. data/app/models/version.rb +2 -2
  31. data/app/models/virtual_class.rb +418 -73
  32. data/app/views/columns/_form.html.erb +1 -1
  33. data/app/views/columns/_li.html.erb +1 -1
  34. data/app/views/comments/_form.rhtml +1 -1
  35. data/app/views/comments/_li.rhtml +1 -1
  36. data/app/views/comments/_li_simple.rhtml +1 -1
  37. data/app/views/groups/_form.rhtml +1 -1
  38. data/app/views/links/_li.rhtml +1 -1
  39. data/app/views/nodes/_groups.rhtml +1 -1
  40. data/app/views/nodes/_import_results.rhtml +1 -1
  41. data/app/views/nodes/_parent.rhtml +1 -1
  42. data/app/views/nodes/_results.rhtml +1 -1
  43. data/app/views/nodes/create.rjs +4 -2
  44. data/app/views/relations/_li.erb +2 -2
  45. data/app/views/templates/document_create_tabs/_file.rhtml +1 -1
  46. data/app/views/templates/document_create_tabs/_template.rhtml +2 -2
  47. data/app/views/templates/document_create_tabs/_text_document.rhtml +2 -2
  48. data/app/views/templates/edit_tabs/_help.rhtml +1 -1
  49. data/app/views/templates/edit_tabs/_title.rhtml +0 -3
  50. data/app/views/users/_form.rhtml +2 -6
  51. data/app/views/users/_li.rhtml +1 -3
  52. data/app/views/users/create.rjs +4 -4
  53. data/app/views/users/preferences.html.erb +1 -4
  54. data/app/views/versions/custom_tab.rhtml +5 -0
  55. data/app/views/virtual_classes/_form.erb +20 -10
  56. data/app/views/virtual_classes/_li.erb +21 -8
  57. data/app/views/zafu/default/Node-+search.zafu +1 -1
  58. data/app/views/zafu/default/Node.zafu +3 -3
  59. data/bricks/captcha/lib/bricks/captcha.rb +1 -1
  60. data/bricks/mongrel/zena/deploy.rb +14 -0
  61. data/bricks/{data2pdf → pdf}/.document +0 -0
  62. data/bricks/pdf/README +33 -0
  63. data/bricks/{data2pdf → pdf}/Rakefile +0 -0
  64. data/bricks/pdf/VERSION +1 -0
  65. data/bricks/pdf/lib/bricks/pdf.rb +110 -0
  66. data/bricks/pdf/lib/bricks/pdf/engine/prince.rb +38 -0
  67. data/bricks/pdf/lib/bricks/pdf/engine/xhtml2pdf.rb +9 -0
  68. data/bricks/pdf/lib/bricks/pdf/install.rb +121 -0
  69. data/bricks/pdf/test/engines/test_prince.rb +15 -0
  70. data/bricks/pdf/test/engines/test_xhtml2pdf.rb +15 -0
  71. data/bricks/{data2pdf → pdf}/test/fixtures/application.css +0 -0
  72. data/bricks/{data2pdf → pdf}/test/fixtures/contact.html +0 -0
  73. data/bricks/{data2pdf → pdf}/test/fixtures/pisa-default.css +0 -0
  74. data/bricks/{data2pdf → pdf}/test/fixtures/sheet1.css +0 -0
  75. data/bricks/{data2pdf → pdf}/test/fixtures/sheet2.css +0 -0
  76. data/bricks/{data2pdf → pdf}/test/fixtures/simple-html.html +0 -0
  77. data/bricks/{data2pdf → pdf}/test/fixtures/simple-text.txt +0 -0
  78. data/bricks/{data2pdf → pdf}/test/helper.rb +4 -5
  79. data/bricks/pdf/test/shoulda_macros/shoulda_pdf.rb +72 -0
  80. data/bricks/pdf/zena/init.rb +5 -0
  81. data/bricks/pdf/zena/tasks.rb +17 -0
  82. data/bricks/sphinx/lib/{use_sphinx.rb → bricks/sphinx.rb} +1 -1
  83. data/bricks/tags/zena/init.rb +2 -2
  84. data/bricks/tags/zena/test/zafu/tags.yml +4 -4
  85. data/bricks/zena/zena/migrate/01_base.rb +482 -0
  86. data/config/bricks.yml +22 -6
  87. data/config/gems.yml +8 -6
  88. data/db/20100628074512_zena0x_to1x.rb +6 -1
  89. data/db/fix/024_correct_vclass_kpath.rb +11 -0
  90. data/db/fix/025_move_tag_into_vclass.rb +13 -0
  91. data/db/{migrate → fix}/026_rename_templates.rb +0 -0
  92. data/db/{migrate → fix}/045_avoid_star_in_templates.rb +0 -0
  93. data/db/{migrate → fix}/046_fix_zazen_image_tag.rb +0 -0
  94. data/db/{migrate → fix}/047_change_default_link_id_to_zero.rb +1 -3
  95. data/db/{migrate → fix}/049_fix_publish_from_is_null.rb +0 -0
  96. data/db/{migrate → fix}/20090924141459_zafu_fix_sept09.rb +0 -0
  97. data/db/{migrate → fix}/20091013100351_rename_publish_group_to_drive_group.rb +1 -3
  98. data/db/{migrate → fix}/20091124161608_rebuild_fullpath.rb +0 -1
  99. data/db/{migrate → fix}/20100115134729_rebuild_fullpath_after_fix.rb +0 -0
  100. data/db/{migrate → fix}/20100526090140_renamed_contact_model_to_base_contact.rb +2 -4
  101. data/db/{migrate → fix/old_migrations}/001_create_base.rb +0 -1
  102. data/db/{migrate → fix/old_migrations}/002_add_time_zone_to_users.rb +0 -0
  103. data/db/{migrate → fix/old_migrations}/003_add_custom_base_flag.rb +0 -0
  104. data/db/{migrate → fix/old_migrations}/004_rename_template_skin.rb +0 -0
  105. data/db/{migrate → fix/old_migrations}/005_create_cached_pages.rb +0 -0
  106. data/db/{migrate → fix/old_migrations}/006_create_sites.rb +0 -0
  107. data/db/{migrate → fix/old_migrations}/007_replace_id_by_zip.rb +0 -0
  108. data/db/{migrate → fix/old_migrations}/008_user_status.rb +0 -0
  109. data/db/{migrate → fix/old_migrations}/009_fulltext.rb +0 -0
  110. data/db/fix/old_migrations/010_create_template_content.rb +17 -0
  111. data/db/{migrate → fix/old_migrations}/011_project_to_section.rb +0 -0
  112. data/db/{migrate → fix/old_migrations}/012_add_project_id.rb +0 -0
  113. data/db/{migrate → fix/old_migrations}/013_remove_defaults.rb +0 -0
  114. data/db/{migrate → fix/old_migrations}/014_add_sort_field.rb +0 -0
  115. data/db/{migrate → fix/old_migrations}/015_add_dyn_attributes.rb +0 -0
  116. data/db/{migrate → fix/old_migrations}/016_remove_translations.rb +0 -0
  117. data/db/{migrate → fix/old_migrations}/017_rename_authorize.rb +0 -0
  118. data/db/{migrate → fix/old_migrations}/018_add_auth_option.rb +0 -0
  119. data/db/{migrate → fix/old_migrations}/019_remove_user_status.rb +0 -0
  120. data/db/{migrate → fix/old_migrations}/020_create_participation.rb +0 -0
  121. data/db/{migrate → fix/old_migrations}/021_create_relations.rb +0 -0
  122. data/db/{migrate → fix/old_migrations}/022_create_virtual_classes.rb +0 -0
  123. data/db/{migrate → fix/old_migrations}/023_ip_on_anonymous_comment.rb +0 -0
  124. data/db/{migrate → fix/old_migrations}/027_add_country_to_contacts.rb +0 -0
  125. data/db/{migrate → fix/old_migrations}/028_change_size_of_conten_type_field.rb +0 -0
  126. data/db/{migrate → fix/old_migrations}/029_create_data_entries.rb +0 -0
  127. data/db/{migrate → fix/old_migrations}/030_redit_auto_publish_site_settings.rb +0 -0
  128. data/db/{migrate → fix/old_migrations}/031_create_iformats.rb +0 -0
  129. data/db/{migrate → fix/old_migrations}/032_caches_context_as_hash.rb +0 -0
  130. data/db/{migrate → fix/old_migrations}/033_documents_kpath_change.rb +0 -0
  131. data/db/{migrate → fix/old_migrations}/034_change_file_storage.rb +0 -0
  132. data/db/{migrate → fix/old_migrations}/035_add_status_to_link.rb +0 -0
  133. data/db/{migrate → fix/old_migrations}/036_add_flag_fields_on_nodes.rb +0 -0
  134. data/db/{migrate → fix/old_migrations}/037_add_auto_create_discussion_to_v_class.rb +0 -0
  135. data/db/{migrate → fix/old_migrations}/038_create_site_attributes.rb +0 -0
  136. data/db/{migrate → fix/old_migrations}/039_default_position.rb +0 -0
  137. data/db/{migrate → fix/old_migrations}/040_second_value_for_data_entry.rb +0 -0
  138. data/db/{migrate → fix/old_migrations}/041_add_attributes_to_v_class.rb +0 -0
  139. data/db/{migrate → fix/old_migrations}/042_fix_position_should_be_float.rb +0 -0
  140. data/db/{migrate → fix/old_migrations}/043_move_user_lang_into_participation.rb +0 -0
  141. data/db/{migrate → fix/old_migrations}/044_remove_monolingual_site_option.rb +0 -0
  142. data/db/{migrate → fix/old_migrations}/048_link_source_target_can_be_null.rb +0 -0
  143. data/db/{migrate → fix/old_migrations}/050_date_in_links.rb +0 -0
  144. data/db/{migrate → fix/old_migrations}/051_add_exif_tags_to_images.rb +0 -0
  145. data/db/{migrate → fix/old_migrations}/20090825201159_insert_zero_link.rb +0 -0
  146. data/db/{migrate → fix/old_migrations}/20090825201200_merge_bricks_migrations_with_std_migrations.rb +0 -0
  147. data/db/{migrate → fix/old_migrations}/20090927125912_allow_null_in_text_fields.rb +0 -0
  148. data/db/{migrate → fix/old_migrations}/20090928133440_no_more_private_nodes.rb +0 -0
  149. data/db/{migrate → fix/old_migrations}/20090928143754_version_status_change.rb +0 -0
  150. data/db/{migrate → fix/old_migrations}/20091001084025_change_status_values_for_comments.rb +0 -0
  151. data/db/{migrate → fix/old_migrations}/20091009084057_add_vhash_in_node.rb +0 -0
  152. data/db/{migrate → fix/old_migrations}/20091014130833_fix_template_title.rb +0 -0
  153. data/db/{migrate → fix/old_migrations}/20091014183726_merge_participation_into_users.rb +0 -0
  154. data/db/{migrate → fix/old_migrations}/20091018200734_add_popup_info_to_image_format.rb +0 -0
  155. data/db/{migrate → fix/old_migrations}/20091026161708_add_persistence_token.rb +0 -0
  156. data/db/{migrate → fix/old_migrations}/20091101184952_add_session_table.rb +0 -0
  157. data/db/{migrate → fix/old_migrations}/20091123175137_add_single_access_token.rb +0 -0
  158. data/db/{migrate → fix/old_migrations}/20100125062254_add_dynamo_to_version.rb +0 -0
  159. data/db/{migrate → fix/old_migrations}/20100201133242_remove_default_status_on_version.rb +0 -0
  160. data/db/{migrate → fix/old_migrations}/20100208194210_create_attachments.rb +0 -0
  161. data/db/{migrate → fix/old_migrations}/20100210112319_change_dynamo_to_property.rb +0 -0
  162. data/db/{migrate → fix/old_migrations}/20100320145726_transform_template_contents_into_index.rb +0 -0
  163. data/db/{migrate → fix/old_migrations}/20100328125634_change_skin_name_to_id.rb +0 -0
  164. data/db/{migrate → fix/old_migrations}/20100417061257_add_properties_to_sites.rb +0 -0
  165. data/db/{migrate → fix/old_migrations}/20100419163149_rename_name_to_node_name.rb +0 -0
  166. data/db/{migrate → fix/old_migrations}/20100422091606_change_v_class_table_into_roles.rb +0 -0
  167. data/db/{migrate → fix/old_migrations}/20100422094048_node_habtm_roles.rb +0 -0
  168. data/db/{migrate → fix/old_migrations}/20100422115935_create_columns.rb +0 -0
  169. data/db/{migrate → fix/old_migrations}/20100513181529_add_site_id_to_columns.rb +0 -0
  170. data/db/{migrate → fix/old_migrations}/20100519091711_add_index_definition_to_columns.rb +0 -0
  171. data/db/{migrate → fix/old_migrations}/20100519091940_create_idx_nodes_string.rb +0 -0
  172. data/db/{migrate → fix/old_migrations}/20100519232432_create_idx_nodes_ml_string.rb +0 -0
  173. data/db/{migrate → fix/old_migrations}/20100525113858_add_porperties_to_users.rb +0 -0
  174. data/db/{migrate → fix/old_migrations}/20100527130937_change_column_index_to_string.rb +0 -0
  175. data/db/{migrate → fix/old_migrations}/20100531135128_add_fulltext_builder_fields.rb +0 -0
  176. data/db/{migrate → fix/old_migrations}/20100915062903_add_api_group_id_to_site.rb +0 -0
  177. data/db/fix/old_migrations/20100923154807_remove_base_contact.rb +84 -0
  178. data/db/fix/old_migrations/20100926192223_remove_su_user.rb +8 -0
  179. data/db/fix/old_migrations/20100927141658_add_eval_attributes_to_v_class.rb +12 -0
  180. data/db/fix/old_migrations/20100928185257_add_obvious_idx.rb +52 -0
  181. data/db/fix/old_migrations/20100929143111_remove_node_name.rb +11 -0
  182. data/db/fix/old_migrations/20101006090454_store_properties_in_long_text.rb +9 -0
  183. data/db/fix/old_migrations/20101014185753_remove_user_prototype_id.rb +9 -0
  184. data/db/fix/old_migrations/20101101084318_create_scope_index.rb +35 -0
  185. data/db/fix/old_migrations/20101109074232_create_idx_nodes_tables.rb +65 -0
  186. data/db/fix/old_migrations/20101110184235_add_role_update_to_site.rb +9 -0
  187. data/db/fix/old_migrations/20101116103920_change_scope_index.rb +31 -0
  188. data/db/fix/old_migrations/20101123125822_add_integer_idx.rb +17 -0
  189. data/db/fix/old_migrations/20101130134522_add_index_field.rb +13 -0
  190. data/db/fix/old_migrations/20101213133816_add_group_to_relation.rb +9 -0
  191. data/db/init/base/help.fr.zml +1 -1
  192. data/db/init/base/skins/default.zml +0 -1
  193. data/db/init/base/skins/default/Node-+search.zafu +1 -1
  194. data/db/init/base/skins/default/Node-tree.zafu +3 -3
  195. data/db/init/base/skins/default/Node.zafu +3 -3
  196. data/lib/bricks/loader.rb +4 -1
  197. data/lib/bricks/requirements_validation.rb +11 -6
  198. data/lib/log_recorder/lib/log_recorder.rb +2 -2
  199. data/lib/tasks/zena.rake +25 -15
  200. data/lib/zena.rb +42 -9
  201. data/lib/zena/acts/enrollable.rb +81 -99
  202. data/lib/zena/acts/secure.rb +27 -23
  203. data/lib/zena/acts/secure_node.rb +10 -55
  204. data/lib/zena/acts/serializable.rb +9 -10
  205. data/lib/zena/app.rb +0 -2
  206. data/lib/zena/code_syntax.rb +1 -1
  207. data/lib/zena/controller/test_case.rb +0 -5
  208. data/lib/zena/core_ext/string.rb +48 -20
  209. data/lib/zena/db.rb +10 -442
  210. data/lib/zena/db_helper/abstract_db.rb +184 -0
  211. data/lib/zena/db_helper/mysql.rb +150 -0
  212. data/lib/zena/db_helper/postgresql.rb +79 -0
  213. data/lib/zena/db_helper/sqlite3.rb +135 -0
  214. data/lib/zena/deploy.rb +4 -1
  215. data/lib/zena/deploy/httpd.rhtml +3 -3
  216. data/lib/zena/deploy/vhost.rhtml +1 -1
  217. data/lib/zena/foxy_parser.rb +37 -18
  218. data/lib/zena/info.rb +3 -13
  219. data/lib/zena/migrator.rb +0 -1
  220. data/lib/zena/parser/zafu_rules.rb +9 -4
  221. data/lib/zena/parser/zazen_rules.rb +5 -5
  222. data/lib/zena/parser/zena_rules.rb +1 -1
  223. data/lib/zena/remote/interface.rb +1 -1
  224. data/lib/zena/site_worker.rb +3 -3
  225. data/lib/zena/test_controller.rb +10 -10
  226. data/lib/zena/use/action.rb +66 -6
  227. data/lib/zena/use/ajax.rb +39 -13
  228. data/lib/zena/use/ancestry.rb +210 -0
  229. data/lib/zena/use/authlogic.rb +30 -1
  230. data/lib/zena/use/calendar.rb +158 -0
  231. data/lib/zena/use/conditional.rb +3 -2
  232. data/lib/zena/use/context.rb +42 -12
  233. data/lib/zena/use/dates.rb +15 -14
  234. data/lib/zena/use/display.rb +54 -7
  235. data/lib/zena/use/error_rendering.rb +1 -0
  236. data/lib/zena/use/field_index.rb +20 -0
  237. data/lib/zena/use/fixtures.rb +12 -9
  238. data/lib/zena/use/forms.rb +230 -106
  239. data/lib/zena/use/fulltext.rb +28 -14
  240. data/lib/zena/use/html_tags.rb +1 -24
  241. data/lib/zena/use/i18n.rb +69 -14
  242. data/lib/zena/use/kpath.rb +60 -0
  243. data/lib/zena/use/ml_index.rb +6 -4
  244. data/lib/zena/use/node_context.rb +63 -0
  245. data/lib/zena/use/prop_eval.rb +90 -0
  246. data/lib/zena/use/query_builder.rb +159 -29
  247. data/lib/zena/use/query_comment.rb +1 -1
  248. data/lib/zena/use/query_node.rb +147 -56
  249. data/lib/zena/use/recursion.rb +2 -2
  250. data/lib/zena/use/relations.rb +31 -19
  251. data/lib/zena/use/rendering.rb +111 -121
  252. data/lib/zena/use/scope_index.rb +230 -0
  253. data/lib/zena/use/search.rb +7 -7
  254. data/lib/zena/use/urls.rb +87 -25
  255. data/lib/zena/use/version_hash.rb +113 -113
  256. data/lib/zena/use/workflow.rb +5 -1
  257. data/lib/zena/use/zafu_attributes.rb +11 -14
  258. data/lib/zena/use/zafu_eval.rb +1 -1
  259. data/lib/zena/use/zafu_safe_definitions.rb +91 -9
  260. data/lib/zena/use/zafu_templates.rb +146 -102
  261. data/lib/zena/use/zazen.rb +5 -4
  262. data/lib/zena/zafu_compiler.rb +1 -0
  263. data/locale/en/LC_MESSAGES/zena.mo +0 -0
  264. data/locale/en/zena.po +0 -1
  265. data/locale/fr/LC_MESSAGES/zena.mo +0 -0
  266. data/locale/fr/zena.mo +0 -0
  267. data/locale/fr/zena.po +4 -4
  268. data/misc/zena +35 -0
  269. data/misc/zena_init +41 -0
  270. data/public/images/ext/{basecontact.png → contact.png} +0 -0
  271. data/public/javascripts/zena.js +35 -7
  272. data/public/stylesheets/admin.css +5 -2
  273. data/public/stylesheets/default.css +2 -1
  274. data/public/stylesheets/popup.css +1 -1
  275. data/public/stylesheets/zena.css +2 -2
  276. data/test/custom_queries/complex.host.yml +12 -5
  277. data/test/fixtures/files/Node-test.zafu +3 -3
  278. data/test/fixtures/files/translations_fr.yml +4 -2
  279. data/test/functional/documents_controller_test.rb +31 -0
  280. data/test/functional/nodes_controller_commit_test.rb +1 -5
  281. data/test/functional/nodes_controller_test.rb +92 -12
  282. data/test/functional/user_sessions_controller_test.rb +2 -2
  283. data/test/functional/users_controller_test.rb +31 -29
  284. data/test/functional/versions_controller_test.rb +2 -2
  285. data/test/functional/virtual_classes_controller_test.rb +2 -2
  286. data/test/integration/multiple_hosts_test.rb +19 -8
  287. data/test/integration/navigation_test.rb +91 -12
  288. data/test/integration/query_node/basic.yml +40 -37
  289. data/test/integration/query_node/complex.yml +23 -18
  290. data/test/integration/query_node/dates.yml +3 -3
  291. data/test/integration/query_node/errors.yml +7 -1
  292. data/test/integration/query_node/filters.yml +41 -35
  293. data/test/integration/query_node/idx_fields.yml +11 -0
  294. data/test/integration/query_node/idx_key_value.yml +77 -0
  295. data/test/integration/query_node/idx_scope.yml +33 -0
  296. data/test/integration/query_node/relations.yml +13 -13
  297. data/test/integration/query_node_test.rb +6 -10
  298. data/test/integration/zafu_compiler/action.yml +19 -6
  299. data/test/integration/zafu_compiler/ajax.yml +111 -51
  300. data/test/integration/zafu_compiler/apphelper.yml +1 -1
  301. data/test/integration/zafu_compiler/asset.yml +1 -1
  302. data/test/integration/zafu_compiler/basic.yml +42 -52
  303. data/test/integration/zafu_compiler/calendar.yml +3 -3
  304. data/test/integration/zafu_compiler/complex.yml +16 -16
  305. data/test/integration/zafu_compiler/complex_ok.yml +2 -2
  306. data/test/integration/zafu_compiler/conditional.yml +42 -33
  307. data/test/integration/zafu_compiler/data.yml +3 -3
  308. data/test/integration/zafu_compiler/dates.yml +25 -10
  309. data/test/integration/zafu_compiler/display.yml +49 -12
  310. data/test/integration/zafu_compiler/errors.yml +26 -6
  311. data/test/integration/zafu_compiler/eval.yml +4 -4
  312. data/test/integration/zafu_compiler/forms.yml +89 -15
  313. data/test/integration/zafu_compiler/i18n.yml +23 -18
  314. data/test/integration/zafu_compiler/idx_scope.yml +7 -0
  315. data/test/integration/zafu_compiler/later.yml +10 -16
  316. data/test/integration/zafu_compiler/off/off.yml +2 -2
  317. data/test/integration/zafu_compiler/query.yml +207 -0
  318. data/test/integration/zafu_compiler/recursion.yml +2 -2
  319. data/test/integration/zafu_compiler/relations.yml +144 -168
  320. data/test/integration/zafu_compiler/roles.yml +86 -10
  321. data/test/integration/zafu_compiler/rubyless.yml +49 -6
  322. data/test/integration/zafu_compiler/safe_definitions.yml +35 -6
  323. data/test/integration/zafu_compiler/search.yml +1 -1
  324. data/test/integration/zafu_compiler/security.yml +37 -0
  325. data/test/integration/zafu_compiler/urls.yml +50 -40
  326. data/test/integration/zafu_compiler/user.yml +21 -6
  327. data/test/integration/zafu_compiler/version.yml +6 -6
  328. data/test/integration/zafu_compiler/zafu_attributes.yml +43 -34
  329. data/test/integration/zafu_compiler/zazen.yml +10 -10
  330. data/test/integration/zafu_compiler_test.rb +19 -13
  331. data/test/sites/complex/nodes.yml +0 -2
  332. data/test/sites/complex/roles.yml +9 -1
  333. data/test/sites/complex/sites.yml +0 -1
  334. data/test/sites/complex/users.yml +2 -5
  335. data/test/sites/ocean/nodes.yml +2 -5
  336. data/test/sites/ocean/roles.yml +8 -0
  337. data/test/sites/ocean/sites.yml +0 -1
  338. data/test/sites/ocean/users.yml +0 -13
  339. data/test/sites/zena/columns.yml +27 -5
  340. data/test/sites/zena/idx_projects.yml +5 -0
  341. data/test/sites/zena/nodes.yml +8 -32
  342. data/test/sites/zena/relations.yml +5 -0
  343. data/test/sites/zena/roles.yml +25 -3
  344. data/test/sites/zena/sites.yml +2 -2
  345. data/test/sites/zena/users.yml +1 -21
  346. data/test/sites/zena/versions.yml +35 -12
  347. data/test/test_helper.rb +7 -0
  348. data/test/unit/after_commit_test.rb +7 -7
  349. data/test/unit/cache_test.rb +32 -0
  350. data/test/unit/cached_page_test.rb +1 -1
  351. data/test/unit/column_test.rb +31 -7
  352. data/test/unit/comment_test.rb +2 -2
  353. data/test/unit/core_ext_test.rb +38 -7
  354. data/test/unit/document_test.rb +14 -42
  355. data/test/unit/node_test.rb +311 -324
  356. data/test/unit/note_test.rb +23 -31
  357. data/test/unit/page_test.rb +16 -58
  358. data/test/unit/project_test.rb +2 -2
  359. data/test/unit/relation_proxy_test.rb +148 -21
  360. data/test/unit/relation_test.rb +23 -3
  361. data/test/unit/remote_test.rb +15 -9
  362. data/test/unit/role_test.rb +9 -0
  363. data/test/unit/site_test.rb +49 -47
  364. data/test/unit/skin_test.rb +16 -0
  365. data/test/unit/template_test.rb +60 -69
  366. data/test/unit/text_document_test.rb +15 -14
  367. data/test/unit/user_test.rb +101 -41
  368. data/test/unit/version_test.rb +4 -4
  369. data/test/unit/virtual_class_test.rb +577 -36
  370. data/test/unit/workflow_test.rb +58 -21
  371. data/test/unit/zena/acts/enrollable_test.rb +36 -127
  372. data/test/unit/zena/acts/secure_test.rb +6 -22
  373. data/test/unit/zena/acts/serializable_test.rb +18 -0
  374. data/test/unit/zena/db_test.rb +14 -14
  375. data/test/unit/zena/parser/zafu.yml +5 -3
  376. data/test/unit/zena/use/ancestry_test.rb +198 -0
  377. data/test/unit/zena/use/calendar_test.rb +8 -8
  378. data/test/unit/zena/use/dates_test.rb +2 -0
  379. data/test/unit/zena/use/fulltext_test.rb +9 -1
  380. data/test/unit/zena/use/html_tags_test.rb +2 -16
  381. data/test/unit/zena/use/i18n_test.rb +2 -2
  382. data/test/unit/zena/use/kpath_test.rb +13 -0
  383. data/test/unit/zena/use/ml_index_test.rb +60 -12
  384. data/test/unit/zena/use/prop_eval_test.rb +170 -0
  385. data/test/unit/zena/use/query_node_test.rb +9 -2
  386. data/test/unit/zena/use/rendering_test.rb +98 -1
  387. data/test/unit/zena/use/scope_index_test.rb +464 -0
  388. data/test/unit/zena/use/urls_test.rb +23 -13
  389. data/test/unit/zena/use/version_hash_test.rb +2 -2
  390. data/test/unit/zena/use/zafu_template_test.rb +21 -8
  391. data/test/unit/zena/use/zazen_test.rb +47 -47
  392. data/zena.gemspec +177 -143
  393. metadata +222 -141
  394. data/app/models/base_contact.rb +0 -79
  395. data/app/models/book.rb +0 -242
  396. data/app/models/contact_content.rb +0 -70
  397. data/app/models/contact_version.rb +0 -40
  398. data/app/models/reference.rb +0 -18
  399. data/app/views/templates/edit_tabs/_basecontact.rhtml +0 -8
  400. data/bricks/data2pdf/README +0 -19
  401. data/bricks/data2pdf/VERSION +0 -1
  402. data/bricks/data2pdf/lib/data2pdf.rb +0 -60
  403. data/bricks/data2pdf/lib/engines/prince.rb +0 -39
  404. data/bricks/data2pdf/lib/engines/xhtml2pdf.rb +0 -41
  405. data/bricks/data2pdf/lib/install.rb +0 -111
  406. data/bricks/data2pdf/test/engines/test_prince.rb +0 -14
  407. data/bricks/data2pdf/test/engines/test_xhtml2pdf.rb +0 -14
  408. data/bricks/data2pdf/test/shoulda_macros/shoulda_data2pdf.rb +0 -91
  409. data/bricks/data2pdf/test/unit/test_rendering.rb +0 -37
  410. data/config/routes.rb +0 -3
  411. data/db/migrate/010_create_template_content.rb +0 -17
  412. data/db/migrate/024_correct_vclass_kpath.rb +0 -13
  413. data/db/migrate/025_move_tag_into_vclass.rb +0 -15
  414. data/lib/version_off.rb +0 -323
  415. data/lib/zena/use/node_name.rb +0 -94
  416. data/test/integration/query_node/properties.yml +0 -41
  417. data/test/unit/base_contact_test.rb +0 -242
  418. data/test/unit/node_name_test.rb +0 -137
@@ -26,7 +26,7 @@ class TextDocumentTest < Zena::Unit::TestCase
26
26
  body { font-size:10px; }
27
27
  #header { background:url('bird.jpg') }
28
28
  #pv { background:url('bird_pv.jpg') }
29
- #footer { background:url('/projects/wiki/flower.jpg') }
29
+ #footer { background:url('/projects list/a wiki with Zena/flower.jpg') }
30
30
  #no_stamp { background:url('/en/image30_pv.jpg?100001001345') }
31
31
  END_CSS
32
32
 
@@ -48,24 +48,24 @@ class TextDocumentTest < Zena::Unit::TestCase
48
48
  end
49
49
  end # in a folder with an image
50
50
  end # on a css text_document
51
-
51
+
52
52
  context 'creating a text document' do
53
53
  context 'with a content_type' do
54
54
  subject do
55
55
  secure!(TextDocument) { TextDocument.create(
56
- :node_name => "yoba",
56
+ :title => "yoba",
57
57
  :parent_id => nodes_id(:wiki),
58
58
  :text => "#header { color:red; }\n#footer { color:blue; }",
59
- :content_type => 'text/css')
59
+ :content_type => 'text/css')
60
60
  }
61
61
  end
62
-
62
+
63
63
  should 'create a new TextDocument' do
64
64
  assert_difference('TextDocument.count', 1) do
65
65
  subject
66
66
  end
67
67
  end
68
-
68
+
69
69
  should 'set extension from content_type' do
70
70
  assert_equal 'css', subject.ext
71
71
  end
@@ -75,11 +75,11 @@ class TextDocumentTest < Zena::Unit::TestCase
75
75
 
76
76
  def test_create_simplest
77
77
  login(:tiger)
78
- doc = secure!(Document) { Document.create(:parent_id=>nodes_id(:cleanWater), :node_name => 'skiny')}
78
+ doc = secure!(Document) { Document.create(:parent_id=>nodes_id(:cleanWater), :title => 'skiny')}
79
79
  assert_equal TextDocument, doc.class
80
80
  assert !doc.new_record?, "Not a new record"
81
81
  assert_equal 0, doc.size
82
- doc = secure!(Document) { Document.create(:parent_id=>nodes_id(:cleanWater), :node_name => 'medium', :text=>"12345678901234567890")}
82
+ doc = secure!(Document) { Document.create(:parent_id=>nodes_id(:cleanWater), :title => 'medium', :text=>"12345678901234567890")}
83
83
  assert_equal TextDocument, doc.class
84
84
  assert !doc.new_record?, "Not a new record"
85
85
  assert_equal 20, doc.size
@@ -91,6 +91,7 @@ class TextDocumentTest < Zena::Unit::TestCase
91
91
  file = uploaded_text('some.txt')
92
92
  doc = secure!(Document) { Document.create( :parent_id => nodes_id(:cleanWater),
93
93
  :file => file ) }
94
+
94
95
  assert_equal TextDocument, doc.class
95
96
  # reload
96
97
  doc = secure!(Document) { Document.find(doc[:id])}
@@ -127,8 +128,8 @@ class TextDocumentTest < Zena::Unit::TestCase
127
128
  body { font-size:10px; behavior:url("/stylesheets/csshover2.htc"); }
128
129
  #header { background:url('bird.jpg') }
129
130
  #pv { background:url('bird_pv.jpg') }
130
- #footer { background:url('/projects/wiki/flower.jpg') }
131
- #back { background:url('../../projects/wiki/flower.jpg') }
131
+ #footer { background:url('/projects list/a wiki with Zena/flower.jpg') }
132
+ #back { background:url('../../projects list/a wiki with Zena/flower.jpg') }
132
133
  #no_stamp { background:url('/en/image30_pv.jpg') }
133
134
  END_CSS
134
135
  node.text = start.dup
@@ -154,8 +155,8 @@ class TextDocumentTest < Zena::Unit::TestCase
154
155
  body { font-size:10px; behavior:url("/stylesheets/csshover2.htc"); }
155
156
  #header { background:url('bird.jpg') }
156
157
  #pv { background:url('bird_pv.jpg') }
157
- #footer { background:url('/projects/wiki/flower.jpg') }
158
- #back { background:url('/projects/wiki/flower.jpg') }
158
+ #footer { background:url('/projects list/a wiki with Zena/flower.jpg') }
159
+ #back { background:url('/projects list/a wiki with Zena/flower.jpg') }
159
160
  #no_stamp { background:url('bird_pv.jpg') }
160
161
  END_CSS
161
162
  assert_equal unparsed, text
@@ -169,13 +170,13 @@ class TextDocumentTest < Zena::Unit::TestCase
169
170
  bird = secure!(Node) { nodes(:bird_jpg)}
170
171
  b_at = bird.updated_at
171
172
  # We need to publish so that the title is used for fullpath
172
- assert bird.update_attributes(:parent_id => node[:parent_id], :title => "greenBird", :v_status => Zena::Status[:pub])
173
+ assert bird.update_attributes(:parent_id => node[:parent_id], :title => "green_bird", :v_status => Zena::Status[:pub])
173
174
  Zena::Db.set_attribute(bird, :updated_at, b_at)
174
175
  start =<<-END_CSS
175
176
  body { font-size:10px; }
176
177
  #header { background:url('green_bird.jpg') }
177
178
  #tiny { background:url('green_bird_tiny.jpg') }
178
- #footer { background:url('/projects/wiki/flower.jpg') }
179
+ #footer { background:url('/projects list/a wiki with Zena/flower.jpg') }
179
180
  END_CSS
180
181
  node.text = start.dup
181
182
  # dummy controller
@@ -3,7 +3,10 @@ require 'test_helper'
3
3
  class UserTest < Zena::Unit::TestCase
4
4
 
5
5
  def test_find_allowed_user_by_login
6
- assert_equal users_id(:su), User.find_allowed_user_by_login('su').id
6
+ login(:anon)
7
+ secure(User) do
8
+ assert_equal users_id(:lion), User.find_allowed_user_by_login('lion').id
9
+ end
7
10
  end
8
11
 
9
12
  def test_deleted_user_should_not_be_allowed
@@ -32,23 +35,27 @@ class UserTest < Zena::Unit::TestCase
32
35
  end
33
36
  end
34
37
 
35
- def test_cannot_destroy_su
36
- login(:su)
37
- su = users(:su)
38
- assert_raise(Zena::AccessViolation){ su.destroy }
39
- end
38
+ context 'Destroying a user' do
39
+ context 'with admin rights' do
40
+ setup do
41
+ login(:lion)
42
+ end
40
43
 
41
- def test_cannot_destroy_anon
42
- login(:su)
43
- anon = users(:anon)
44
- assert_raise(Zena::AccessViolation){ anon.destroy }
45
- end
44
+ should 'not allow anon destruction' do
45
+ assert_raise(Zena::AccessViolation){ users(:anon).destroy }
46
+ end
46
47
 
47
- def test_can_destroy_ant
48
- login(:lion)
49
- ant = users(:ant)
50
- assert_nothing_raised( Zena::AccessViolation ) { ant.destroy }
51
- end
48
+ should 'not allow destruction of self' do
49
+ assert_raise(Zena::AccessViolation){ users(:lion).destroy }
50
+ end
51
+
52
+ should 'allow destruction of regular users' do
53
+ assert_difference('User.count', -1) do
54
+ assert_nothing_raised { users(:ant).destroy }
55
+ end
56
+ end
57
+ end # with admin rights
58
+ end # Destroying a user
52
59
 
53
60
  context 'Creating a new User' do
54
61
  setup do
@@ -56,37 +63,90 @@ class UserTest < Zena::Unit::TestCase
56
63
  end
57
64
 
58
65
  subject do
59
- {
60
- 'name' => 'Dupont',
66
+ attrs = {
61
67
  'lang' => 'fr',
62
68
  'time_zone' => 'Europe/Zurich',
63
69
  'status' => '50',
64
70
  'password' => 'secret',
65
71
  'login' => 'bolomey',
66
- 'first_name' => 'Paul',
67
72
  'group_ids' => [groups_id(:public), ''],
68
- 'email' => 'paul.bolomey@brainfuck.com',
73
+ 'node_attributes' => {
74
+ 'name' => 'Dupont',
75
+ 'first_name' => 'Paul',
76
+ 'email' => 'paul.bolomey@brainfuck.com'
77
+ }
69
78
  }
79
+ secure(User) { User.create(attrs) }
70
80
  end
71
81
 
72
82
  should 'succeed' do
73
83
  assert_difference('User.count', 1) do
74
- user = secure(User) { User.new(subject) }
75
- user.save
84
+ subject
76
85
  end
77
86
  end
87
+
88
+ should 'use missing attributes from prototype' do
89
+ assert_equal 'Iping', subject.node.prop['address']
90
+ end
78
91
  end # Creating a new User
79
92
 
93
+ context 'Setting node attributes' do
94
+ setup do
95
+ login(:anon)
96
+ subject.node_attributes = {'title' => 'bar'}
97
+ end
98
+
99
+ subject do
100
+ User.new
101
+ end
102
+
103
+ should 'create a new record' do
104
+ assert subject.node.new_record?
105
+ end
106
+
107
+ should 'create a Node of the type defined in prototype attributes' do
108
+ assert_equal 'Contact', subject.node.klass
109
+ end
110
+
111
+ context 'more then once' do
112
+ setup do
113
+ @first = subject.node
114
+ second = User.new
115
+ second.node_attributes = {}
116
+ @second = second.node
117
+ end
118
+
119
+ should 'return a new node on each call' do
120
+ assert_not_equal @first.object_id, @second.object_id
121
+ end
122
+ end # more then once
123
+
124
+ end # Setting node attributes
125
+
126
+ context 'On a user' do
127
+ subject do
128
+ users(:lion)
129
+ end
130
+
131
+ should 'evaluate rubyless code in prototype_attributes' do
132
+ assert_equal Hash[
133
+ :_parent_id => subject.site.root_id,
134
+ 'klass' => 'Contact',
135
+ 'address' => 'Iping',
136
+ 'name' => 'lion'], subject.prototype_attributes
137
+ end
138
+ end # On a user
139
+
80
140
  def test_create
81
141
  User.connection.execute "UPDATE users SET lang='ru' WHERE id IN (#{users_id(:incognito)},#{users_id(:whale)})"
82
142
  User.connection.execute "UPDATE sites SET languages='fr,ru' WHERE id=#{sites_id(:ocean)}"
83
143
  User.connection.execute "UPDATE users SET time_zone='US/Hawaii' WHERE id=#{users_id(:incognito)}"
84
144
  login(:whale)
85
145
 
86
- user = secure!(User) { User.create("login"=>"john", "password"=>"isjjna78a9h") }
146
+ user = secure!(User) { User.create("login"=>"john", "password"=>"isjjna78a9h", 'node_attributes' => {'v_lang' => 'ru'}) }
87
147
 
88
148
  assert !user.new_record?, "Not a new record"
89
- assert !user.contact.new_record?, "Users's contact node is not a new record"
149
+ assert !user.node.new_record?, "Users's contact node is not a new record"
90
150
 
91
151
  user = secure!(User) { User.find(user[:id]) } # reload
92
152
  assert_equal sites_id(:ocean), user.site_id
@@ -99,7 +159,7 @@ class UserTest < Zena::Unit::TestCase
99
159
  assert !user.user?, "Not a real user yet"
100
160
  assert visitor.user?, "Whale is a user"
101
161
 
102
- contact = user.contact
162
+ contact = user.node
103
163
  assert_equal "john", contact.title
104
164
  end
105
165
 
@@ -111,25 +171,25 @@ class UserTest < Zena::Unit::TestCase
111
171
  assert user.errors[:base] #.any?
112
172
  login(:lion)
113
173
  user = secure!(User) { User.create("name"=>"Shakespeare", "status"=>"50", "group_ids"=>[""], "lang"=>"fr", "time_zone"=>"Bern", "first_name"=>"William", "login"=>"bob", "password"=>"jsahjks894", "email"=>"") }
114
- assert !user.new_record?, "Saved"
115
- assert !user.contact.new_record?, "BaseContact saved"
116
- assert_equal sites_id(:zena), user.contact.site_id
174
+ assert !user.new_record?
175
+ assert !user.node.new_record?
176
+ assert_equal sites_id(:zena), user.node.site_id
117
177
  end
118
178
 
119
179
  def test_create_with_auto_publish
120
180
  Site.connection.execute "UPDATE sites SET auto_publish = #{Zena::Db::TRUE} WHERE id = #{sites_id(:zena)}"
121
181
  login(:lion)
122
- user = secure!(User) { User.create("name"=>"Shakespeare", "status"=>"50", "group_ids"=>[""], "lang"=>"fr", "time_zone"=>"Europe/Zurich", "first_name"=>"William", "login"=>"bob", "password"=>"jsahjks894", "email"=>"") }
123
- assert !user.new_record?, "Saved"
124
- assert !user.contact.new_record?, "BaseContact saved"
125
- assert_equal sites_id(:zena), user.contact.site_id
182
+ user = secure!(User) { User.create('status'=>'50', 'group_ids'=>[''], 'lang'=>'fr', 'time_zone'=>'Europe/Zurich', 'node_attributes' => {'first_name'=>'William', 'name'=>'Shakespeare'}, 'login'=>'bob', 'password'=>'jsahjks894') }
183
+ assert !user.new_record?
184
+ assert !user.node.new_record?
185
+ assert_equal sites_id(:zena), user.node.site_id
126
186
  end
127
187
 
128
188
  def test_create_admin_with_groups
129
189
  login(:lion)
130
- user = secure!(User) { User.new("login"=>"john", "password"=>"isjjna78a9h", "group_ids" => [groups_id(:admin)]) }
190
+ user = secure(User) { User.new("login"=>"john", "password"=>"isjjna78a9h", "group_ids" => [groups_id(:admin)]) }
131
191
  assert user.save
132
- user = secure!(User) { User.find(user[:id])}
192
+ user = secure(User) { User.find(user[:id])}
133
193
  assert_equal 3, user.groups.size
134
194
  end
135
195
 
@@ -146,13 +206,13 @@ class UserTest < Zena::Unit::TestCase
146
206
  def test_only_self_or_admin_can_update
147
207
  login(:tiger)
148
208
  user = secure!(User) { users(:ant) }
149
- user.email = "eat@spam.com"
209
+ user.lang = 'de'
150
210
  assert !user.save
151
211
  assert user.errors[:base] #.any?
152
212
  user = secure!(User) { users(:tiger) }
153
- user.email = "socr@isa.man"
213
+ user.lang = 'de'
154
214
  assert user.save
155
- assert_equal "socr@isa.man", user.email
215
+ assert_equal 'de', user.lang
156
216
  end
157
217
 
158
218
  def test_only_admin_can_create
@@ -290,14 +350,14 @@ class UserTest < Zena::Unit::TestCase
290
350
 
291
351
  def test_redactions
292
352
  login(:tiger)
293
- assert_equal ['opening'], visitor.redactions.map {|r| r.node.node_name}
353
+ assert_equal ['super ouverture'], visitor.redactions.map {|r| r.node.title}
294
354
  node = secure(Page) { Page.create(:title => 'hello', :parent_id => nodes_id(:projects)) }
295
355
  node.propose
296
- assert_equal ['hello'], visitor.to_publish.map {|r| r.node.node_name}
297
- assert_equal ['hello'], visitor.proposed.map {|r| r.node.node_name}
356
+ assert_equal ['hello'], visitor.to_publish.map {|r| r.node.title}
357
+ assert_equal ['hello'], visitor.proposed.map {|r| r.node.title}
298
358
 
299
359
  login(:lion)
300
- assert_equal ['hello'], visitor.to_publish.map {|r| r.node.node_name}
360
+ assert_equal ['hello'], visitor.to_publish.map {|r| r.node.title}
301
361
  end
302
362
 
303
363
  context 'Creating a new user' do
@@ -11,8 +11,8 @@ class VersionTest < Zena::Unit::TestCase
11
11
  end
12
12
 
13
13
  context 'receiving author' do
14
- should 'return a BaseContact' do
15
- assert_kind_of BaseContact, subject.author
14
+ should 'return a Node' do
15
+ assert_kind_of Node, subject.author
16
16
  end
17
17
 
18
18
  should 'return the contact node of the author' do
@@ -58,7 +58,7 @@ class VersionTest < Zena::Unit::TestCase
58
58
  context 'on node creation' do
59
59
  context 'setting an invalid v_lang' do
60
60
  setup do
61
- @node = secure!(Page) { Page.create(:v_lang => 'io', :parent_id => nodes_id(:status), :node_name => 'hello')}
61
+ @node = secure!(Page) { Page.create(:v_lang => 'io', :parent_id => nodes_id(:status), :title => 'hello')}
62
62
  end
63
63
 
64
64
  should 'not create record if lang is not allowed' do
@@ -72,7 +72,7 @@ class VersionTest < Zena::Unit::TestCase
72
72
 
73
73
  context 'setting a valid v_lang' do
74
74
  subject do
75
- @node = secure!(Page) { Page.create(:v_lang => 'de', :parent_id => nodes_id(:status), :node_name => 'hello')}
75
+ @node = secure!(Page) { Page.create(:v_lang => 'de', :parent_id => nodes_id(:status), :title => 'hello')}
76
76
  end
77
77
 
78
78
  should 'create a single version' do
@@ -6,7 +6,7 @@ class VirtualClassTest < Zena::Unit::TestCase
6
6
  def test_virtual_subclasse
7
7
  # add a sub class
8
8
  login(:lion)
9
- vclass = VirtualClass.create(:superclass => 'Post', :name => 'Super', :create_group_id => groups_id(:public))
9
+ vclass = VirtualClass.create(:superclass => 'Post', :name => 'Super', :create_group_id => groups_id(:public))
10
10
  assert !vclass.new_record?
11
11
  assert_equal "NNPS", vclass.kpath
12
12
  end
@@ -14,7 +14,7 @@ class VirtualClassTest < Zena::Unit::TestCase
14
14
  def test_node_classes_for_form
15
15
  login(:anon)
16
16
  # preload models
17
- [Project, Skin, Note, Image, Template, BaseContact]
17
+ [Project, Skin, Note, Image, Template]
18
18
 
19
19
  classes_for_form = Node.classes_for_form
20
20
  assert classes_for_form.include?(["Node", "Node"])
@@ -27,13 +27,14 @@ class VirtualClassTest < Zena::Unit::TestCase
27
27
  def test_note_classes_for_form
28
28
  login(:anon)
29
29
  # preload models
30
- [Project, Skin, Note, Image, Template, BaseContact]
30
+ [Project, Skin, Note, Image, Template]
31
31
 
32
32
  classes_for_form = Note.classes_for_form
33
33
  assert classes_for_form.include?(["Note", "Note"])
34
34
  assert classes_for_form.include?(["  Letter", "Letter"])
35
35
  assert classes_for_form.include?(["  Post", "Post"])
36
36
  classes_for_form.map!{|k,c| c}
37
+
37
38
  assert !classes_for_form.include?("Node")
38
39
  assert !classes_for_form.include?("Page")
39
40
  assert !classes_for_form.include?("Reference")
@@ -42,7 +43,7 @@ class VirtualClassTest < Zena::Unit::TestCase
42
43
  def test_post_classes_for_form
43
44
  # add a sub class
44
45
  login(:lion)
45
- vclass = VirtualClass.create(:superclass => 'Post', :name => 'Super', :create_group_id => groups_id(:public))
46
+ vclass = VirtualClass.create(:superclass => 'Post', :name => 'Super', :create_group_id => groups_id(:public))
46
47
  assert !vclass.new_record?
47
48
 
48
49
  login(:anon)
@@ -61,7 +62,7 @@ class VirtualClassTest < Zena::Unit::TestCase
61
62
  def test_post_classes_for_form_opt
62
63
  # add a sub class
63
64
  login(:lion)
64
- vclass = VirtualClass.create(:superclass => 'Post', :name => 'Super', :create_group_id => groups_id(:public))
65
+ vclass = VirtualClass.create(:superclass => 'Post', :name => 'Super', :create_group_id => groups_id(:public))
65
66
  assert !vclass.new_record?
66
67
 
67
68
  login(:anon)
@@ -80,12 +81,13 @@ class VirtualClassTest < Zena::Unit::TestCase
80
81
  def test_post_classes_for_form_opt
81
82
  # add a sub class
82
83
  login(:lion)
83
- vclass = VirtualClass.create(:superclass => 'Post', :name => 'Super', :create_group_id => groups_id(:public))
84
+ vclass = VirtualClass.create(:superclass => 'Post', :name => 'Super', :create_group_id => groups_id(:public))
84
85
  assert !vclass.new_record?
85
86
 
86
87
  login(:anon)
87
88
 
88
89
  classes_for_form = Node.classes_for_form(:class => 'Post', :without=>'Super')
90
+
89
91
  assert classes_for_form.include?(["Post", "Post"])
90
92
  classes_for_form.map!{|k,c| c}
91
93
  assert !classes_for_form.include?("Node")
@@ -99,7 +101,7 @@ class VirtualClassTest < Zena::Unit::TestCase
99
101
  def test_node_classes_for_form_except
100
102
  login(:anon)
101
103
  # preload models
102
- [Project, Skin, Note, Image, Template, BaseContact]
104
+ [Project, Skin, Note, Image, Template]
103
105
 
104
106
  classes_for_form = Node.classes_for_form(:without => 'Letter')
105
107
  assert classes_for_form.include?(["Node", "Node"])
@@ -149,19 +151,6 @@ class VirtualClassTest < Zena::Unit::TestCase
149
151
  assert_equal "NNL", node[:kpath]
150
152
  end
151
153
 
152
- def test_new_instance
153
- login(:ant)
154
- klass = roles(:Letter)
155
- assert node = secure!(Node) { klass.new_instance(:title => 'my letter', :parent_id => nodes_id(:cleanWater)) }
156
- assert node.save
157
- assert_kind_of Note, node
158
- assert !node.new_record?
159
- assert node.virtual_class
160
- assert_equal roles_id(:Letter), node.vclass_id
161
- assert_equal 'Letter', node.klass
162
- assert node.vkind_of?('Letter')
163
- assert_equal "NNL", node[:kpath]
164
- end
165
154
 
166
155
  def test_relation
167
156
  login(:ant)
@@ -175,9 +164,9 @@ class VirtualClassTest < Zena::Unit::TestCase
175
164
  end
176
165
 
177
166
  def test_superclass
178
- assert_equal Note, roles(:Post).superclass
179
- assert_equal Note, roles(:Letter).superclass
180
- assert_equal Page, roles(:Tracker).superclass
167
+ assert_equal VirtualClass['Note'], roles(:Post).superclass
168
+ assert_equal VirtualClass['Note'], roles(:Letter).superclass
169
+ assert_equal VirtualClass['Page'], roles(:Tracker).superclass
181
170
  end
182
171
 
183
172
  def test_new_conflict_virtual_kpath
@@ -198,17 +187,6 @@ class VirtualClassTest < Zena::Unit::TestCase
198
187
  assert_equal 'NPU', vclass.kpath
199
188
  end
200
189
 
201
- def test_update
202
- # add a sub class
203
- login(:lion)
204
- vclass = roles(:Post)
205
- assert_equal "reading, book", vclass.dyn_keys
206
- assert_equal "NNP", vclass.kpath
207
- assert vclass.update_attributes(:dyn_keys => 'foo, bar')
208
- assert_equal "foo, bar", vclass.dyn_keys
209
- assert_equal "NNP", vclass.kpath
210
- end
211
-
212
190
  def test_update_name
213
191
  # add a sub class
214
192
  login(:lion)
@@ -222,9 +200,9 @@ class VirtualClassTest < Zena::Unit::TestCase
222
200
  # add a sub class
223
201
  login(:lion)
224
202
  vclass = roles(:Post)
225
- assert_equal Note, vclass.superclass
203
+ assert_equal VirtualClass['Note'], vclass.superclass
226
204
  assert vclass.update_attributes(:superclass => 'Project')
227
- assert_equal Project, vclass.superclass
205
+ assert_equal VirtualClass['Project'], vclass.superclass
228
206
  assert_equal "NPPP", vclass.kpath
229
207
  end
230
208
 
@@ -233,6 +211,569 @@ class VirtualClassTest < Zena::Unit::TestCase
233
211
  assert roles(:Post).auto_create_discussion
234
212
  end
235
213
 
214
+ context 'Loading a virtual class' do
215
+ context 'with a kpath' do
216
+ subject do
217
+ VirtualClass['Post']
218
+ end
219
+
220
+ should 'return a virtual class' do
221
+ assert_kind_of VirtualClass, subject
222
+ assert_equal 'Post', subject.name
223
+ end
224
+
225
+ should 'cache found virtual class' do
226
+ assert_equal VirtualClass['Post'].object_id, subject.object_id
227
+ end
228
+
229
+ should 'return a loaded virtual class' do
230
+ assert_equal %w{assigned cached_role_ids date origin summary text title tz weight}, subject.column_names.sort
231
+ end
232
+
233
+ context 'related to a real class' do
234
+ subject do
235
+ VirtualClass.find_by_kpath('NN')
236
+ end
237
+
238
+ should 'return a virtual class' do
239
+ assert_kind_of VirtualClass, subject
240
+ assert_equal 'Note', subject.name
241
+ end
242
+
243
+ should 'return a loaded virtual class' do
244
+ assert_equal %w{assigned cached_role_ids origin summary text title tz weight}, subject.column_names.sort
245
+ end
246
+ end # related to a real class
247
+
248
+ end # with a kpath
249
+
250
+ context 'with an id' do
251
+ subject do
252
+ VirtualClass.find_by_id roles_id(:Post)
253
+ end
254
+
255
+ should 'return a virtual class' do
256
+ assert_kind_of VirtualClass, subject
257
+ assert_equal 'Post', subject.name
258
+ end
259
+
260
+ should 'cache found virtual class' do
261
+ assert_equal VirtualClass.find_by_id(roles_id(:Post)), subject
262
+ assert_equal VirtualClass['Post'].object_id, subject.object_id
263
+ end
264
+
265
+ should 'return a loaded virtual class' do
266
+ assert_equal %w{assigned cached_role_ids date origin summary text title tz weight}, subject.column_names.sort
267
+ end
268
+ end # with an id
269
+
270
+
271
+ context 'with a name' do
272
+ subject do
273
+ VirtualClass.find_by_name 'Post'
274
+ end
275
+
276
+ should 'return a virtual class' do
277
+ assert_kind_of VirtualClass, subject
278
+ assert_equal 'Post', subject.name
279
+ end
280
+
281
+ should 'cache found virtual class' do
282
+ assert_equal VirtualClass.find_by_id(roles_id(:Post)).object_id, subject.object_id
283
+ assert_equal VirtualClass['Post'].object_id, subject.object_id
284
+ end
285
+
286
+ should 'return a loaded virtual class' do
287
+ assert_equal %w{assigned cached_role_ids date origin summary text title tz weight}, subject.column_names.sort
288
+ end
289
+
290
+ context 'related to a real class' do
291
+ subject do
292
+ VirtualClass.find_by_name('Note')
293
+ end
294
+
295
+ should 'return a virtual class' do
296
+ assert_kind_of VirtualClass, subject
297
+ assert_equal 'Note', subject.name
298
+ end
299
+
300
+ should 'return a loaded virtual class' do
301
+ assert_equal %w{assigned cached_role_ids origin summary text title tz weight}, subject.column_names.sort
302
+ end
303
+ end # related to a real class
304
+ end # with a name
305
+
306
+ context 'from a node instance' do
307
+ subject do
308
+ nodes(:proposition)
309
+ end
310
+
311
+ should 'load from cache' do
312
+ assert_equal VirtualClass['Post'].object_id, subject.virtual_class.object_id
313
+ end
314
+
315
+ context 'that is not a virtual class instance' do
316
+ subject do
317
+ nodes(:projects)
318
+ end
319
+
320
+ should 'load from cache' do
321
+ assert_equal VirtualClass['Page'].object_id, subject.virtual_class.object_id
322
+ end
323
+ end # that is not a virtual class instance
324
+
325
+ end # from a node instance
326
+
327
+ end # Loading a virtual class
328
+
329
+ def self.should_clear_cache
330
+
331
+ should 'update roles_updated_at date' do
332
+ subject
333
+ date = current_site.roles_updated_at
334
+ assert_equal date.to_i, Site.find(current_site.id).roles_updated_at.to_i # to_i because of the precision in db
335
+ assert_kind_of Time, date
336
+ assert @before < current_site.roles_updated_at
337
+ end
338
+
339
+ should 'empty process cache' do
340
+ # in same process
341
+ subject
342
+ cache = VirtualClass.caches_by_site[current_site.id]
343
+ assert cache.instance_variable_get(:@cache_by_id).empty?
344
+ assert cache.instance_variable_get(:@cache_by_kpath).empty?
345
+ assert cache.instance_variable_get(:@cache_by_name).empty?
346
+ end
347
+
348
+ should 'mark cache' do
349
+ subject
350
+ # This is needed for other processes
351
+ assert @cache.stale?
352
+ end
353
+ end
354
+
355
+ def setup_cache_test
356
+ login(:lion)
357
+ Site.connection.execute 'UPDATE sites SET roles_updated_at = NULL'
358
+ # preload in cache
359
+ VirtualClass['Post'].column_names
360
+ @before = Time.now.utc
361
+ @cache = VirtualClass.caches_by_site[current_site.id]
362
+ end
363
+
364
+ context 'Creating a Role' do
365
+ setup do
366
+ setup_cache_test
367
+ end
368
+
369
+ subject do
370
+ role = VirtualClass.create(:name => 'Flop', :superclass => 'Note', :create_group_id => groups_id(:public))
371
+ err role
372
+ assert !role.new_record?
373
+ end
374
+
375
+ should_clear_cache
376
+
377
+ should 'load new role from cache' do
378
+ subject
379
+ assert_kind_of VirtualClass, VirtualClass.find_by_name('Flop')
380
+ end
381
+
382
+ end # Creating a Role
383
+
384
+ context 'Creating a Column' do
385
+ setup do
386
+ setup_cache_test
387
+ end
388
+
389
+ subject do
390
+ column = Column.create(:role_id => roles_id(:Original), :ptype => 'string', :name => 'foo')
391
+ err column
392
+ assert !column.new_record?
393
+ end
394
+
395
+ should_clear_cache
396
+
397
+ should 'load new role from cache' do
398
+ subject
399
+ # no more linked to assigned
400
+ assert_equal %w{assigned cached_role_ids date foo origin summary text title tz weight}, VirtualClass['Post'].column_names.sort
401
+ end
402
+
403
+ end # Creating a Column
404
+
405
+ context 'Updating a Role' do
406
+ setup do
407
+ setup_cache_test
408
+ end
409
+
410
+ subject do
411
+ assert roles(:Original).update_attributes(:superclass => 'Page')
412
+ end
413
+
414
+ should_clear_cache
415
+
416
+ should 'load new role from cache' do
417
+ subject
418
+ # no more linked to Original
419
+ assert_equal %w{assigned cached_role_ids date summary text title}, VirtualClass['Post'].column_names.sort
420
+ end
421
+
422
+ end # Updating a Role
423
+
424
+ context 'Updating a Column' do
425
+ setup do
426
+ setup_cache_test
427
+ end
428
+
429
+ subject do
430
+ assert columns(:Original_tz).update_attributes(:name => 'toz')
431
+ end
432
+
433
+ should_clear_cache
434
+
435
+ should 'load new role from cache' do
436
+ subject
437
+ # change name
438
+ assert_equal %w{assigned cached_role_ids date origin summary text title toz weight}, VirtualClass['Post'].column_names.sort
439
+ end
440
+
441
+ end # Updating a Column
442
+
443
+ context 'Deleting a Role' do
444
+ setup do
445
+ setup_cache_test
446
+ end
447
+
448
+ subject do
449
+ assert roles(:Original).destroy
450
+ end
451
+
452
+ should_clear_cache
453
+
454
+ should 'load new role from cache' do
455
+ subject
456
+ # no more linked to Original
457
+ assert_equal %w{assigned cached_role_ids date summary text title}, VirtualClass['Post'].column_names.sort
458
+ end
459
+
460
+ end # Deleting a Role
461
+
462
+ context 'Deleting a Column' do
463
+ setup do
464
+ setup_cache_test
465
+ end
466
+
467
+ subject do
468
+ assert columns(:Original_tz).destroy
469
+ end
470
+
471
+ should_clear_cache
472
+
473
+ should 'load new role from cache' do
474
+ subject
475
+ # no more linked to assigned
476
+ assert_equal %w{assigned cached_role_ids date origin summary text title weight}, VirtualClass['Post'].column_names.sort
477
+ end
478
+
479
+ end # Deleting a Column
480
+
481
+ context 'Finding all classes' do
482
+ subject do
483
+ VirtualClass.all_classes
484
+ end
485
+
486
+ context 'without base or filter' do
487
+ should 'load all classes' do
488
+ assert_equal %w{N ND NDI NDT NDTT NN NNL NNP NP NPA NPP NPPB NPS NPSS NPT NR NRC}, subject.map(&:kpath).reject{|k| k =~ /\ANU|\ANDD/}.sort
489
+ end
490
+ end # without base or filter
491
+
492
+ context 'with a base' do
493
+ subject do
494
+ VirtualClass.all_classes('ND')
495
+ end
496
+
497
+ should 'load sub classes and self' do
498
+ VirtualClass.expire_cache!
499
+ assert_equal %w{ND NDI NDT NDTT}, subject.map(&:kpath).sort.reject{|k| k == 'NDD'} # test leakage
500
+ end
501
+ end # with a base
502
+
503
+ context 'with a filter' do
504
+ subject do
505
+ VirtualClass.all_classes('N', 'Document')
506
+ end
507
+
508
+ should 'description' do
509
+ assert_equal %w{N NN NNL NNP NP NPA NPP NPPB NPS NPSS NPT NR NRC}, subject.map(&:kpath).reject{|k| k =~ /\ANU/}.sort
510
+ end
511
+ end # with a filter
512
+
513
+ end # Finding all classes
514
+
515
+ context 'A Document vclass' do
516
+ context 'on new_instance' do
517
+ subject do
518
+ VirtualClass['Document'].new_instance(
519
+ :parent_id => nodes_id(:cleanWater),
520
+ :file => uploaded_jpg('bird.jpg')
521
+ )
522
+ end
523
+
524
+ should 'select class from content type' do
525
+ assert_kind_of Image, subject
526
+ end
527
+ end # on new_instance
528
+ end # A Document vclass
529
+
530
+ context 'A vclass' do
531
+ context 'of a real class' do
532
+ subject do
533
+ VirtualClass['Page']
534
+ end
535
+
536
+ should 'return true on real_class?' do
537
+ assert subject.real_class?
538
+ end
539
+
540
+ should 'return super vclass' do
541
+ assert_equal VirtualClass['Node'], subject.superclass
542
+ end
543
+
544
+ should 'return safe column types' do
545
+ assert_equal %w{assigned origin summary text title tz weight}, subject.safe_column_types.keys.sort
546
+ end
547
+
548
+ should 'return nil on unsafe method type' do
549
+ assert_nil subject.safe_method_type(['cached_role_ids'])
550
+ end
551
+
552
+ should 'return type on safe method type' do
553
+ assert_equal Hash[:class => String, :nil => true, :method => "prop['title']"], subject.safe_method_type(['title'])
554
+ end
555
+
556
+ should 'return list of roles' do
557
+ assert_equal %w{Node Original Task}, subject.sorted_roles.map(&:name)
558
+ end
559
+
560
+ context 'that is a Node' do
561
+ subject do
562
+ VirtualClass['Node']
563
+ end
564
+
565
+ should 'return Node on super vclass' do
566
+ assert_equal Node, subject.superclass
567
+ end
568
+
569
+ should 'return safe columns' do
570
+ assert_equal %w{summary text title assigned origin tz weight}, subject.safe_columns.map(&:name)
571
+ end
572
+
573
+ should 'return defined safe columns' do
574
+ assert_equal %w{summary text title}, subject.defined_safe_columns.map(&:name)
575
+ end
576
+
577
+ should 'return safe column types' do
578
+ assert_equal %w{assigned origin summary text title tz weight}, subject.safe_column_types.keys.sort
579
+ end
580
+
581
+ should 'not include unsafe properties in safe column types' do
582
+ unsafe_prop = 'cached_role_ids'
583
+ assert subject.columns[unsafe_prop]
584
+ assert !subject.safe_column_types[unsafe_prop]
585
+ end
586
+
587
+ should 'return list of roles' do
588
+ assert_equal %w{Node Original Task}, subject.sorted_roles.map(&:name)
589
+ end
590
+ end
591
+ end # of a real class
592
+
593
+
594
+ context 'of a virtual class' do
595
+ subject do
596
+ VirtualClass['Post']
597
+ end
598
+
599
+ should 'return false on real_class?' do
600
+ assert !subject.real_class?
601
+ end
602
+
603
+ should 'return safe columns' do
604
+ assert_equal %w{summary text title assigned origin tz weight date}, subject.safe_columns.map(&:name)
605
+ end
606
+
607
+ should 'return defined safe columns' do
608
+ assert_equal %w{date}, subject.defined_safe_columns.map(&:name)
609
+ end
610
+
611
+ should 'return safe column types' do
612
+ assert_equal %w{assigned date origin summary text title tz weight}, subject.safe_column_types.keys.sort
613
+ end
614
+
615
+ should 'return type on safe method type' do
616
+ assert_equal Hash[:class => String, :nil => true, :method => "prop['title']"], subject.safe_method_type(['title'])
617
+ assert_equal Hash[:class => Time, :nil => true, :method => "prop['date']"], subject.safe_method_type(['date'])
618
+ end
619
+
620
+ should 'return type of ruby method on safe method type' do
621
+ assert_equal Hash[:class => Time, :nil => true, :method => "created_at"], subject.safe_method_type(['created_at'])
622
+ end
623
+
624
+ should 'return list of roles' do
625
+ assert_equal %w{Node Original Task Post}, subject.sorted_roles.map(&:name)
626
+ end
627
+ end # of a virtual class
628
+
629
+
630
+ context 'on all_relations' do
631
+ subject do
632
+ VirtualClass['Letter'].all_relations
633
+ end
634
+
635
+ should 'return a list of relation proxies' do
636
+ assert_kind_of RelationProxy, subject.first
637
+ end
638
+
639
+ should 'return a list of relation names when mapped with other_role' do
640
+ assert subject.map(&:other_role).include?('icon')
641
+ end
642
+ end # on relations
643
+
644
+
645
+ context 'on filtered_relations' do
646
+ subject do
647
+ VirtualClass['Letter'].filtered_relations('doc')
648
+ end
649
+
650
+ should 'filter relation proxies' do
651
+ assert_kind_of RelationProxy, subject.first
652
+ end
653
+
654
+ should 'return a list of relation names on other_role' do
655
+ assert_equal %w{reference reference_for set_tag}, subject.map(&:other_role).sort
656
+ end
657
+ end # on relations
658
+
659
+ context 'on new_instance' do
660
+ subject do
661
+ VirtualClass['Letter'].new_instance(
662
+ :parent_id => nodes_id(:cleanWater),
663
+ :title => 'lambda'
664
+ )
665
+ end
666
+
667
+ should 'use real_class' do
668
+ assert_kind_of Note, subject
669
+ end
670
+
671
+ should 'set virtual class' do
672
+ assert_equal VirtualClass['Letter'].object_id, subject.vclass.object_id
673
+ end
674
+ end # on new_instance
675
+ end # A note vclass
676
+
677
+ context 'A virtual class' do
678
+ subject do
679
+ VirtualClass['Post']
680
+ end
681
+
682
+ should 'respond to less or equal then' do
683
+ assert subject <= Note
684
+ assert subject <= Node
685
+ assert subject <= VirtualClass['Note']
686
+ assert !(subject <= Project)
687
+ end
688
+
689
+ should 'respond to less then' do
690
+ assert subject < Note
691
+ assert subject < Node
692
+ assert subject < VirtualClass['Note']
693
+ assert !(subject < Project)
694
+ assert !(subject < VirtualClass['Post'])
695
+ end
696
+
697
+ should 'consider role methods as safe' do
698
+ assert_equal Hash[:class=>String, :method=>"prop['assigned']", :nil=>true], subject.safe_method_type(['assigned'])
699
+ end
700
+ end # A virtual class
701
+
702
+ context 'A visitor with write access' do
703
+ setup do
704
+ login(:tiger)
705
+ end
706
+
707
+ context 'on a node' do
708
+ context 'from a class with roles' do
709
+ subject do
710
+ secure(Node) { nodes(:letter) }
711
+ end
712
+
713
+ should 'use method missing to assign properties' do
714
+ assert_nothing_raised do
715
+ subject.assigned = 'flat Eric'
716
+ end
717
+ end
718
+
719
+ should 'use property filter on set attributes' do
720
+ assert_nothing_raised do
721
+ subject.attributes = {'assigned' => 'flat Eric'}
722
+ end
723
+ end
724
+
725
+ should 'accept properties' do
726
+ subject.properties = {'assigned' => 'flat Eric'}
727
+ assert subject.save
728
+ assert_equal 'flat Eric', subject.assigned
729
+ end
730
+
731
+ should 'use property filter on update_attributes' do
732
+ assert_nothing_raised do
733
+ assert subject.update_attributes('assigned' => 'flat Eric', 'origin' => '2D')
734
+ end
735
+ end
736
+
737
+ should 'accept properties in update_attributes' do
738
+ assert_nothing_raised do
739
+ assert subject.update_attributes('properties' => {'assigned' => 'flat Eric'})
740
+ assert_equal 'flat Eric', subject.assigned
741
+ end
742
+ end
743
+
744
+ should 'consider role methods as safe' do
745
+ assert_equal Hash[:class=>String, :method=>"prop['paper']", :nil=>true], subject.safe_method_type(['paper'])
746
+ end
747
+
748
+ should 'not consider VirtualClass own methods as safe' do
749
+ assert_nil subject.safe_method_type(['name'])
750
+ end
751
+
752
+ should 'not allow arbitrary attributes' do
753
+ assert !subject.update_attributes('assigned' => 'flat Eric', 'bad' => 'property')
754
+ end
755
+
756
+ should 'not raise on bad attributes' do
757
+ assert_nothing_raised do
758
+ subject.attributes = {'elements' => 'Statistical Learning'}
759
+ end
760
+ end
761
+
762
+ should 'add an error on first bad attributes' do
763
+ subject.attributes = {'elements' => 'Statistical Learning'}
764
+ assert !subject.save
765
+ assert_equal 'property not declared', subject.errors[:elements]
766
+ end
767
+
768
+ should 'not allow property bypassing' do
769
+ assert !subject.update_attributes('properties' => {'bad' => 'property'})
770
+ assert_equal 'property not declared', subject.errors[:bad]
771
+ end
772
+
773
+ end # from a class with roles
774
+ end # on a node
775
+ end # A visitor with write access
776
+
236
777
  context 'importing virtual class definitions' do
237
778
  setup do
238
779
  login(:lion)