spontaneous 0.2.0.beta1 → 0.2.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (335) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/.locat +42 -0
  4. data/.travis/gemfiles/Gemfile.empty +7 -0
  5. data/.travis.yml +18 -0
  6. data/Gemfile +12 -8
  7. data/LICENSE +1 -1
  8. data/Rakefile +15 -157
  9. data/Readme.markdown +1 -1
  10. data/application/css/core.css.scss +22 -146
  11. data/application/css/definitions.css.scss +7 -3
  12. data/application/css/dialogue.css.scss +26 -1
  13. data/application/css/editing.css.scss +70 -28
  14. data/application/css/font.css.scss +1 -1
  15. data/application/css/popover.css.scss +2 -0
  16. data/application/css/top.css.scss +231 -0
  17. data/application/js/add_alias_dialogue.js +1 -1
  18. data/application/js/add_home_dialogue.js +1 -1
  19. data/application/js/ajax.js +61 -31
  20. data/application/js/box.js +4 -4
  21. data/application/js/conflicted_field_dialogue.js +1 -1
  22. data/application/js/content.js +5 -5
  23. data/application/js/dom.js +5 -0
  24. data/application/js/edit_panel.js +1 -0
  25. data/application/js/editing.js +1 -1
  26. data/application/js/extensions.js +8 -0
  27. data/application/js/field/boolean.js +31 -0
  28. data/application/js/field/file.js +32 -4
  29. data/application/js/field/image.js +24 -9
  30. data/application/js/field/markdown.js +87 -59
  31. data/application/js/field/select.js +1 -1
  32. data/application/js/field/webvideo.js +6 -1
  33. data/application/js/init.js +2 -2
  34. data/application/js/jquery-selection-position.js +130 -0
  35. data/application/js/location.js +4 -25
  36. data/application/js/meta_view/user_admin.js +2 -2
  37. data/application/js/metadata.js +2 -2
  38. data/application/js/page_browser.js +1 -1
  39. data/application/js/panel/root_menu.js +0 -1
  40. data/application/js/popover.js +27 -12
  41. data/application/js/popover_view.js +20 -4
  42. data/application/js/preview.js +31 -16
  43. data/application/js/progress.js +22 -21
  44. data/application/js/publish.js +18 -7
  45. data/application/js/sharded_upload.js +9 -6
  46. data/application/js/spontaneous.js +3 -1
  47. data/application/js/top_bar.js +264 -173
  48. data/application/js/upload.js +12 -5
  49. data/application/js/upload_manager.js +4 -3
  50. data/application/js/user.js +1 -2
  51. data/application/js/views/box_view.js +1 -1
  52. data/application/js/views/page_view.js +16 -5
  53. data/application/js/views/piece_view.js +5 -4
  54. data/application/static/font/fontawesome-webfont-1c66a4738b40ef0f6b1abca0ba9a796d.ttf +0 -0
  55. data/application/views/index.erb +6 -14
  56. data/application/views/login.erb +6 -25
  57. data/application/views/schema_modification_error.html.erb +3 -7
  58. data/db/migrations/20130114120000_create_revision_tables.rb +2 -2
  59. data/db/migrations/20130813111009_increase_path_length.rb +14 -0
  60. data/gem-public_cert.pem +20 -0
  61. data/lib/spontaneous/asset/app_compiler.rb +44 -0
  62. data/lib/spontaneous/asset/environment.rb +225 -0
  63. data/lib/spontaneous/asset.rb +2 -67
  64. data/lib/spontaneous/box.rb +0 -1
  65. data/lib/spontaneous/capistrano/deploy.rb +2 -2
  66. data/lib/spontaneous/capistrano/sync.rb +1 -1
  67. data/lib/spontaneous/cli/init.rb +36 -13
  68. data/lib/spontaneous/cli/server.rb +0 -1
  69. data/lib/spontaneous/cli/site.rb +2 -1
  70. data/lib/spontaneous/cli.rb +3 -1
  71. data/lib/spontaneous/collections/entry_set.rb +4 -12
  72. data/lib/spontaneous/collections/hash_with_fallback.rb +20 -0
  73. data/lib/spontaneous/collections/prototype_set.rb +6 -5
  74. data/lib/spontaneous/crypt.rb +2 -2
  75. data/lib/spontaneous/data_mapper/content_model/associations.rb +115 -63
  76. data/lib/spontaneous/data_mapper.rb +1 -1
  77. data/lib/spontaneous/errors.rb +6 -0
  78. data/lib/spontaneous/extensions/object_space.rb +6 -0
  79. data/lib/spontaneous/facet.rb +1 -0
  80. data/lib/spontaneous/field/base.rb +86 -13
  81. data/lib/spontaneous/field/boolean.rb +65 -0
  82. data/lib/spontaneous/field/file.rb +17 -6
  83. data/lib/spontaneous/field/html.rb +13 -0
  84. data/lib/spontaneous/field/image/size.rb +76 -0
  85. data/lib/spontaneous/field/image.rb +99 -414
  86. data/lib/spontaneous/field/tags.rb +36 -0
  87. data/lib/spontaneous/field/update.rb +1 -1
  88. data/lib/spontaneous/field/webvideo/fallback.rb +41 -0
  89. data/lib/spontaneous/field/webvideo/vimeo.rb +113 -0
  90. data/lib/spontaneous/field/webvideo/vine.rb +94 -0
  91. data/lib/spontaneous/field/webvideo/youtube.rb +133 -0
  92. data/lib/spontaneous/field/webvideo.rb +100 -250
  93. data/lib/spontaneous/field.rb +1 -1
  94. data/lib/spontaneous/generators/site/Gemfile.tt +5 -14
  95. data/lib/spontaneous/generators/site/assets/README.md +20 -0
  96. data/lib/spontaneous/generators/site/assets/css/site.scss +8 -0
  97. data/lib/spontaneous/generators/site/assets/js/site.js +6 -0
  98. data/lib/spontaneous/generators/site/config/deploy.rb.tt +9 -0
  99. data/lib/spontaneous/generators/site/config/user_levels.yml +14 -3
  100. data/lib/spontaneous/generators/site/public/README.md +12 -0
  101. data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +2 -2
  102. data/lib/spontaneous/generators/site.rb +77 -35
  103. data/lib/spontaneous/layout.rb +6 -7
  104. data/lib/spontaneous/loader.rb +21 -13
  105. data/lib/spontaneous/media/file.rb +22 -9
  106. data/lib/spontaneous/media/image/attributes.rb +33 -0
  107. data/lib/spontaneous/media/image/format/gif.rb +4 -0
  108. data/lib/spontaneous/media/image/format/jpg.rb +17 -0
  109. data/lib/spontaneous/media/image/format/png.rb +4 -0
  110. data/lib/spontaneous/media/image/format/webp.rb +26 -0
  111. data/lib/spontaneous/media/image/format.rb +79 -0
  112. data/lib/spontaneous/media/image/optimizer.rb +69 -0
  113. data/lib/spontaneous/media/image/processor.rb +17 -0
  114. data/lib/spontaneous/media/image/renderable.rb +52 -0
  115. data/lib/spontaneous/media/image/skeptick.rb +70 -0
  116. data/lib/spontaneous/media/image.rb +50 -0
  117. data/lib/spontaneous/media/temp_file.rb +4 -0
  118. data/lib/spontaneous/media.rb +1 -0
  119. data/lib/spontaneous/model/core/aliases.rb +14 -8
  120. data/lib/spontaneous/model/core/boxes.rb +5 -2
  121. data/lib/spontaneous/model/core/entries.rb +4 -0
  122. data/lib/spontaneous/model/core/entry.rb +1 -0
  123. data/lib/spontaneous/model/core/fields.rb +5 -2
  124. data/lib/spontaneous/model/core/locks.rb +16 -0
  125. data/lib/spontaneous/model/core/media.rb +1 -15
  126. data/lib/spontaneous/model/core.rb +31 -1
  127. data/lib/spontaneous/model/page/controllers.rb +2 -2
  128. data/lib/spontaneous/model/page/formats.rb +1 -4
  129. data/lib/spontaneous/model/page/layouts.rb +6 -2
  130. data/lib/spontaneous/model/page/locks.rb +8 -2
  131. data/lib/spontaneous/model/page/page_tree.rb +2 -2
  132. data/lib/spontaneous/model/page/paths.rb +74 -9
  133. data/lib/spontaneous/model/page.rb +11 -3
  134. data/lib/spontaneous/model.rb +6 -6
  135. data/lib/spontaneous/output/context/render_cache.rb +23 -0
  136. data/lib/spontaneous/output/context.rb +56 -30
  137. data/lib/spontaneous/output/helpers/script_helper.rb +9 -53
  138. data/lib/spontaneous/output/helpers/stylesheet_helper.rb +8 -40
  139. data/lib/spontaneous/output/template/renderer.rb +17 -5
  140. data/lib/spontaneous/output.rb +0 -1
  141. data/lib/spontaneous/paths.rb +6 -2
  142. data/lib/spontaneous/permissions/access_key.rb +18 -0
  143. data/lib/spontaneous/permissions/user.rb +1 -1
  144. data/lib/spontaneous/permissions.rb +4 -1
  145. data/lib/spontaneous/plugins/application/state.rb +19 -12
  146. data/lib/spontaneous/prototypes/field_prototype.rb +14 -8
  147. data/lib/spontaneous/published_revision.rb +7 -0
  148. data/lib/spontaneous/publishing/immediate.rb +43 -34
  149. data/lib/spontaneous/publishing/revision.rb +9 -6
  150. data/lib/spontaneous/rack/asset_server.rb +20 -0
  151. data/lib/spontaneous/rack/back/alias.rb +46 -0
  152. data/lib/spontaneous/rack/back/application_assets.rb +28 -0
  153. data/lib/spontaneous/rack/back/base.rb +34 -0
  154. data/lib/spontaneous/rack/back/changes.rb +19 -0
  155. data/lib/spontaneous/rack/back/content.rb +54 -0
  156. data/lib/spontaneous/rack/back/events.rb +38 -0
  157. data/lib/spontaneous/rack/back/field.rb +37 -0
  158. data/lib/spontaneous/rack/back/file.rb +118 -0
  159. data/lib/spontaneous/rack/back/helpers.rb +71 -0
  160. data/lib/spontaneous/rack/back/index.rb +16 -0
  161. data/lib/spontaneous/rack/back/login.rb +47 -0
  162. data/lib/spontaneous/rack/back/map.rb +24 -0
  163. data/lib/spontaneous/rack/back/page.rb +46 -0
  164. data/lib/spontaneous/rack/back/preview.rb +43 -0
  165. data/lib/spontaneous/rack/back/schema.rb +30 -0
  166. data/lib/spontaneous/rack/back/site.rb +25 -0
  167. data/lib/spontaneous/rack/back/site_assets.rb +13 -0
  168. data/lib/spontaneous/rack/back/unsupported_browser.rb +7 -0
  169. data/lib/spontaneous/rack/{user_admin.rb → back/user_admin.rb} +2 -5
  170. data/lib/spontaneous/rack/back.rb +85 -764
  171. data/lib/spontaneous/rack/cacheable_file.rb +3 -3
  172. data/lib/spontaneous/rack/front.rb +16 -9
  173. data/lib/spontaneous/rack/middleware/authenticate.rb +65 -0
  174. data/lib/spontaneous/rack/middleware/csrf.rb +66 -0
  175. data/lib/spontaneous/rack/middleware/reloader.rb +52 -0
  176. data/lib/spontaneous/rack/middleware/scope.rb +60 -0
  177. data/lib/spontaneous/rack/middleware.rb +6 -0
  178. data/lib/spontaneous/rack/page_controller.rb +18 -5
  179. data/lib/spontaneous/rack/public.rb +17 -11
  180. data/lib/spontaneous/rack.rb +34 -24
  181. data/lib/spontaneous/revision.rb +29 -2
  182. data/lib/spontaneous/schema/uid.rb +4 -3
  183. data/lib/spontaneous/schema/uid_map.rb +5 -24
  184. data/lib/spontaneous/schema.rb +1 -0
  185. data/lib/spontaneous/search/database.rb +8 -0
  186. data/lib/spontaneous/search/field.rb +1 -1
  187. data/lib/spontaneous/search/index.rb +3 -5
  188. data/lib/spontaneous/server.rb +1 -1
  189. data/lib/spontaneous/simultaneous.rb +1 -1
  190. data/lib/spontaneous/site/features.rb +4 -5
  191. data/lib/spontaneous/site/helpers.rb +22 -5
  192. data/lib/spontaneous/site/instance.rb +2 -2
  193. data/lib/spontaneous/site/selectors.rb +22 -3
  194. data/lib/spontaneous/storage/cloud.rb +13 -9
  195. data/lib/spontaneous/storage/local.rb +11 -6
  196. data/lib/spontaneous/style.rb +40 -23
  197. data/lib/spontaneous/utils/database/mysql_dumper.rb +1 -1
  198. data/lib/spontaneous/utils/smush_it.rb +1 -1
  199. data/lib/spontaneous/version.rb +1 -1
  200. data/lib/spontaneous.rb +35 -33
  201. data/spontaneous.gemspec +53 -787
  202. data/test/experimental/test_crypt.rb +56 -56
  203. data/test/experimental/test_features.rb +16 -27
  204. data/test/fixtures/assets/public1/css/data.css.scss +3 -0
  205. data/test/fixtures/assets/public1/css/image1.css.scss +4 -0
  206. data/test/fixtures/assets/public1/css/import.css.scss +1 -0
  207. data/test/fixtures/assets/public1/css/urlhash.css.scss +3 -0
  208. data/test/fixtures/assets/public1/js/a.js +1 -1
  209. data/test/fixtures/assets/public1/js/all.js +4 -0
  210. data/test/fixtures/assets/public1/js/{m.coffee → m.js.coffee} +1 -0
  211. data/test/fixtures/assets/public1/x.js +1 -0
  212. data/test/fixtures/assets/public2/css/all.css +4 -0
  213. data/test/fixtures/assets/public2/css/missing.css.scss +3 -0
  214. data/test/fixtures/assets/public2/i/y.png +0 -0
  215. data/test/fixtures/assets/public2/js/b.js +1 -1
  216. data/test/fixtures/assets/public2/js/c.js +1 -1
  217. data/test/fixtures/images/size.extended.webp +0 -0
  218. data/test/fixtures/images/size.lossless.webp +0 -0
  219. data/test/fixtures/images/size.lossy.webp +0 -0
  220. data/test/fixtures/schema/before.yml +4 -4
  221. data/test/fixtures/schema/schema.yml +1 -1
  222. data/test/fixtures/templates/aliases/aaa.html.cut +0 -0
  223. data/test/fixtures/templates/extended/partial_with_renderer.html.cut +1 -0
  224. data/test/fixtures/templates/extended/with_includes_and_renderer.html.cut +2 -0
  225. data/test/functional/test_application.rb +108 -106
  226. data/test/functional/test_back.rb +924 -930
  227. data/test/functional/test_front.rb +285 -238
  228. data/test/functional/test_user_manager.rb +75 -100
  229. data/test/integration/test_installation.rb +1 -1
  230. data/test/support/matchers.rb +12 -0
  231. data/test/support/minitest.rb +121 -0
  232. data/test/support/rack.rb +45 -0
  233. data/test/support/test_start_finish.rb +103 -0
  234. data/test/test_helper.rb +21 -68
  235. data/test/test_integration_helper.rb +1 -3
  236. data/test/unit/test_alias.rb +432 -408
  237. data/test/unit/test_asset_bundler.rb +58 -58
  238. data/test/unit/test_assets.rb +485 -155
  239. data/test/unit/test_async.rb +16 -37
  240. data/test/unit/test_authentication.rb +425 -457
  241. data/test/unit/test_boxes.rb +191 -191
  242. data/test/unit/test_changesets.rb +244 -254
  243. data/test/unit/test_config.rb +128 -142
  244. data/test/unit/test_content.rb +313 -359
  245. data/test/unit/test_content_inheritance.rb +29 -30
  246. data/test/unit/test_datamapper.rb +1205 -1080
  247. data/test/unit/test_datamapper_content.rb +49 -51
  248. data/test/unit/test_extensions.rb +23 -23
  249. data/test/unit/test_fields.rb +1488 -1180
  250. data/test/unit/test_formats.rb +158 -158
  251. data/test/unit/test_generators.rb +98 -40
  252. data/test/unit/test_helpers.rb +73 -76
  253. data/test/unit/test_image_size.rb +53 -22
  254. data/test/unit/test_images.rb +164 -165
  255. data/test/unit/test_layouts.rb +133 -122
  256. data/test/unit/test_logger.rb +14 -17
  257. data/test/unit/test_media.rb +69 -84
  258. data/test/unit/test_modifications.rb +513 -525
  259. data/test/unit/test_page.rb +462 -361
  260. data/test/unit/test_permissions.rb +379 -364
  261. data/test/unit/test_piece.rb +67 -75
  262. data/test/unit/test_plugins.rb +82 -89
  263. data/test/unit/test_prototype_set.rb +215 -216
  264. data/test/unit/test_prototypes.rb +114 -124
  265. data/test/unit/test_publishing.rb +252 -289
  266. data/test/unit/test_render.rb +167 -115
  267. data/test/unit/test_revisions.rb +436 -444
  268. data/test/unit/test_schema.rb +339 -309
  269. data/test/unit/test_search.rb +577 -574
  270. data/test/unit/test_serialisation.rb +136 -147
  271. data/test/unit/test_site.rb +252 -227
  272. data/test/unit/test_skeptick.rb +130 -0
  273. data/test/unit/test_storage.rb +46 -40
  274. data/test/unit/test_structure.rb +57 -66
  275. data/test/unit/test_styles.rb +104 -104
  276. data/test/unit/test_templates.rb +72 -57
  277. data/test/unit/test_type_hierarchy.rb +15 -16
  278. data/test/unit/test_visibility.rb +239 -257
  279. metadata +455 -326
  280. data/application/js/vendor/JS.Class-2.1.5/CHANGELOG +0 -283
  281. data/application/js/vendor/JS.Class-2.1.5/MIT-LICENSE +0 -30
  282. data/application/js/vendor/JS.Class-2.1.5/README +0 -30
  283. data/application/js/vendor/JS.Class-2.1.5/min/command.js +0 -1
  284. data/application/js/vendor/JS.Class-2.1.5/min/comparable.js +0 -1
  285. data/application/js/vendor/JS.Class-2.1.5/min/constant_scope.js +0 -1
  286. data/application/js/vendor/JS.Class-2.1.5/min/decorator.js +0 -1
  287. data/application/js/vendor/JS.Class-2.1.5/min/enumerable.js +0 -1
  288. data/application/js/vendor/JS.Class-2.1.5/min/forwardable.js +0 -1
  289. data/application/js/vendor/JS.Class-2.1.5/min/hash.js +0 -1
  290. data/application/js/vendor/JS.Class-2.1.5/min/linked_list.js +0 -1
  291. data/application/js/vendor/JS.Class-2.1.5/min/loader.js +0 -1
  292. data/application/js/vendor/JS.Class-2.1.5/min/method_chain.js +0 -1
  293. data/application/js/vendor/JS.Class-2.1.5/min/observable.js +0 -1
  294. data/application/js/vendor/JS.Class-2.1.5/min/package.js +0 -1
  295. data/application/js/vendor/JS.Class-2.1.5/min/proxy.js +0 -1
  296. data/application/js/vendor/JS.Class-2.1.5/min/ruby.js +0 -1
  297. data/application/js/vendor/JS.Class-2.1.5/min/set.js +0 -1
  298. data/application/js/vendor/JS.Class-2.1.5/min/stack_trace.js +0 -1
  299. data/application/js/vendor/JS.Class-2.1.5/min/state.js +0 -1
  300. data/application/js/vendor/JS.Class-2.1.5/min/stdlib.js +0 -16
  301. data/application/js/vendor/jquery-1.6.2.min.js +0 -18
  302. data/application/js/vendor/jquery-ui-1.8.16.custom.min.js +0 -791
  303. data/application/js/vendor/jquery-ui-1.8.9.custom.min.js +0 -415
  304. data/application/static/font/fontawesome-webfont-5c5c21100a346972a82c34c5e96ffcfe.ttf +0 -0
  305. data/application/static/select-arrow-6e7dd3745b00e934b0d7a3250c46558b.png +0 -0
  306. data/bin/limit-upload +0 -5
  307. data/bin/unlimit-upload +0 -3
  308. data/lib/spontaneous/asset/file.rb +0 -25
  309. data/lib/spontaneous/asset/source.rb +0 -28
  310. data/lib/spontaneous/image_size.rb +0 -123
  311. data/lib/spontaneous/output/assets/compression.rb +0 -58
  312. data/lib/spontaneous/output/assets.rb +0 -32
  313. data/lib/spontaneous/rack/around_back.rb +0 -20
  314. data/lib/spontaneous/rack/around_front.rb +0 -27
  315. data/lib/spontaneous/rack/around_preview.rb +0 -22
  316. data/lib/spontaneous/rack/assets.rb +0 -126
  317. data/lib/spontaneous/rack/authentication.rb +0 -20
  318. data/lib/spontaneous/rack/cookie_authentication.rb +0 -38
  319. data/lib/spontaneous/rack/helpers.rb +0 -52
  320. data/lib/spontaneous/rack/http.rb +0 -18
  321. data/lib/spontaneous/rack/media.rb +0 -30
  322. data/lib/spontaneous/rack/query_authentication.rb +0 -35
  323. data/lib/spontaneous/rack/reloader.rb +0 -45
  324. data/lib/spontaneous/rack/user_helpers.rb +0 -28
  325. /data/{README → application/js/field/markdown/text_command.js} +0 -0
  326. /data/application/js/vendor/{JS.Class-2.1.5/min/core.js → js.class-2.1.5.min.js} +0 -0
  327. /data/test/fixtures/assets/public1/css/{a.scss → a.css.scss} +0 -0
  328. /data/{lib/spontaneous/generators/site/public/css/site.scss → test/fixtures/assets/public1/x.css} +0 -0
  329. /data/{lib/spontaneous/generators/site/public/js/.empty_directory → test/fixtures/assets/public1/x.png} +0 -0
  330. /data/test/fixtures/assets/public2/css/{b.scss → b.css.scss} +0 -0
  331. /data/test/fixtures/assets/public2/js/{n.coffee → n.js.coffee} +0 -0
  332. /data/test/fixtures/back/{public → assets}/css/sass_include.scss +0 -0
  333. /data/test/fixtures/back/{public → assets}/css/sass_template.scss +0 -0
  334. /data/test/fixtures/back/{public → assets}/js/coffeescript.coffee +0 -0
  335. /data/{lib/spontaneous/generators/site/public/js/site.js → test/fixtures/templates/aliases/aa_alias.html.cut} +0 -0
@@ -2,7 +2,7 @@
2
2
 
3
3
  require File.expand_path('../../test_helper', __FILE__)
4
4
 
5
- class SearchTest < MiniTest::Spec
5
+ describe "Search" do
6
6
 
7
7
  # search should be defined by DSL
8
8
  # DSL should
@@ -23,673 +23,676 @@ class SearchTest < MiniTest::Spec
23
23
  #
24
24
  # - Indexing is done by page
25
25
 
26
-
27
-
28
- def self.startup
29
- # make sure that S::Piece & S::Page are removed from the schema
30
- # setup_site
31
- # *ids = S::Page.schema_id, S::Piece.schema_id
32
- # Object.const_set(:Site, Class.new(S::Site))
33
- end
34
-
35
- def self.shutdown
36
- # Object.send(:remove_const, :Site) rescue nil
37
- end
38
-
39
- def setup
26
+ before do
40
27
  @site = setup_site
28
+ Content.delete
29
+
30
+
31
+ # class ::Piece < S::Piece; end
32
+ # class ::Page < S::Page; end
33
+ b = ::Page.box :pages
34
+ # instantiate box instance class to it gets added to schema
35
+ ::Page.boxes.pages.instance_class.schema_id
36
+
37
+ class ::PageClass1 < ::Page; end
38
+ class ::PageClass2 < ::Page; end
39
+ class ::PageClass3 < ::PageClass1; end
40
+ class ::PageClass4 < ::PageClass2; end
41
+ class ::PageClass5 < ::PageClass3; end
42
+ class ::PageClass6 < ::PageClass5; end
43
+
44
+ class ::PieceClass1 < ::Piece; end
45
+ class ::PieceClass2 < ::Piece; end
46
+ class ::PieceClass3 < ::Piece; end
47
+
48
+ @all_page_classes = [::Page, ::PageClass1, ::PageClass2, ::PageClass3, ::PageClass4, ::PageClass5, ::PageClass6]
49
+ @all_piece_classes = [::Piece, ::PieceClass1, ::PieceClass2, ::PieceClass3]
50
+ @all_box_classes = [ ::Box, ::Page::PagesBox ]
51
+ @all_classes = @all_page_classes + @all_piece_classes + @all_box_classes
52
+
53
+ @root0 = ::Page.create(:uid => "root")
54
+ @page1 = ::PageClass1.create(:slug => "page1", :uid => "page1")
55
+ @root0.pages << @page1
56
+ @page2 = ::PageClass2.create(:slug => "page2", :uid => "page2")
57
+ @root0.pages << @page2
58
+ @page3 = ::PageClass3.create(:slug => "page3", :uid => "page3")
59
+ @root0.pages << @page3
60
+ @page4 = ::PageClass4.create(:slug => "page4", :uid => "page4")
61
+ @root0.pages << @page4
62
+ @page5 = ::PageClass5.create(:slug => "page5", :uid => "page5")
63
+ @root0.pages << @page5
64
+ @page6 = ::PageClass6.create(:slug => "page6", :uid => "page6")
65
+ @root0.pages << @page6
66
+
67
+ @page7 = ::PageClass1.create(:slug => "page7", :uid => "page7")
68
+ @page1.pages << @page7
69
+ @page8 = ::PageClass6.create(:slug => "page8", :uid => "page8")
70
+ @page1.pages << @page8
71
+
72
+ @page9 = ::PageClass1.create(:slug => "page9", :uid => "page9")
73
+ @page8.pages << @page9
74
+ @page10 = ::PageClass2.create(:slug => "page10", :uid => "page10")
75
+ @page8.pages << @page10
76
+ @page11 = ::PageClass3.create(:slug => "page11", :uid => "page11")
77
+ @page8.pages << @page11
78
+ @page12 = ::PageClass4.create(:slug => "page12", :uid => "page12")
79
+ @page8.pages << @page12
80
+
81
+ @all_pages = [@root0, @page1, @page2, @page3, @page4, @page5, @page6, @page7, @page8, @page9, @page10, @page11, @page12]
82
+ @all_pages.each { |page| page.save; page.reload }
41
83
  end
42
84
 
43
- def teardown
85
+ after do
86
+ (@all_classes.map { |k| k.name.to_sym }).each { |klass|
87
+ Object.send(:remove_const, klass) rescue nil
88
+ } rescue nil
89
+ Content.delete
44
90
  teardown_site
45
91
  end
46
92
 
47
- context "Search" do
48
- setup do
49
- Content.delete
50
-
51
-
52
- # class ::Piece < S::Piece; end
53
- # class ::Page < S::Page; end
54
- b = ::Page.box :pages
55
- # instantiate box instance class to it gets added to schema
56
- ::Page.boxes.pages.instance_class.schema_id
57
-
58
- class ::PageClass1 < ::Page; end
59
- class ::PageClass2 < ::Page; end
60
- class ::PageClass3 < ::PageClass1; end
61
- class ::PageClass4 < ::PageClass2; end
62
- class ::PageClass5 < ::PageClass3; end
63
- class ::PageClass6 < ::PageClass5; end
64
-
65
- class ::PieceClass1 < ::Piece; end
66
- class ::PieceClass2 < ::Piece; end
67
- class ::PieceClass3 < ::Piece; end
68
-
69
- @all_page_classes = [::Page, ::PageClass1, ::PageClass2, ::PageClass3, ::PageClass4, ::PageClass5, ::PageClass6]
70
- @all_piece_classes = [::Piece, ::PieceClass1, ::PieceClass2, ::PieceClass3]
71
- @all_box_classes = [ ::Box, ::Page::PagesBox ]
72
- @all_classes = @all_page_classes + @all_piece_classes + @all_box_classes
73
-
74
- @root0 = ::Page.create(:uid => "root")
75
- @page1 = ::PageClass1.create(:slug => "page1", :uid => "page1")
76
- @root0.pages << @page1
77
- @page2 = ::PageClass2.create(:slug => "page2", :uid => "page2")
78
- @root0.pages << @page2
79
- @page3 = ::PageClass3.create(:slug => "page3", :uid => "page3")
80
- @root0.pages << @page3
81
- @page4 = ::PageClass4.create(:slug => "page4", :uid => "page4")
82
- @root0.pages << @page4
83
- @page5 = ::PageClass5.create(:slug => "page5", :uid => "page5")
84
- @root0.pages << @page5
85
- @page6 = ::PageClass6.create(:slug => "page6", :uid => "page6")
86
- @root0.pages << @page6
87
-
88
- @page7 = ::PageClass1.create(:slug => "page7", :uid => "page7")
89
- @page1.pages << @page7
90
- @page8 = ::PageClass6.create(:slug => "page8", :uid => "page8")
91
- @page1.pages << @page8
92
-
93
- @page9 = ::PageClass1.create(:slug => "page9", :uid => "page9")
94
- @page8.pages << @page9
95
- @page10 = ::PageClass2.create(:slug => "page10", :uid => "page10")
96
- @page8.pages << @page10
97
- @page11 = ::PageClass3.create(:slug => "page11", :uid => "page11")
98
- @page8.pages << @page11
99
- @page12 = ::PageClass4.create(:slug => "page12", :uid => "page12")
100
- @page8.pages << @page12
101
-
102
- @all_pages = [@root0, @page1, @page2, @page3, @page4, @page5, @page6, @page7, @page8, @page9, @page10, @page11, @page12]
103
- @all_pages.each { |page| page.save; page.reload }
104
- end
105
-
106
- teardown do
107
- (@all_classes.map { |k| k.name.to_sym }).each { |klass|
108
- Object.send(:remove_const, klass) rescue nil
109
- } rescue nil
110
- Content.delete
111
- end
112
-
113
- context "indexes" do
114
-
115
- should "be retrievable by name" do
116
- index = S::Site.index :arthur
117
- S::Site.indexes[:arthur].must_be_instance_of Spontaneous::Search::Index
118
- S::Site.indexes[:arthur].name.should == :arthur
119
- S::Site.indexes[:arthur].should == index
120
- end
93
+ describe "indexes" do
94
+ it "be retrievable by name" do
95
+ index = S::Site.index :arthur
96
+ S::Site.indexes[:arthur].must_be_instance_of Spontaneous::Search::Index
97
+ S::Site.indexes[:arthur].name.must_equal :arthur
98
+ S::Site.indexes[:arthur].must_equal index
99
+ end
100
+
101
+ it "default to indexing all content classes" do
102
+ index = S::Site.index :all
103
+ assert_has_elements (@all_classes), index.search_types
104
+ end
121
105
 
122
- should "default to indexing all content classes" do
123
- index = S::Site.index :all
124
- assert_same_elements (@all_classes), index.search_types
106
+ it "allow restriction to particular classes" do
107
+ index = S::Site.index :all do
108
+ include_types ::PageClass1, "PageClass2", :PageClass3
125
109
  end
110
+ assert_has_elements [::PageClass1, ::PageClass2, ::PageClass3], index.search_types
111
+ end
126
112
 
127
- should "allow restriction to particular classes" do
128
- index = S::Site.index :all do
129
- include_types ::PageClass1, "PageClass2", :PageClass3
130
- end
131
- assert_same_elements [::PageClass1, ::PageClass2, ::PageClass3], index.search_types
113
+ it "allow restriction to a class & its subclasses" do
114
+ index = S::Site.index :all do
115
+ include_types ">= PageClass1"
132
116
  end
117
+ assert_has_elements [::PageClass1, ::PageClass3, ::PageClass5, ::PageClass6], index.search_types
118
+ end
133
119
 
134
- should "allow restriction to a class & its subclasses" do
135
- index = S::Site.index :all do
136
- include_types ">= PageClass1"
137
- end
138
- assert_same_elements [::PageClass1, ::PageClass3, ::PageClass5, ::PageClass6], index.search_types
120
+ it "allow restriction to a class's subclasses" do
121
+ index = S::Site.index :all do
122
+ include_types "> PageClass1"
139
123
  end
124
+ assert_has_elements [::PageClass3, ::PageClass5, ::PageClass6], index.search_types
125
+ end
140
126
 
141
- should "allow restriction to a class's subclasses" do
142
- index = S::Site.index :all do
143
- include_types "> PageClass1"
144
- end
145
- assert_same_elements [::PageClass3, ::PageClass5, ::PageClass6], index.search_types
127
+ it "allow removal of particular classes" do
128
+ index = S::Site.index :all do
129
+ exclude_types ::PageClass1, "PageClass2"
146
130
  end
131
+ assert_has_elements (@all_classes - [PageClass1, PageClass2]), index.search_types
132
+ end
147
133
 
148
- should "allow removal of particular classes" do
149
- index = S::Site.index :all do
150
- exclude_types ::PageClass1, "PageClass2"
151
- end
152
- assert_same_elements (@all_classes - [PageClass1, PageClass2]), index.search_types
134
+ it "allow removal of a class and its subclasses" do
135
+ index = S::Site.index :all do
136
+ exclude_types ">= PageClass1", PieceClass1
153
137
  end
138
+ assert_has_elements (@all_classes - [::PageClass1, ::PageClass3, ::PageClass5, ::PageClass6, PieceClass1]), index.search_types
139
+ end
154
140
 
155
- should "allow removal of a class and its subclasses" do
156
- index = S::Site.index :all do
157
- exclude_types ">= PageClass1", PieceClass1
158
- end
159
- assert_same_elements (@all_classes - [::PageClass1, ::PageClass3, ::PageClass5, ::PageClass6, PieceClass1]), index.search_types
141
+ it "allow removal of a class's subclasses" do
142
+ index = S::Site.index :all do
143
+ exclude_types "> PageClass1"
160
144
  end
145
+ assert_has_elements (@all_classes - [::PageClass3, ::PageClass5, ::PageClass6]), index.search_types
146
+ end
161
147
 
162
- should "allow removal of a class's subclasses" do
163
- index = S::Site.index :all do
164
- exclude_types "> PageClass1"
165
- end
166
- assert_same_elements (@all_classes - [::PageClass3, ::PageClass5, ::PageClass6]), index.search_types
148
+ it "default to including all content" do
149
+ index = S::Site.index :all
150
+ @all_pages.each do |page|
151
+ assert index.include?(page)
167
152
  end
153
+ end
168
154
 
169
- should "default to including all content" do
170
- index = S::Site.index :all
171
- @all_pages.each do |page|
172
- index.include?(page).should be_true
173
- end
155
+ it "allow restriction to a set of specific pages" do
156
+ id = @root0.id
157
+ path = @page8.path
158
+ index = S::Site.index :all do
159
+ include_pages id, "$page11", path
174
160
  end
175
161
 
176
- should "allow restriction to a set of specific pages" do
177
- id = @root0.id
178
- path = @page8.path
179
- index = S::Site.index :all do
180
- include_pages id, "#page11", path
181
- end
162
+ included = @all_pages.map{ |page| index.include?(page) }
163
+ included.must_equal [true,false,false,false,false,false,false,false,true,false,false,true,false]
164
+ end
182
165
 
183
- @all_pages.map{ |page| index.include?(page) }.should ==
184
- [true,false,false,false,false,false,false,false,true,false,false,true,false]
166
+ it "allow restriction to a page and its children" do
167
+ index = S::Site.index :all do
168
+ include_pages ">= $page8"
185
169
  end
186
170
 
187
- should "allow restriction to a page and its children" do
188
- index = S::Site.index :all do
189
- include_pages ">= #page8"
190
- end
171
+ included = @all_pages.map{ |page| index.include?(page) }
172
+ included.must_equal [false,false,false,false,false,false,false,false,true,true,true,true,true]
173
+ end
191
174
 
192
- @all_pages.map{ |page| index.include?(page) }.should ==
193
- [false,false,false,false,false,false,false,false,true,true,true,true,true]
175
+ it "allow restriction to a page's children" do
176
+ index = S::Site.index :all do
177
+ include_pages "> $page8"
194
178
  end
195
179
 
196
- should "allow restriction to a page's children" do
197
- index = S::Site.index :all do
198
- include_pages "> #page8"
199
- end
180
+ included = @all_pages.map{ |page| index.include?(page) }
181
+ included.must_equal [false,false,false,false,false,false,false,false,false,true,true,true,true]
182
+ end
200
183
 
201
- @all_pages.map{ |page| index.include?(page) }.should ==
202
- [false,false,false,false,false,false,false,false,false,true,true,true,true]
184
+ it "allow removal of specific pages" do
185
+ index = S::Site.index :all do
186
+ exclude_pages "$page8", "/page1"
203
187
  end
204
188
 
205
- should "allow removal of specific pages" do
206
- index = S::Site.index :all do
207
- exclude_pages "#page8", "/page1"
208
- end
189
+ included = @all_pages.map{ |page| index.include?(page) }
190
+ included.must_equal [true,false,true,true,true,true,true,true,false,true,true,true,true]
191
+ end
209
192
 
210
- @all_pages.map{ |page| index.include?(page) }.should ==
211
- [true,false,true,true,true,true,true,true,false,true,true,true,true]
193
+ it "allow removal of a page and its children" do
194
+ index = S::Site.index :all do
195
+ exclude_pages "/page1", ">= $page8"
212
196
  end
213
197
 
214
- should "allow removal of a page and its children" do
215
- index = S::Site.index :all do
216
- exclude_pages "/page1", ">= #page8"
217
- end
198
+ included = @all_pages.map{ |page| index.include?(page) }
199
+ included.must_equal [true,false,true,true,true,true,true,true,false,false,false,false,false]
200
+ end
218
201
 
219
- @all_pages.map{ |page| index.include?(page) }.should ==
220
- [true,false,true,true,true,true,true,true,false,false,false,false,false]
202
+ it "allow removal of a page's children" do
203
+ index = S::Site.index :all do
204
+ exclude_pages "/page1", "> $page8"
221
205
  end
222
206
 
223
- should "allow removal of a page's children" do
224
- index = S::Site.index :all do
225
- exclude_pages "/page1", "> #page8"
226
- end
207
+ included = @all_pages.map{ |page| index.include?(page) }
208
+ included.must_equal [true,false,true,true,true,true,true,true,true,false,false,false,false]
209
+ end
227
210
 
228
- @all_pages.map{ |page| index.include?(page) }.should ==
229
- [true,false,true,true,true,true,true,true,true,false,false,false,false]
211
+ it "allow multiple, mixed, page restrictions" do
212
+ index = S::Site.index :all do
213
+ include_pages "$page1", "> $page8"
230
214
  end
231
215
 
232
- should "allow multiple, mixed, page restrictions" do
233
- index = S::Site.index :all do
234
- include_pages "#page1", "> #page8"
235
- end
216
+ included = @all_pages.map{ |page| index.include?(page) }
217
+ included.must_equal [false,true,false,false,false,false,false,false,false,true,true,true,true]
218
+ end
236
219
 
237
- @all_pages.map{ |page| index.include?(page) }.should ==
238
- [false,true,false,false,false,false,false,false,false,true,true,true,true]
220
+ it "allow combining of class and page restrictions" do
221
+ index = S::Site.index :all do
222
+ exclude_types PageClass3, PageClass4
223
+ include_pages "$page1", "> $page8"
224
+ exclude_pages "$page10"
239
225
  end
226
+ included = @all_pages.map{ |page| index.include?(page) }
227
+ included.must_equal [false,true,false,false,false,false,false,false,false,true,false,false,false]
228
+ end
229
+ end
240
230
 
241
- should "allow combining of class and page restrictions" do
242
- index = S::Site.index :all do
243
- exclude_types PageClass3, PageClass4
244
- include_pages "#page1", "> #page8"
245
- exclude_pages "#page10"
246
- end
247
- @all_pages.map{ |page| index.include?(page) }.should ==
248
- [false,true,false,false,false,false,false,false,false,true,false,false,false]
231
+ describe "Fields definitions" do
232
+ # Inclusion of field in indexes.
233
+ # Default is not to include field
234
+ # By adding the following clause:
235
+ #
236
+ # field :title, :index => true
237
+ #
238
+ # you include the :title field in all indexes with a search weight of 1. this is equivalent to the following:
239
+ #
240
+ # field :title, :index => { :name => :*, :weight => 1, :group => nil }
241
+ #
242
+ # If you only want to include this field in a specific index, then you do the following:
243
+ #
244
+ # field :title, :index => :tags
245
+ #
246
+ # this is equivalent to
247
+ #
248
+ # field :title, :index => { :name => :tags, :weight => 1, :group => nil }
249
+ #
250
+ # or if you want to include it into more than one index:
251
+ #
252
+ # field :title, :index => [:tags, :content]
253
+ #
254
+ # this is equivalent to
255
+ #
256
+ # field :title, :index => [
257
+ # { :name => :tags, :weight => 1, :group => nil },
258
+ # { :name => :content, :weight => 1, :group => nil }]
259
+ #
260
+ # Groups:
261
+ #
262
+ # Normally field values are grouped by content types. Indexes are generated from a page by iterating through
263
+ # all it's pieces and creating a single aggregate value for each field of each type found
264
+ #
265
+ # Groups are a way of joining disparate fields from different types into a single, addressable/searchable
266
+ # index
267
+ #
268
+ # weight:
269
+ #
270
+ # weight defines how much priority is given to a field. I.e. if your search term occurs in a field
271
+ # with a high weight value then it will apear higher in the results list than in a page where the
272
+ # term appears in a lower weight field
273
+ #
274
+ # :store = 0 : store but don't index (makes value available to results lister without loading page from db)
275
+ # :normal = 1 : default weight
276
+ # :high = 2 : high weight
277
+ # :higher = 4 : higher weight
278
+ # :highest = 8 : higest
279
+ #
280
+ # actual weight are powers of 10: 10, 100, 10000, 100000000 (unless this is different from Ferret)
281
+ #
282
+ #
283
+ before do
284
+ @index1 = S::Site.index(:one)
285
+ @index2 = S::Site.index(:two)
286
+ @index3 = S::Site.index(:three) do
287
+ include_types PageClass1
249
288
  end
250
289
  end
251
290
 
252
- context "Fields definitions" do
253
- # Inclusion of field in indexes.
254
- # Default is not to include field
255
- # By adding the following clause:
256
- #
257
- # field :title, :index => true
258
- #
259
- # you include the :title field in all indexes with a search weight of 1. this is equivalent to the following:
260
- #
261
- # field :title, :index => { :name => :*, :weight => 1, :group => nil }
262
- #
263
- # If you only want to include this field in a specific index, then you do the following:
264
- #
265
- # field :title, :index => :tags
266
- #
267
- # this is equivalent to
268
- #
269
- # field :title, :index => { :name => :tags, :weight => 1, :group => nil }
270
- #
271
- # or if you want to include it into more than one index:
272
- #
273
- # field :title, :index => [:tags, :content]
274
- #
275
- # this is equivalent to
276
- #
277
- # field :title, :index => [
278
- # { :name => :tags, :weight => 1, :group => nil },
279
- # { :name => :content, :weight => 1, :group => nil }]
280
- #
281
- # Groups:
282
- #
283
- # Normally field values are grouped by content types. Indexes are generated from a page by iterating through
284
- # all it's pieces and creating a single aggregate value for each field of each type found
285
- #
286
- # Groups are a way of joining disparate fields from different types into a single, addressable/searchable
287
- # index
288
- #
289
- # weight:
290
- #
291
- # weight defines how much priority is given to a field. I.e. if your search term occurs in a field
292
- # with a high weight value then it will apear higher in the results list than in a page where the
293
- # term appears in a lower weight field
294
- #
295
- # :store = 0 : store but don't index (makes value available to results lister without loading page from db)
296
- # :normal = 1 : default weight
297
- # :high = 2 : high weight
298
- # :higher = 4 : higher weight
299
- # :highest = 8 : higest
300
- #
301
- # actual weight are powers of 10: 10, 100, 10000, 100000000 (unless this is different from Ferret)
302
- #
303
- #
304
- setup do
305
- @index1 = S::Site.index(:one)
306
- @index2 = S::Site.index(:two)
307
- @index3 = S::Site.index(:three) do
308
- include_types PageClass1
309
- end
310
- end
291
+ after do
292
+ end
311
293
 
312
- teardown do
313
- end
294
+ it "be included in all indexes if :index is set to true" do
295
+ prototype_a = PageClass1.field :a, :index => true
296
+ assert prototype_a.in_index?(@index1)
297
+ assert prototype_a.in_index?(@index2)
298
+ assert prototype_a.in_index?(@index3)
299
+ end
314
300
 
315
- should "be included in all indexes if :index is set to true" do
316
- prototype_a = PageClass1.field :a, :index => true
317
- prototype_a.in_index?(@index1).should be_true
318
- prototype_a.in_index?(@index2).should be_true
319
- prototype_a.in_index?(@index3).should be_true
301
+ it "must be included in all indexes with if passed a hash with no name key" do
302
+ prototype_a = PageClass1.field :a, :index => {weight: 16}
303
+ assert prototype_a.in_index?(@index1)
304
+ assert prototype_a.in_index?(@index2)
305
+ assert prototype_a.in_index?(@index3)
306
+ [:one, :two, :three].each do |name|
307
+ index = S::Site.indexes[name]
308
+ index.fields[PageClass1.fields[:a].schema_id.to_s][:weight].must_equal 16
320
309
  end
310
+ end
321
311
 
322
- should "be included in indexes referenced by name" do
323
- prototype_a = PageClass1.field :a, :index => [:one, :two]
324
- prototype_a.in_index?(@index1).should be_true
325
- prototype_a.in_index?(@index2).should be_true
326
- prototype_a.in_index?(@index3).should be_false
327
- end
312
+ it "be included in indexes referenced by name" do
313
+ prototype_a = PageClass1.field :a, :index => [:one, :two]
314
+ assert prototype_a.in_index?(@index1)
315
+ assert prototype_a.in_index?(@index2)
316
+ refute prototype_a.in_index?(@index3)
317
+ end
328
318
 
329
- should "be included in indexes referenced as hash" do
330
- prototype_a = PageClass1.field :a, :index => {:name => :two}
331
- prototype_a.in_index?(@index1).should be_false
332
- prototype_a.in_index?(@index2).should be_true
333
- prototype_a.in_index?(@index3).should be_false
334
- end
319
+ it "be included in indexes referenced as hash" do
320
+ prototype_a = PageClass1.field :a, :index => {:name => :two}
321
+ refute prototype_a.in_index?(@index1)
322
+ assert prototype_a.in_index?(@index2)
323
+ refute prototype_a.in_index?(@index3)
324
+ end
335
325
 
336
- should "be included in indexes listed in hash" do
337
- prototype_a = PageClass1.field :a, :index => [{:name => :one}, {:name => :two}]
338
- prototype_a.in_index?(@index1).should be_true
339
- prototype_a.in_index?(@index2).should be_true
340
- prototype_a.in_index?(@index3).should be_false
341
- end
326
+ it "be included in indexes listed in hash" do
327
+ prototype_a = PageClass1.field :a, :index => [{:name => :one}, {:name => :two}]
328
+ assert prototype_a.in_index?(@index1)
329
+ assert prototype_a.in_index?(@index2)
330
+ refute prototype_a.in_index?(@index3)
331
+ end
342
332
 
343
- should "return the field's schema id as its index name by default" do
344
- prototype_a = PageClass1.field :a, :index => [{:name => :one}, {:name => :two, :group => :a}]
345
- prototype_a.index_id(@index1).should == prototype_a.schema_id.to_s
346
- prototype_a.index_id(@index2).should == :a
347
- end
333
+ it "return the field's schema id as its index name by default" do
334
+ prototype_a = PageClass1.field :a, :index => [{:name => :one}, {:name => :two, :group => :a}]
335
+ prototype_a.index_id(@index1).must_equal prototype_a.schema_id.to_s
336
+ prototype_a.index_id(@index2).must_equal :a
337
+ end
348
338
 
349
- should "produce a field list in a xapian-fu compatible format" do
350
- a = PageClass1.field :a, :index => [{:name => :one, :weight => :store},
351
- {:name => :two, :group => :a, :weight => 2}]
352
- b = PageClass2.field :b, :index => :one
353
- c = ::Piece.field :c, :index => [{:name => :one, :weight => 4}, {:name => :two, :group => :a}]
354
- d = ::Piece.field :d, :index => :three
355
- e = ::PageClass1.field :e, :index => :three
356
- f = ::PageClass2.field :f, :index => :three
357
- g = ::Piece.field :g, :index => {:weight => :highest}
358
-
359
- h = ::PageClass1.boxes.pages.instance_class.field :h, :index => :two
360
-
361
- S::Site.indexes[:one].fields.should == {
362
- a.schema_id.to_s => { :type => String, :store => true, :index => false},
363
- b.schema_id.to_s => { :type => String, :store => true, :weight => 1, :index => true},
364
- c.schema_id.to_s => { :type => String, :store => true, :weight => 4, :index => true},
365
- g.schema_id.to_s => { :type => String, :store => true, :weight => 16, :index => true}
366
- }
367
-
368
- S::Site.indexes[:two].fields.should == {
369
- :a => { :type => String, :store => true, :weight => 2, :index => true},
370
- g.schema_id.to_s => { :type => String, :store => true, :weight => 16, :index => true},
371
- h.schema_id.to_s => { :type => String, :store => true, :weight => 1, :index => true}
372
- }
373
-
374
- S::Site.indexes[:three].fields.should == {
375
- e.schema_id.to_s => { :type => String, :store => true, :weight => 1, :index => true}
376
- }
377
- end
339
+ it "produce a field list in a xapian-fu compatible format" do
340
+ a = PageClass1.field :a, :index => [{:name => :one, :weight => :store},
341
+ {:name => :two, :group => :a, :weight => 2}]
342
+ b = PageClass2.field :b, :index => :one
343
+ c = ::Piece.field :c, :index => [{:name => :one, :weight => 4}, {:name => :two, :group => :a}]
344
+ d = ::Piece.field :d, :index => :three
345
+ e = ::PageClass1.field :e, :index => :three
346
+ f = ::PageClass2.field :f, :index => :three
347
+ g = ::Piece.field :g, :index => {:weight => :highest}
348
+
349
+ h = ::PageClass1.boxes.pages.instance_class.field :h, :index => :two
350
+
351
+ S::Site.indexes[:one].fields.must_equal({
352
+ a.schema_id.to_s => { :type => String, :store => true, :index => false},
353
+ b.schema_id.to_s => { :type => String, :store => true, :weight => 1, :index => true},
354
+ c.schema_id.to_s => { :type => String, :store => true, :weight => 4, :index => true},
355
+ g.schema_id.to_s => { :type => String, :store => true, :weight => 16, :index => true}
356
+ })
357
+
358
+ S::Site.indexes[:two].fields.must_equal({
359
+ :a => { :type => String, :store => true, :weight => 2, :index => true},
360
+ g.schema_id.to_s => { :type => String, :store => true, :weight => 16, :index => true},
361
+ h.schema_id.to_s => { :type => String, :store => true, :weight => 1, :index => true}
362
+ })
363
+
364
+ S::Site.indexes[:three].fields.must_equal({
365
+ e.schema_id.to_s => { :type => String, :store => true, :weight => 1, :index => true}
366
+ })
378
367
  end
368
+ end
379
369
 
380
- context "Indexes" do
381
- setup do
382
- @revision = 99
370
+ describe "indexing" do
371
+ before do
372
+ @revision = 99
383
373
 
384
- @index1 = S::Site.index :one do
385
- exclude_types PageClass3
386
- end
387
- @index2 = S::Site.index :two
388
-
389
- @a = PageClass1.field :a, :index => true
390
- @b = PageClass2.field :b, :index => true
391
- @c = PageClass3.field :c, :index => true
392
- @d = PageClass4.field :d, :index => true
393
- @e = PageClass5.field :e, :index => true
394
- @f = PageClass6.field :f, :index => true
395
- @g = PieceClass1.field :g, :index => true
396
- @h = PieceClass2.field :h, :index => true
397
- @i = PieceClass3.field :i, :index => {:group => :i}
398
- @j = PieceClass3.field :j, :index => {:group => :i}
399
- @k = PieceClass3.field :k
400
-
401
- @l = ::PageClass1.boxes.pages.instance_class.field :l, :index => true
402
-
403
- @page1.a = "a value 1"
404
- @page1.pages.first.a = "a value 2"
405
- @page1.pages.l = "l value 1"
406
-
407
- @piece1 = PieceClass1.new(:g => "g value 1")
408
- @page1.pages << @piece1
409
- @piece2 = PieceClass1.new(:g => "g value 2")
410
- @page1.pages << @piece2
411
- @piece3 = PieceClass1.new(:g => "g value 3")
412
- @page1.pages << @piece3
413
- @piece4 = PieceClass2.new(:h => "h value 1")
414
- @page1.pages << @piece4
415
- @piece5 = PieceClass2.new(:h => "h value 2")
416
- @page1.pages << @piece5
417
- @piece6 = PieceClass3.new(:i => "i value 1", :j => "j value 1", :k => "k value 1")
418
- @page1.pages << @piece6
419
- @piece7 = PieceClass3.new(:i => "i value 2", :j => "j value 2", :k => "k value 2")
420
- @page1.pages << @piece7
421
-
422
- @page2.b = "b value 1"
423
- @page3.c = "c value 1"
424
- @page1.save
374
+ @index1 = S::Site.index :one do
375
+ exclude_types PageClass3
425
376
  end
377
+ @index2 = S::Site.index :two
426
378
 
427
- teardown do
428
- end
379
+ @a = PageClass1.field :a, :index => true
380
+ @b = PageClass2.field :b, :index => true
381
+ @c = PageClass3.field :c, :index => true
382
+ @d = PageClass4.field :d, :index => true
383
+ @e = PageClass5.field :e, :index => true
384
+ @f = PageClass6.field :f, :index => true
385
+ @g = PieceClass1.field :g, :index => true
386
+ @h = PieceClass2.field :h, :index => true
387
+ @i = PieceClass3.field :i, :index => {:group => :i}
388
+ @j = PieceClass3.field :j, :index => {:group => :i}
389
+ @k = PieceClass3.field :k
429
390
 
430
- should "correctly extract content from pages" do
431
- @page1.a.expects(:indexable_value).returns("(a value 1)")
432
- @index1.indexable_content(@page1).should == {
433
- :id => @page1.id,
434
- @a.schema_id.to_s => "(a value 1)",
435
- @g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
436
- @h.schema_id.to_s => "h value 1\nh value 2",
437
- :i => "i value 1\nj value 1\ni value 2\nj value 2",
438
- @l.schema_id.to_s => "l value 1",
439
- }
440
- end
391
+ @l = ::PageClass1.boxes.pages.instance_class.field :l, :index => true
441
392
 
442
- should "only include specified pieces" do
443
- index = S::Site.index :four do
444
- include_types PageClass1, PieceClass1
445
- end
393
+ @page1.a = "a value 1"
394
+ @page1.pages.first.a = "a value 2"
395
+ @page1.pages.l = "l value 1"
396
+
397
+ @piece1 = PieceClass1.new(:g => "g value 1")
398
+ @page1.pages << @piece1
399
+ @piece2 = PieceClass1.new(:g => "g value 2")
400
+ @page1.pages << @piece2
401
+ @piece3 = PieceClass1.new(:g => "g value 3")
402
+ @page1.pages << @piece3
403
+ @piece4 = PieceClass2.new(:h => "h value 1")
404
+ @page1.pages << @piece4
405
+ @piece5 = PieceClass2.new(:h => "h value 2")
406
+ @page1.pages << @piece5
407
+ @piece6 = PieceClass3.new(:i => "i value 1", :j => "j value 1", :k => "k value 1")
408
+ @page1.pages << @piece6
409
+ @piece7 = PieceClass3.new(:i => "i value 2", :j => "j value 2", :k => "k value 2")
410
+ @page1.pages << @piece7
411
+
412
+ @page2.b = "b value 1"
413
+ @page3.c = "c value 1"
414
+ @page1.save
415
+ end
446
416
 
447
- index.indexable_content(@page1).should == {
448
- :id => @page1.id,
449
- @a.schema_id.to_s => "a value 1",
450
- @g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
451
- }
417
+ after do
418
+ end
419
+
420
+ it "correctly extract content from pages" do
421
+ @page1.a.expects(:indexable_value).returns("(a value 1)")
422
+ @index1.indexable_content(@page1).must_equal({
423
+ :id => @page1.id,
424
+ @a.schema_id.to_s => "(a value 1)",
425
+ @g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
426
+ @h.schema_id.to_s => "h value 1\nh value 2",
427
+ :i => "i value 1\nj value 1\ni value 2\nj value 2",
428
+ @l.schema_id.to_s => "l value 1",
429
+ })
430
+ end
431
+
432
+ it "only include specified pieces" do
433
+ index = S::Site.index :four do
434
+ include_types PageClass1, PieceClass1
452
435
  end
453
436
 
454
- should "allow for page types to append their own custom indexable values" do
455
- index = S::Site.index :four do
456
- include_types PageClass1, PieceClass1
457
- end
458
- class ::PageClass1
459
- def additional_search_values
460
- { "search_key1" => "value 1",
461
- "search_key2" => "value 2" }
462
- end
437
+ index.indexable_content(@page1).must_equal({
438
+ :id => @page1.id,
439
+ @a.schema_id.to_s => "a value 1",
440
+ @g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
441
+ })
442
+ end
443
+
444
+ it "allow for page types to append their own custom indexable values" do
445
+ index = S::Site.index :four do
446
+ include_types PageClass1, PieceClass1
447
+ end
448
+ class ::PageClass1
449
+ def additional_search_values
450
+ { "search_key1" => "value 1",
451
+ "search_key2" => "value 2" }
463
452
  end
464
- index.indexable_content(@page1).should == {
465
- :id => @page1.id,
466
- @a.schema_id.to_s => "a value 1",
467
- @g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
468
- "search_key1" => "value 1",
469
- "search_key2" => "value 2"
470
- }
471
453
  end
454
+ index.indexable_content(@page1).must_equal({
455
+ :id => @page1.id,
456
+ @a.schema_id.to_s => "a value 1",
457
+ @g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
458
+ "search_key1" => "value 1",
459
+ "search_key2" => "value 2"
460
+ })
461
+ end
472
462
 
473
- should "deal with arrays of additional search index values" do
474
- index = S::Site.index :four do
475
- include_types PageClass1, PieceClass1
476
- end
477
- class ::PageClass1
478
- def additional_search_values
479
- [ { "search_key1" => "value 1",
480
- "search_key2" => "value 2" },
463
+ it "deal with arrays of additional search index values" do
464
+ index = S::Site.index :four do
465
+ include_types PageClass1, PieceClass1
466
+ end
467
+ class ::PageClass1
468
+ def additional_search_values
469
+ [ { "search_key1" => "value 1",
470
+ "search_key2" => "value 2" },
481
471
  { "search_key1" => "value 3",
482
472
  "search_key2" => "value 4" } ]
483
- end
484
473
  end
485
- index.indexable_content(@page1).should == {
486
- :id => @page1.id,
487
- @a.schema_id.to_s => "a value 1",
488
- @g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
489
- "search_key1" => "value 1\nvalue 3",
490
- "search_key2" => "value 2\nvalue 4"
491
- }
492
474
  end
475
+ index.indexable_content(@page1).must_equal({
476
+ :id => @page1.id,
477
+ @a.schema_id.to_s => "a value 1",
478
+ @g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
479
+ "search_key1" => "value 1\nvalue 3",
480
+ "search_key2" => "value 2\nvalue 4"
481
+ })
482
+ end
493
483
 
494
- should "allow for pieces to append their own custom indexable values" do
495
- index = S::Site.index :four do
496
- include_types PageClass1, PieceClass1
497
- end
498
- class ::PieceClass1
499
- def additional_search_values
500
- { "search_key3" => "value 3",
501
- "search_key4" => "value 4" }
502
- end
503
- end
504
- index.indexable_content(@page1).should == {
505
- :id => @page1.id,
506
- @a.schema_id.to_s => "a value 1",
507
- @g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
508
- "search_key3" => "value 3\nvalue 3\nvalue 3",
509
- "search_key4" => "value 4\nvalue 4\nvalue 4"
510
- }
484
+ it "allow for pieces to append their own custom indexable values" do
485
+ index = S::Site.index :four do
486
+ include_types PageClass1, PieceClass1
511
487
  end
512
-
513
- should "create database in the right directory" do
514
- db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
515
- Site.stubs(:published_revision).returns(@revision)
516
- mset = mock()
517
- mset.stubs(:matches).returns([])
518
- xapian = mock()
519
- xapian.expects(:<<).with(@index1.indexable_content(@page1))
520
- xapian.expects(:search).with('"value 2"', {}).returns(XapianFu::ResultSet.new(:mset => mset))
521
- xapian.expects(:flush)
522
-
523
- XapianFu::XapianDb.expects(:new).with(has_entries({
524
- :dir => db_path,
525
- :create => true,
526
- :overwrite => true,
527
- :language => :english,
528
- :fields => @index1.fields,
529
- :spelling => true
530
- })).returns(xapian)
531
-
532
- db = @index1.create_db(@revision)
533
- assert File.directory?(db_path)
534
- db << @page1
535
- db << @page3
536
- db.close
537
- db.search('"value 2"')
538
- FileUtils.rm_r(db_path)
488
+ class ::PieceClass1
489
+ def additional_search_values
490
+ { "search_key3" => "value 3",
491
+ "search_key4" => "value 4" }
492
+ end
539
493
  end
494
+ index.indexable_content(@page1).must_equal({
495
+ :id => @page1.id,
496
+ @a.schema_id.to_s => "a value 1",
497
+ @g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
498
+ "search_key3" => "value 3\nvalue 3\nvalue 3",
499
+ "search_key4" => "value 4\nvalue 4\nvalue 4"
500
+ })
501
+ end
540
502
 
541
- should "pass on index configuration to the xapian db" do
542
- db_path = @site.revision_dir(@revision) / 'indexes' / 'name'
503
+ it "create database in the right directory" do
504
+ db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
505
+ Site.stubs(:published_revision).returns(@revision)
506
+ mset = mock()
507
+ mset.stubs(:matches).returns([])
508
+ xapian = mock()
509
+ xapian.expects(:<<).with(@index1.indexable_content(@page1))
510
+ xapian.expects(:search).with('"value 2"', {}).returns(XapianFu::ResultSet.new(:mset => mset))
511
+ xapian.expects(:flush)
512
+
513
+ XapianFu::XapianDb.expects(:new).with(has_entries({
514
+ :dir => db_path,
515
+ :create => true,
516
+ :overwrite => true,
517
+ :language => :english,
518
+ :fields => @index1.fields,
519
+ :spelling => true
520
+ })).returns(xapian)
521
+
522
+ db = @index1.create_db(@revision)
523
+ assert File.directory?(db_path)
524
+ db << @page1
525
+ db << @page3
526
+ db.close
527
+ db.search('"value 2"')
528
+ FileUtils.rm_r(db_path)
529
+ end
543
530
 
544
- index = Site.index :name do
545
- language :italian
546
- end
531
+ it "pass on index configuration to the xapian db" do
532
+ db_path = @site.revision_dir(@revision) / 'indexes' / 'name'
547
533
 
548
- XapianFu::XapianDb.expects(:new).with(has_entries({
549
- :dir => db_path,
550
- :create => true,
551
- :overwrite => true,
552
- :language => :italian,
553
- :fields => index.fields,
554
- :spelling => true
555
- }))
556
-
557
- db = index.create_db(@revision)
558
-
559
- index = Site.index :name do
560
- language :french
561
- stopper false
562
- stemmer false
563
- end
534
+ index = Site.index :name do
535
+ language :italian
536
+ end
564
537
 
565
- XapianFu::XapianDb.expects(:new).with(has_entries({
566
- :dir => db_path,
567
- :create => true,
568
- :overwrite => true,
569
- :language => :french,
570
- :stemmer => false,
571
- :stopper => false,
572
- :fields => index.fields,
573
- :spelling => true
574
- }))
538
+ XapianFu::XapianDb.expects(:new).with(has_entries({
539
+ :dir => db_path,
540
+ :create => true,
541
+ :overwrite => true,
542
+ :language => :italian,
543
+ :fields => index.fields,
544
+ :spelling => true
545
+ }))
575
546
 
576
- db = index.create_db(@revision)
547
+ db = index.create_db(@revision)
577
548
 
578
- FileUtils.rm_r(db_path)
549
+ index = Site.index :name do
550
+ language :french
551
+ stopper false
552
+ stemmer false
579
553
  end
580
554
 
581
- should "return (reasonable) results to searches" do
582
- db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
583
- S::Site.stubs(:published_revision).returns(@revision)
584
- db = @index1.create_db(@revision)
585
- db << @page1
586
- db << @page2
587
- db << @page3
588
- db.close
589
-
590
- results = @index1.search('+valeu', :limit => 1, :autocorrect => true)
591
- results.must_be_instance_of S::Search::Results
592
- results.each do |result|
593
- result.class.should < Content::Page
594
- end
555
+ XapianFu::XapianDb.expects(:new).with(has_entries({
556
+ :dir => db_path,
557
+ :create => true,
558
+ :overwrite => true,
559
+ :language => :french,
560
+ :stemmer => false,
561
+ :stopper => false,
562
+ :fields => index.fields,
563
+ :spelling => true
564
+ }))
595
565
 
596
- results.corrected_query.should == '+value'
597
- results.current_page.should == 1
598
- results.per_page.should == 1
599
- results.total_pages.should == 2
600
- results.next_page.should == 2
601
- results.offset.should == 0
602
- results.previous_page.should == nil
603
- results.total_entries.should == 2
566
+ db = index.create_db(@revision)
604
567
 
605
- results = @index1.search('valeu', :limit => 1, :autocorrect => false)
606
- results.corrected_query.should == 'value'
607
- results.total_entries.should == 0
568
+ FileUtils.rm_r(db_path)
569
+ end
608
570
 
609
- results = @index1.search('value', :limit => 1)
610
- results.corrected_query.should == ''
611
- results.total_entries.should == 2
571
+ it "return (reasonable) results to searches" do
572
+ db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
573
+ S::Site.stubs(:published_revision).returns(@revision)
574
+ db = @index1.create_db(@revision)
575
+ db << @page1
576
+ db << @page2
577
+ db << @page3
578
+ db.close
579
+
580
+ results = @index1.search('+valeu', :limit => 1, :autocorrect => true)
581
+ results.must_be_instance_of S::Search::Results
582
+ results.each do |result|
583
+ result.class.must_be :<, Content::Page
584
+ end
585
+
586
+ results.corrected_query.must_equal '+value'
587
+ results.current_page.must_equal 1
588
+ results.per_page.must_equal 1
589
+ results.total_pages.must_equal 2
590
+ results.next_page.must_equal 2
591
+ results.offset.must_equal 0
592
+ results.previous_page.must_equal nil
593
+ results.total_entries.must_equal 2
594
+
595
+ results = @index1.search('valeu', :limit => 1, :autocorrect => false)
596
+ results.corrected_query.must_equal 'value'
597
+ results.total_entries.must_equal 0
598
+
599
+ results = @index1.search('value', :limit => 1)
600
+ results.corrected_query.must_equal ''
601
+ results.total_entries.must_equal 2
602
+
603
+ FileUtils.rm_r(db_path)
604
+ end
612
605
 
613
- FileUtils.rm_r(db_path)
614
- end
606
+ it "returns pages based on the contents of their boxes" do
607
+ db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
608
+ S::Site.stubs(:published_revision).returns(@revision)
609
+ db = @index1.create_db(@revision)
610
+ db << @page1
611
+ db << @page2
612
+ db << @page3
613
+ db.close
614
+
615
+ results = @index1.search('h value')
616
+ results.to_a.first.id.must_equal @page1.id
617
+ end
615
618
 
616
- should "respect weighting factors given to fields" do
617
- db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
618
- S::Site.stubs(:published_revision).returns(@revision)
619
- db = @index1.create_db(@revision)
620
- @w = PieceClass1.field :w, :index => { :weight => 100 }
621
- @page1.pages << PieceClass1.new(:w => "findme")
622
- @page2.pages << PieceClass2.new(:h => "findme findme")
623
- @page2.pages << PieceClass2.new(:h => "findme findme")
624
- @page5.pages << PieceClass2.new(:h => "findme")
625
- @page5.pages << PieceClass2.new(:h => "findme")
626
-
627
- @page1.save
628
- @page2.save
629
- @page5.save
630
- db << @page1
631
- db << @page2
632
- db << @page5
633
- db.close
634
- results = @index1.search('findme', :limit => 5)
635
- results.map(&:id).should == [@page1.id, @page2.id, @page5.id]
636
- end
637
619
 
638
- should "use the weighting specific to a subclass" do
639
- db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
640
- S::Site.stubs(:published_revision).returns(@revision)
641
- @w = PieceClass1.field :w, :index => { :weight => 100 }
642
- WeightedPiece = Class.new(PieceClass1)
643
- WeightedPiece.field :w, :index => { :weight => 1}
644
- index = Site.index :weighted do
645
- end
646
- @page1.pages << WeightedPiece.new(:w => "findme")
647
- @page2.pages << PieceClass2.new(:h => "findme findme")
648
- @page2.pages << PieceClass2.new(:h => "findme findme")
649
- @page5.pages << PieceClass2.new(:h => "findme")
650
- @page5.pages << PieceClass2.new(:h => "findme")
651
-
652
- @page1.save
653
- @page2.save
654
- @page5.save
655
- db = index.create_db(@revision)
656
- db << @page1
657
- db << @page2
658
- db << @page5
659
- db.close
660
- results = index.search('findme', :limit => 5)
661
- results.map(&:id).should == [@page2.id, @page5.id, @page1.id]
662
- end
620
+ it "respect weighting factors given to fields" do
621
+ db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
622
+ S::Site.stubs(:published_revision).returns(@revision)
623
+ db = @index1.create_db(@revision)
624
+ @w = PieceClass1.field :w, :index => { :weight => 100 }
625
+ @page1.pages << PieceClass1.new(:w => "findme")
626
+ @page2.pages << PieceClass2.new(:h => "findme findme")
627
+ @page2.pages << PieceClass2.new(:h => "findme findme")
628
+ @page5.pages << PieceClass2.new(:h => "findme")
629
+ @page5.pages << PieceClass2.new(:h => "findme")
630
+
631
+ @page1.save
632
+ @page2.save
633
+ @page5.save
634
+ db << @page1
635
+ db << @page2
636
+ db << @page5
637
+ db.close
638
+ results = @index1.search('findme', :limit => 5)
639
+ results.map(&:id).must_equal [@page1.id, @page2.id, @page5.id]
640
+ end
663
641
 
664
- should "provide a convenient way to add documents to multiple indexes" do
665
- db1 = mock()
666
- db2 = mock()
667
- @index1.expects(:create_db).with(@revision).returns(db1)
668
- @index2.expects(:create_db).with(@revision).returns(db2)
669
- db1.expects(:<<).with(@page1)
670
- db2.expects(:<<).with(@page1)
671
- db1.expects(:close)
672
- db2.expects(:close)
673
- S::Site.indexer(@revision) do |indexer|
674
- indexer.length.should == 2
675
- indexer << @page1
676
- end
677
- end
642
+ it "use the weighting specific to a subclass" do
643
+ db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
644
+ S::Site.stubs(:published_revision).returns(@revision)
645
+ @w = PieceClass1.field :w, :index => { :weight => 100 }
646
+ WeightedPiece = Class.new(PieceClass1)
647
+ WeightedPiece.field :w, :index => { :weight => 1}
648
+ index = Site.index :weighted do
649
+ end
650
+ @page1.pages << WeightedPiece.new(:w => "findme")
651
+ @page2.pages << PieceClass2.new(:h => "findme findme")
652
+ @page2.pages << PieceClass2.new(:h => "findme findme")
653
+ @page5.pages << PieceClass2.new(:h => "findme")
654
+ @page5.pages << PieceClass2.new(:h => "findme")
655
+
656
+ @page1.save
657
+ @page2.save
658
+ @page5.save
659
+ db = index.create_db(@revision)
660
+ db << @page1
661
+ db << @page2
662
+ db << @page5
663
+ db.close
664
+ results = index.search('findme', :limit => 5)
665
+ results.map(&:id).must_equal [@page2.id, @page5.id, @page1.id]
678
666
  end
679
667
 
680
- context "initialization" do
681
- setup do
682
- FileUtils.cp_r(File.expand_path("../../fixtures/search/config", __FILE__), @site.root)
668
+ it "provide a convenient way to add documents to multiple indexes" do
669
+ db1 = mock()
670
+ db2 = mock()
671
+ @index1.expects(:create_db).with(@revision).returns(db1)
672
+ @index2.expects(:create_db).with(@revision).returns(db2)
673
+ db1.expects(:<<).with(@page1)
674
+ db2.expects(:<<).with(@page1)
675
+ db1.expects(:close)
676
+ db2.expects(:close)
677
+ S::Site.indexer(@revision) do |indexer|
678
+ indexer.length.must_equal 2
679
+ indexer << @page1
683
680
  end
681
+ end
682
+ end
684
683
 
685
- should "load the config/indexes.rb file" do
686
- @site.expects(:connect_to_database!)
687
- @site.initialize!
688
- index = @site.indexes[:fast]
689
- index.must_be_instance_of S::Search::Index
690
- index.name.should == :fast
691
- index.search_types.should == [PageClass1, PageClass2, PageClass3]
692
- end
684
+ describe "initialization" do
685
+ before do
686
+ FileUtils.cp_r(File.expand_path("../../fixtures/search/config", __FILE__), @site.root)
687
+ end
688
+
689
+ it "load the config/indexes.rb file" do
690
+ @site.expects(:connect_to_database!)
691
+ @site.initialize!
692
+ index = @site.indexes[:fast]
693
+ index.must_be_instance_of S::Search::Index
694
+ index.name.must_equal :fast
695
+ index.search_types.must_equal [PageClass1, PageClass2, PageClass3]
693
696
  end
694
697
  end
695
698
  end