spontaneous 0.2.0.beta4 → 0.2.0.beta5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -0
  3. data/Gemfile +11 -6
  4. data/Readme.markdown +136 -69
  5. data/application/css/core.css.scss +27 -7
  6. data/application/css/editing.css.scss +4 -26
  7. data/application/css/schema_error.css.scss +22 -0
  8. data/application/js/content.js +11 -3
  9. data/application/js/edit_panel.js +1 -4
  10. data/application/js/field/file.js +17 -0
  11. data/application/js/field/image.js +30 -21
  12. data/application/js/field/string.js +4 -1
  13. data/application/js/field_preview.js +21 -16
  14. data/application/js/publish.js +6 -6
  15. data/application/js/types.js +5 -13
  16. data/application/js/views.js +2 -2
  17. data/application/js/views/box_view.js +3 -2
  18. data/application/js/views/page_piece_view.js +1 -1
  19. data/application/js/views/piece_view.js +1 -1
  20. data/application/views/schema_modification_error.html.erb +13 -3
  21. data/db/migrations/20131104101935_site_must_publish_all.rb +14 -0
  22. data/lib/spontaneous.rb +0 -1
  23. data/lib/spontaneous/box_style.rb +15 -9
  24. data/lib/spontaneous/capistrano/deploy.rb +13 -1
  25. data/lib/spontaneous/change.rb +11 -13
  26. data/lib/spontaneous/cli.rb +5 -2
  27. data/lib/spontaneous/cli/assets.rb +7 -1
  28. data/lib/spontaneous/cli/console.rb +7 -1
  29. data/lib/spontaneous/cli/content.rb +35 -0
  30. data/lib/spontaneous/cli/fields.rb +3 -2
  31. data/lib/spontaneous/cli/generate.rb +5 -2
  32. data/lib/spontaneous/cli/server.rb +12 -8
  33. data/lib/spontaneous/cli/site.rb +12 -12
  34. data/lib/spontaneous/cli/user.rb +28 -14
  35. data/lib/spontaneous/collections/box_set.rb +4 -4
  36. data/lib/spontaneous/collections/field_set.rb +4 -4
  37. data/lib/spontaneous/collections/prototype_set.rb +12 -4
  38. data/lib/spontaneous/data_mapper.rb +11 -7
  39. data/lib/spontaneous/data_mapper/content_model.rb +8 -0
  40. data/lib/spontaneous/data_mapper/content_model/associations.rb +1 -1
  41. data/lib/spontaneous/data_mapper/dataset.rb +14 -2
  42. data/lib/spontaneous/data_mapper/scope.rb +33 -13
  43. data/lib/spontaneous/facet.rb +4 -0
  44. data/lib/spontaneous/field.rb +12 -12
  45. data/lib/spontaneous/field/base.rb +27 -22
  46. data/lib/spontaneous/field/boolean.rb +4 -4
  47. data/lib/spontaneous/field/date.rb +2 -2
  48. data/lib/spontaneous/field/file.rb +24 -18
  49. data/lib/spontaneous/field/html.rb +1 -1
  50. data/lib/spontaneous/field/image.rb +6 -19
  51. data/lib/spontaneous/field/location.rb +1 -1
  52. data/lib/spontaneous/field/long_string.rb +3 -3
  53. data/lib/spontaneous/field/markdown.rb +3 -3
  54. data/lib/spontaneous/field/select.rb +2 -2
  55. data/lib/spontaneous/field/string.rb +2 -2
  56. data/lib/spontaneous/field/tags.rb +2 -2
  57. data/lib/spontaneous/field/update.rb +21 -20
  58. data/lib/spontaneous/field/webvideo.rb +6 -6
  59. data/lib/spontaneous/field/webvideo/fallback.rb +2 -2
  60. data/lib/spontaneous/field/webvideo/vimeo.rb +7 -7
  61. data/lib/spontaneous/generators/site.rb +2 -2
  62. data/lib/spontaneous/generators/site/Gemfile.tt +5 -1
  63. data/lib/spontaneous/layout.rb +2 -2
  64. data/lib/spontaneous/media.rb +1 -0
  65. data/lib/spontaneous/media/file.rb +6 -5
  66. data/lib/spontaneous/media/image/attributes.rb +4 -0
  67. data/lib/spontaneous/media/image/renderable.rb +4 -4
  68. data/lib/spontaneous/media/store.rb +22 -0
  69. data/lib/spontaneous/{storage → media/store}/backend.rb +1 -1
  70. data/lib/spontaneous/{storage → media/store}/cloud.rb +1 -1
  71. data/lib/spontaneous/{storage → media/store}/local.rb +1 -1
  72. data/lib/spontaneous/media/temp_file.rb +1 -1
  73. data/lib/spontaneous/model.rb +10 -7
  74. data/lib/spontaneous/model/action.rb +7 -0
  75. data/lib/spontaneous/model/action/clean.rb +87 -0
  76. data/lib/spontaneous/model/box/allowed_types.rb +15 -1
  77. data/lib/spontaneous/model/core.rb +10 -0
  78. data/lib/spontaneous/model/core/aliases.rb +1 -1
  79. data/lib/spontaneous/model/core/content_groups.rb +1 -1
  80. data/lib/spontaneous/model/core/fields.rb +1 -1
  81. data/lib/spontaneous/model/core/modifications.rb +2 -2
  82. data/lib/spontaneous/model/core/page_search.rb +4 -0
  83. data/lib/spontaneous/model/core/publishing.rb +4 -17
  84. data/lib/spontaneous/model/core/render.rb +4 -4
  85. data/lib/spontaneous/model/core/styles.rb +2 -2
  86. data/lib/spontaneous/model/core/visibility.rb +6 -2
  87. data/lib/spontaneous/model/page.rb +6 -2
  88. data/lib/spontaneous/model/page/controllers.rb +55 -17
  89. data/lib/spontaneous/model/page/formats.rb +12 -7
  90. data/lib/spontaneous/model/page/layouts.rb +2 -2
  91. data/lib/spontaneous/model/page/locks.rb +4 -1
  92. data/lib/spontaneous/model/page/page_tree.rb +40 -6
  93. data/lib/spontaneous/output.rb +14 -52
  94. data/lib/spontaneous/output/context.rb +11 -39
  95. data/lib/spontaneous/output/context/navigation.rb +31 -0
  96. data/lib/spontaneous/output/format.rb +15 -19
  97. data/lib/spontaneous/output/renderable.rb +99 -0
  98. data/lib/spontaneous/output/store.rb +24 -0
  99. data/lib/spontaneous/output/store/backend.rb +52 -0
  100. data/lib/spontaneous/output/store/file.rb +77 -0
  101. data/lib/spontaneous/output/store/moneta.rb +117 -0
  102. data/lib/spontaneous/output/store/revision.rb +34 -0
  103. data/lib/spontaneous/output/store/store.rb +15 -0
  104. data/lib/spontaneous/output/store/transaction.rb +44 -0
  105. data/lib/spontaneous/output/template/engine.rb +17 -7
  106. data/lib/spontaneous/output/template/renderer.rb +66 -40
  107. data/lib/spontaneous/page_lock.rb +5 -7
  108. data/lib/spontaneous/page_piece.rb +2 -2
  109. data/lib/spontaneous/permissions/user.rb +14 -7
  110. data/lib/spontaneous/plugins/application/features.rb +8 -4
  111. data/lib/spontaneous/plugins/application/state.rb +12 -6
  112. data/lib/spontaneous/prototypes/box_prototype.rb +9 -10
  113. data/lib/spontaneous/prototypes/field_prototype.rb +66 -15
  114. data/lib/spontaneous/publishing/immediate.rb +30 -26
  115. data/lib/spontaneous/rack.rb +12 -7
  116. data/lib/spontaneous/rack/back.rb +43 -37
  117. data/lib/spontaneous/rack/back/base.rb +4 -4
  118. data/lib/spontaneous/rack/back/changes.rb +2 -2
  119. data/lib/spontaneous/rack/back/file.rb +16 -24
  120. data/lib/spontaneous/rack/back/map.rb +5 -5
  121. data/lib/spontaneous/rack/back/preview.rb +3 -4
  122. data/lib/spontaneous/rack/back/schema.rb +1 -1
  123. data/lib/spontaneous/rack/back/site.rb +6 -7
  124. data/lib/spontaneous/rack/front.rb +19 -16
  125. data/lib/spontaneous/rack/middleware/authenticate.rb +3 -3
  126. data/lib/spontaneous/rack/middleware/reloader.rb +3 -2
  127. data/lib/spontaneous/rack/middleware/scope.rb +25 -19
  128. data/lib/spontaneous/rack/page_controller.rb +164 -13
  129. data/lib/spontaneous/rack/public.rb +23 -62
  130. data/lib/spontaneous/rack/static.rb +2 -3
  131. data/lib/spontaneous/schema.rb +27 -8
  132. data/lib/spontaneous/schema/schema_modification.rb +9 -1
  133. data/lib/spontaneous/schema/uid.rb +2 -2
  134. data/lib/spontaneous/schema/uid_map.rb +3 -2
  135. data/lib/spontaneous/search/database.rb +2 -2
  136. data/lib/spontaneous/search/field.rb +5 -3
  137. data/lib/spontaneous/search/index.rb +12 -7
  138. data/lib/spontaneous/search/results.rb +5 -3
  139. data/lib/spontaneous/server.rb +2 -2
  140. data/lib/spontaneous/site.rb +10 -3
  141. data/lib/spontaneous/site/features.rb +26 -6
  142. data/lib/spontaneous/site/helpers.rb +9 -12
  143. data/lib/spontaneous/site/level.rb +7 -9
  144. data/lib/spontaneous/site/map.rb +9 -11
  145. data/lib/spontaneous/site/paths.rb +5 -5
  146. data/lib/spontaneous/site/publishing.rb +83 -80
  147. data/lib/spontaneous/site/schema.rb +1 -7
  148. data/lib/spontaneous/site/search.rb +8 -18
  149. data/lib/spontaneous/site/selectors.rb +60 -54
  150. data/lib/spontaneous/site/state.rb +36 -30
  151. data/lib/spontaneous/site/storage.rb +10 -16
  152. data/lib/spontaneous/state.rb +8 -0
  153. data/lib/spontaneous/style.rb +32 -33
  154. data/lib/spontaneous/version.rb +1 -1
  155. data/spontaneous.gemspec +22 -21
  156. data/test/fixtures/public/templates/layouts/default.html.cut +1 -1
  157. data/test/fixtures/public/templates/layouts/default.pdf.cut +1 -1
  158. data/test/fixtures/public/templates/layouts/default.rss.cut +1 -1
  159. data/test/fixtures/search/config/indexes.rb +1 -1
  160. data/test/fixtures/serialisation/class_hash.yaml.erb +13 -1
  161. data/test/fixtures/serialisation/root_hash.yaml.erb +10 -0
  162. data/test/functional/test_application.rb +20 -24
  163. data/test/functional/test_back.rb +26 -27
  164. data/test/functional/test_cli.rb +146 -0
  165. data/test/functional/test_front.rb +287 -216
  166. data/test/functional/test_user_manager.rb +1 -1
  167. data/test/test_helper.rb +15 -11
  168. data/test/unit/test_alias.rb +32 -25
  169. data/test/unit/test_asset_bundler.rb +1 -1
  170. data/test/unit/test_assets.rb +34 -33
  171. data/test/unit/test_authentication.rb +1 -1
  172. data/test/unit/test_boxes.rb +16 -2
  173. data/test/unit/test_changesets.rb +23 -11
  174. data/test/unit/test_content.rb +15 -0
  175. data/test/unit/test_context.rb +139 -0
  176. data/test/unit/test_controllers.rb +374 -0
  177. data/test/{experimental → unit}/test_crypt.rb +0 -0
  178. data/test/unit/test_datamapper.rb +260 -237
  179. data/test/unit/test_datamapper_content.rb +42 -12
  180. data/test/{experimental → unit}/test_features.rb +85 -3
  181. data/test/unit/test_fields.rb +117 -42
  182. data/test/unit/test_formats.rb +11 -1
  183. data/test/unit/test_generators.rb +2 -2
  184. data/test/unit/test_helpers.rb +7 -8
  185. data/test/unit/test_images.rb +39 -2
  186. data/test/unit/test_layouts.rb +14 -12
  187. data/test/unit/test_media.rb +32 -23
  188. data/test/unit/test_output_store.rb +342 -0
  189. data/test/unit/test_page.rb +8 -1
  190. data/test/unit/test_permissions.rb +11 -7
  191. data/test/unit/test_plugins.rb +3 -3
  192. data/test/unit/test_prototype_set.rb +8 -1
  193. data/test/unit/test_publishing.rb +67 -54
  194. data/test/unit/test_render.rb +91 -38
  195. data/test/unit/test_revisions.rb +4 -4
  196. data/test/unit/test_schema.rb +109 -84
  197. data/test/unit/test_search.rb +42 -42
  198. data/test/unit/test_serialisation.rb +3 -2
  199. data/test/unit/test_site.rb +39 -27
  200. data/test/unit/test_storage.rb +9 -6
  201. data/test/unit/test_styles.rb +25 -32
  202. data/test/unit/test_templates.rb +8 -4
  203. metadata +89 -54
  204. data/lib/spontaneous/model/page/request.rb +0 -105
  205. data/lib/spontaneous/storage.rb +0 -22
@@ -102,8 +102,8 @@ describe "Revisions" do
102
102
  end
103
103
 
104
104
  it "understand with_published" do
105
- S::Site.stubs(:published_revision).returns(99)
106
- Content.with_published do
105
+ site.stubs(:published_revision).returns(99)
106
+ Content.with_published(site) do
107
107
  Content.mapper.current_revision.must_equal 99
108
108
  end
109
109
  end
@@ -130,7 +130,7 @@ describe "Revisions" do
130
130
 
131
131
  it "read revision from the environment if present" do
132
132
  ENV["SPOT_REVISION"] = '1001'
133
- Content.with_published do
133
+ Content.with_published(site) do
134
134
  Content.mapper.current_revision.must_equal 1001
135
135
  end
136
136
  ENV.delete("SPOT_REVISION")
@@ -474,7 +474,7 @@ describe "Revisions" do
474
474
  first.first_published_at.must_be_nil
475
475
  Revision.create(Content, @revision)
476
476
  first.reload.first_published_at.to_i.must_equal @now.to_i
477
- c = Content.create
477
+ c = Page.create
478
478
  c.first_published_at.must_be_nil
479
479
  stub_time(@now + 100)
480
480
  Revision.create(Content, @revision+1)
@@ -150,19 +150,19 @@ describe "Schema" do
150
150
 
151
151
  describe "lookups" do
152
152
  it "return classes" do
153
- Site.schema.to_class("xxxxxxxxxxxx").must_equal SchemaClass
153
+ @site.schema.to_class("xxxxxxxxxxxx").must_equal SchemaClass
154
154
  end
155
155
  it "return fields" do
156
- Site.schema.to_class("ffffffffffff").must_equal SchemaClass.field_prototypes[:description]
156
+ @site.schema.to_class("ffffffffffff").must_equal SchemaClass.field_prototypes[:description]
157
157
  end
158
158
  it "return boxes" do
159
- Site.schema.to_class("bbbbbbbbbbbb").must_equal SchemaClass.box_prototypes[:posts]
159
+ @site.schema.to_class("bbbbbbbbbbbb").must_equal SchemaClass.box_prototypes[:posts]
160
160
  end
161
161
  it "return styles" do
162
- Site.schema.to_class("ssssssssssss").must_equal SchemaClass.style_prototypes[:simple]
162
+ @site.schema.to_class("ssssssssssss").must_equal SchemaClass.style_prototypes[:simple]
163
163
  end
164
164
  it "return layouts" do
165
- Site.schema.to_class("llllllllllll").must_equal SchemaClass.layout_prototypes[:clean]
165
+ @site.schema.to_class("llllllllllll").must_equal SchemaClass.layout_prototypes[:clean]
166
166
  end
167
167
  end
168
168
 
@@ -769,30 +769,6 @@ describe "Schema" do
769
769
  end
770
770
 
771
771
 
772
- it "be done automatically if only classes have been removed" do
773
- uid = B.schema_id.to_s
774
- Object.send(:remove_const, :B)
775
- S.schema.stubs(:classes).returns([::A])
776
- S.schema.reload!
777
- S.schema.validate!
778
- m = YAML.load_file(@map_file)
779
- refute m.key?(uid)
780
- end
781
-
782
- it "be done automatically if only boxes have been removed" do
783
- uid = A.boxes[:posts].schema_id.to_s
784
- Object.send :remove_const, :A
785
- class ::A < ::Page
786
- field :title
787
- field :introduction
788
- layout :sparse
789
- end
790
- S.schema.stubs(:classes).returns([A, B])
791
- S.schema.reload!
792
- S.schema.validate!
793
- m = YAML.load_file(@map_file)
794
- refute m.key?(uid)
795
- end
796
772
 
797
773
  it "be done automatically if only fields have been removed" do
798
774
  uid = A.fields[:title].schema_id.to_s
@@ -809,20 +785,6 @@ describe "Schema" do
809
785
  refute m.key?(uid)
810
786
  end
811
787
 
812
- it "be done automatically in presence of independent addition inside type and of type" do
813
- A.field :moose
814
- uid = B.schema_id.to_s
815
- Object.send(:remove_const, :B)
816
- S.schema.stubs(:classes).returns([::A])
817
- S.schema.reload!
818
- S.schema.validate!
819
- ::A.field_prototypes[:moose].schema_id.wont_be_nil
820
-
821
- m = YAML.load_file(@map_file)
822
- m[::A.field_prototypes[:moose].schema_id.to_s].must_equal ::A.field_prototypes[:moose].schema_name
823
- refute m.key?(uid)
824
- end
825
-
826
788
  it "be done automatically in presence of independent addition & removal of fields" do
827
789
  A.field :moose
828
790
  f1 = B.field_prototypes[:location]
@@ -840,46 +802,6 @@ describe "Schema" do
840
802
  refute m.key?(uid)
841
803
  end
842
804
 
843
- it "be done automatically in presence of independent changes to boxes & fields" do
844
- B.field :crisis
845
- uid = A.boxes[:posts].schema_id.to_s
846
- A.stubs(:box_prototypes).returns(S::Collections::PrototypeSet.new)
847
- S.schema.stubs(:classes).returns([A, B])
848
- S.schema.reload!
849
- S.schema.validate!
850
-
851
- ::B.field_prototypes[:crisis].schema_id.wont_be_nil
852
- m = YAML.load_file(@map_file)
853
- refute m.key?(uid)
854
- end
855
-
856
- it "be done automatically in presence of independent changes to classes, boxes & fields" do
857
- class ::X < B; end
858
- uid = A.boxes[:posts].schema_id.to_s
859
- A.stubs(:box_prototypes).returns(S::Collections::PrototypeSet.new)
860
- B.field :crisis
861
- B.box :circus
862
- A.field :crisis
863
- S.schema.stubs(:classes).returns([::A, ::B, ::X])
864
- S.schema.reload!
865
- S.schema.validate!
866
-
867
- ::A.field_prototypes[:crisis].schema_id.wont_be_nil
868
- m = YAML.load_file(@map_file)
869
-
870
- box = ::B.boxes[:circus]
871
- m[box.schema_id.to_s].must_equal box.schema_name
872
-
873
- field = ::A.field_prototypes[:crisis]
874
- m[field.schema_id.to_s].must_equal field.schema_name
875
-
876
- field = ::B.field_prototypes[:crisis]
877
- m[field.schema_id.to_s].must_equal field.schema_name
878
-
879
- refute m.key?(uid)
880
- end
881
-
882
-
883
805
  # sanity check
884
806
  it "still raise error in case of addition & deletion" do
885
807
  A.field :added
@@ -902,6 +824,28 @@ describe "Schema" do
902
824
  lambda { S.schema.validate! }.must_raise(Spontaneous::SchemaModificationError)
903
825
  end
904
826
 
827
+ it "raise an error if classes have been removed" do
828
+ uid = B.schema_id.to_s
829
+ Object.send(:remove_const, :B)
830
+ S.schema.stubs(:classes).returns([::A])
831
+ S.schema.reload!
832
+
833
+ lambda { S.schema.validate! }.must_raise(Spontaneous::SchemaModificationError)
834
+ end
835
+
836
+ it "raise an error if boxes have been removed" do
837
+ uid = A.boxes[:posts].schema_id.to_s
838
+ Object.send :remove_const, :A
839
+ class ::A < ::Page
840
+ field :title
841
+ field :introduction
842
+ layout :sparse
843
+ end
844
+ S.schema.stubs(:classes).returns([A, B])
845
+ S.schema.reload!
846
+ lambda { S.schema.validate! }.must_raise(Spontaneous::SchemaModificationError)
847
+ end
848
+
905
849
  it "delete box content when a box is removed" do
906
850
  instance = A.new
907
851
  piece1 = B.new
@@ -916,11 +860,92 @@ describe "Schema" do
916
860
  A.stubs(:box_prototypes).returns(S::Collections::PrototypeSet.new)
917
861
  S.schema.stubs(:classes).returns([A, B])
918
862
  S.schema.reload!
919
- S.schema.validate!
863
+
864
+ begin
865
+ S.schema.validate!
866
+ flunk("Validation should raise error when adding & deleting fields")
867
+ rescue Spontaneous::SchemaModificationError => e
868
+ @modification = e.modification
869
+ end
870
+ action = @modification.actions.first
871
+ S.schema.apply(action)
920
872
  Content.count.must_equal 1
921
873
  Content[instance.id].must_equal instance
922
874
  end
923
875
 
876
+ it "deletes type instances when a type is removed" do
877
+ Spontaneous::State.instance.update(must_publish_all: false)
878
+ @site.must_publish_all?.must_equal false
879
+ B.box :pages
880
+ A.box :pages
881
+ # a1
882
+ # |- b2
883
+ # |- a3
884
+ # |- a2
885
+ #
886
+ # b1
887
+ # |- a4
888
+ a1, a2, a3, a4 = A.create, A.create, A.create, A.create
889
+ b1, b2, b3 = B.create, B.create, B.create
890
+ a1.pages << b2
891
+ a1.pages << a2
892
+ b2.pages << a3
893
+ b1.pages << a4
894
+ [a1, a2, a3, a4, b1, b2, b3].each(&:save)
895
+ Content.count.must_equal 7
896
+ uid = B.schema_id.to_s
897
+ Object.send(:remove_const, :B)
898
+ S.schema.stubs(:classes).returns([::A])
899
+ S.schema.reload!
900
+ begin
901
+ S.schema.validate!
902
+ flunk("Validation should raise error when adding & deleting fields")
903
+ rescue Spontaneous::SchemaModificationError => e
904
+ @modification = e.modification
905
+ end
906
+ action = @modification.actions.first
907
+ S.schema.apply(action)
908
+ # The type filtering automatically filters out any instances belonging to the deleted type
909
+ # only a1 & a2 should be left
910
+ Content.count.must_equal 2
911
+ all = Content.order(:id).all
912
+ all.map(&:class).must_equal [A, A]
913
+ # to check that they're gone from the db i have to go a bit lower
914
+ content = S.database[:content].all
915
+ content.length.must_equal 2
916
+ content.map { |c| c[:type_sid] }.must_equal [A.schema_id.to_s, A.schema_id.to_s]
917
+ @site.must_publish_all?.must_equal true
918
+ end
919
+
920
+ it "doesn't mark the site as 'dirty' if no instances are deleted by the change in the schema" do
921
+ Spontaneous::State.instance.update(must_publish_all: false)
922
+ @site.must_publish_all?.must_equal false
923
+ A.box :pages
924
+ # a1
925
+ # |- b2
926
+ # |- a3
927
+ # |- a2
928
+ #
929
+ # b1
930
+ # |- a4
931
+ a = A.create
932
+ Content.count.must_equal 1
933
+ uid = B.schema_id.to_s
934
+ Object.send(:remove_const, :B)
935
+ S.schema.stubs(:classes).returns([::A])
936
+ S.schema.reload!
937
+ begin
938
+ S.schema.validate!
939
+ flunk("Validation should raise error when adding & deleting fields")
940
+ rescue Spontaneous::SchemaModificationError => e
941
+ @modification = e.modification
942
+ end
943
+ action = @modification.actions.first
944
+ S.schema.apply(action)
945
+ Content.count.must_equal 1
946
+ @site.must_publish_all?.must_equal false
947
+ end
948
+
924
949
  describe "conflict" do
925
950
  describe "-1 field" do
926
951
  before do
@@ -92,61 +92,61 @@ describe "Search" do
92
92
 
93
93
  describe "indexes" do
94
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
95
+ index = @site.index :arthur
96
+ @site.indexes[:arthur].must_be_instance_of Spontaneous::Search::Index
97
+ @site.indexes[:arthur].name.must_equal :arthur
98
+ @site.indexes[:arthur].must_equal index
99
99
  end
100
100
 
101
101
  it "default to indexing all content classes" do
102
- index = S::Site.index :all
102
+ index = @site.index :all
103
103
  assert_has_elements (@all_classes), index.search_types
104
104
  end
105
105
 
106
106
  it "allow restriction to particular classes" do
107
- index = S::Site.index :all do
107
+ index = @site.index :all do
108
108
  include_types ::PageClass1, "PageClass2", :PageClass3
109
109
  end
110
110
  assert_has_elements [::PageClass1, ::PageClass2, ::PageClass3], index.search_types
111
111
  end
112
112
 
113
113
  it "allow restriction to a class & its subclasses" do
114
- index = S::Site.index :all do
114
+ index = @site.index :all do
115
115
  include_types ">= PageClass1"
116
116
  end
117
117
  assert_has_elements [::PageClass1, ::PageClass3, ::PageClass5, ::PageClass6], index.search_types
118
118
  end
119
119
 
120
120
  it "allow restriction to a class's subclasses" do
121
- index = S::Site.index :all do
121
+ index = @site.index :all do
122
122
  include_types "> PageClass1"
123
123
  end
124
124
  assert_has_elements [::PageClass3, ::PageClass5, ::PageClass6], index.search_types
125
125
  end
126
126
 
127
127
  it "allow removal of particular classes" do
128
- index = S::Site.index :all do
128
+ index = @site.index :all do
129
129
  exclude_types ::PageClass1, "PageClass2"
130
130
  end
131
131
  assert_has_elements (@all_classes - [PageClass1, PageClass2]), index.search_types
132
132
  end
133
133
 
134
134
  it "allow removal of a class and its subclasses" do
135
- index = S::Site.index :all do
135
+ index = @site.index :all do
136
136
  exclude_types ">= PageClass1", PieceClass1
137
137
  end
138
138
  assert_has_elements (@all_classes - [::PageClass1, ::PageClass3, ::PageClass5, ::PageClass6, PieceClass1]), index.search_types
139
139
  end
140
140
 
141
141
  it "allow removal of a class's subclasses" do
142
- index = S::Site.index :all do
142
+ index = @site.index :all do
143
143
  exclude_types "> PageClass1"
144
144
  end
145
145
  assert_has_elements (@all_classes - [::PageClass3, ::PageClass5, ::PageClass6]), index.search_types
146
146
  end
147
147
 
148
148
  it "default to including all content" do
149
- index = S::Site.index :all
149
+ index = @site.index :all
150
150
  @all_pages.each do |page|
151
151
  assert index.include?(page)
152
152
  end
@@ -155,7 +155,7 @@ describe "Search" do
155
155
  it "allow restriction to a set of specific pages" do
156
156
  id = @root0.id
157
157
  path = @page8.path
158
- index = S::Site.index :all do
158
+ index = @site.index :all do
159
159
  include_pages id, "$page11", path
160
160
  end
161
161
 
@@ -164,7 +164,7 @@ describe "Search" do
164
164
  end
165
165
 
166
166
  it "allow restriction to a page and its children" do
167
- index = S::Site.index :all do
167
+ index = @site.index :all do
168
168
  include_pages ">= $page8"
169
169
  end
170
170
 
@@ -173,7 +173,7 @@ describe "Search" do
173
173
  end
174
174
 
175
175
  it "allow restriction to a page's children" do
176
- index = S::Site.index :all do
176
+ index = @site.index :all do
177
177
  include_pages "> $page8"
178
178
  end
179
179
 
@@ -182,7 +182,7 @@ describe "Search" do
182
182
  end
183
183
 
184
184
  it "allow removal of specific pages" do
185
- index = S::Site.index :all do
185
+ index = @site.index :all do
186
186
  exclude_pages "$page8", "/page1"
187
187
  end
188
188
 
@@ -191,7 +191,7 @@ describe "Search" do
191
191
  end
192
192
 
193
193
  it "allow removal of a page and its children" do
194
- index = S::Site.index :all do
194
+ index = @site.index :all do
195
195
  exclude_pages "/page1", ">= $page8"
196
196
  end
197
197
 
@@ -200,7 +200,7 @@ describe "Search" do
200
200
  end
201
201
 
202
202
  it "allow removal of a page's children" do
203
- index = S::Site.index :all do
203
+ index = @site.index :all do
204
204
  exclude_pages "/page1", "> $page8"
205
205
  end
206
206
 
@@ -209,7 +209,7 @@ describe "Search" do
209
209
  end
210
210
 
211
211
  it "allow multiple, mixed, page restrictions" do
212
- index = S::Site.index :all do
212
+ index = @site.index :all do
213
213
  include_pages "$page1", "> $page8"
214
214
  end
215
215
 
@@ -218,7 +218,7 @@ describe "Search" do
218
218
  end
219
219
 
220
220
  it "allow combining of class and page restrictions" do
221
- index = S::Site.index :all do
221
+ index = @site.index :all do
222
222
  exclude_types PageClass3, PageClass4
223
223
  include_pages "$page1", "> $page8"
224
224
  exclude_pages "$page10"
@@ -281,9 +281,9 @@ describe "Search" do
281
281
  #
282
282
  #
283
283
  before do
284
- @index1 = S::Site.index(:one)
285
- @index2 = S::Site.index(:two)
286
- @index3 = S::Site.index(:three) do
284
+ @index1 = @site.index(:one)
285
+ @index2 = @site.index(:two)
286
+ @index3 = @site.index(:three) do
287
287
  include_types PageClass1
288
288
  end
289
289
  end
@@ -304,7 +304,7 @@ describe "Search" do
304
304
  assert prototype_a.in_index?(@index2)
305
305
  assert prototype_a.in_index?(@index3)
306
306
  [:one, :two, :three].each do |name|
307
- index = S::Site.indexes[name]
307
+ index = @site.indexes[name]
308
308
  index.fields[PageClass1.fields[:a].schema_id.to_s][:weight].must_equal 16
309
309
  end
310
310
  end
@@ -348,20 +348,20 @@ describe "Search" do
348
348
 
349
349
  h = ::PageClass1.boxes.pages.instance_class.field :h, :index => :two
350
350
 
351
- S::Site.indexes[:one].fields.must_equal({
351
+ @site.indexes[:one].fields.must_equal({
352
352
  a.schema_id.to_s => { :type => String, :store => true, :index => false},
353
353
  b.schema_id.to_s => { :type => String, :store => true, :weight => 1, :index => true},
354
354
  c.schema_id.to_s => { :type => String, :store => true, :weight => 4, :index => true},
355
355
  g.schema_id.to_s => { :type => String, :store => true, :weight => 16, :index => true}
356
356
  })
357
357
 
358
- S::Site.indexes[:two].fields.must_equal({
358
+ @site.indexes[:two].fields.must_equal({
359
359
  :a => { :type => String, :store => true, :weight => 2, :index => true},
360
360
  g.schema_id.to_s => { :type => String, :store => true, :weight => 16, :index => true},
361
361
  h.schema_id.to_s => { :type => String, :store => true, :weight => 1, :index => true}
362
362
  })
363
363
 
364
- S::Site.indexes[:three].fields.must_equal({
364
+ @site.indexes[:three].fields.must_equal({
365
365
  e.schema_id.to_s => { :type => String, :store => true, :weight => 1, :index => true}
366
366
  })
367
367
  end
@@ -371,10 +371,10 @@ describe "Search" do
371
371
  before do
372
372
  @revision = 99
373
373
 
374
- @index1 = S::Site.index :one do
374
+ @index1 = @site.index :one do
375
375
  exclude_types PageClass3
376
376
  end
377
- @index2 = S::Site.index :two
377
+ @index2 = @site.index :two
378
378
 
379
379
  @a = PageClass1.field :a, :index => true
380
380
  @b = PageClass2.field :b, :index => true
@@ -430,7 +430,7 @@ describe "Search" do
430
430
  end
431
431
 
432
432
  it "only include specified pieces" do
433
- index = S::Site.index :four do
433
+ index = @site.index :four do
434
434
  include_types PageClass1, PieceClass1
435
435
  end
436
436
 
@@ -442,7 +442,7 @@ describe "Search" do
442
442
  end
443
443
 
444
444
  it "allow for page types to append their own custom indexable values" do
445
- index = S::Site.index :four do
445
+ index = @site.index :four do
446
446
  include_types PageClass1, PieceClass1
447
447
  end
448
448
  class ::PageClass1
@@ -461,7 +461,7 @@ describe "Search" do
461
461
  end
462
462
 
463
463
  it "deal with arrays of additional search index values" do
464
- index = S::Site.index :four do
464
+ index = @site.index :four do
465
465
  include_types PageClass1, PieceClass1
466
466
  end
467
467
  class ::PageClass1
@@ -482,7 +482,7 @@ describe "Search" do
482
482
  end
483
483
 
484
484
  it "allow for pieces to append their own custom indexable values" do
485
- index = S::Site.index :four do
485
+ index = @site.index :four do
486
486
  include_types PageClass1, PieceClass1
487
487
  end
488
488
  class ::PieceClass1
@@ -502,7 +502,7 @@ describe "Search" do
502
502
 
503
503
  it "create database in the right directory" do
504
504
  db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
505
- Site.stubs(:published_revision).returns(@revision)
505
+ @site.stubs(:published_revision).returns(@revision)
506
506
  mset = mock()
507
507
  mset.stubs(:matches).returns([])
508
508
  xapian = mock()
@@ -531,7 +531,7 @@ describe "Search" do
531
531
  it "pass on index configuration to the xapian db" do
532
532
  db_path = @site.revision_dir(@revision) / 'indexes' / 'name'
533
533
 
534
- index = Site.index :name do
534
+ index = @site.index :name do
535
535
  language :italian
536
536
  end
537
537
 
@@ -546,7 +546,7 @@ describe "Search" do
546
546
 
547
547
  db = index.create_db(@revision)
548
548
 
549
- index = Site.index :name do
549
+ index = @site.index :name do
550
550
  language :french
551
551
  stopper false
552
552
  stemmer false
@@ -570,7 +570,7 @@ describe "Search" do
570
570
 
571
571
  it "return (reasonable) results to searches" do
572
572
  db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
573
- S::Site.stubs(:published_revision).returns(@revision)
573
+ @site.stubs(:published_revision).returns(@revision)
574
574
  db = @index1.create_db(@revision)
575
575
  db << @page1
576
576
  db << @page2
@@ -605,7 +605,7 @@ describe "Search" do
605
605
 
606
606
  it "returns pages based on the contents of their boxes" do
607
607
  db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
608
- S::Site.stubs(:published_revision).returns(@revision)
608
+ @site.stubs(:published_revision).returns(@revision)
609
609
  db = @index1.create_db(@revision)
610
610
  db << @page1
611
611
  db << @page2
@@ -619,7 +619,7 @@ describe "Search" do
619
619
 
620
620
  it "respect weighting factors given to fields" do
621
621
  db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
622
- S::Site.stubs(:published_revision).returns(@revision)
622
+ @site.stubs(:published_revision).returns(@revision)
623
623
  db = @index1.create_db(@revision)
624
624
  @w = PieceClass1.field :w, :index => { :weight => 100 }
625
625
  @page1.pages << PieceClass1.new(:w => "findme")
@@ -641,11 +641,11 @@ describe "Search" do
641
641
 
642
642
  it "use the weighting specific to a subclass" do
643
643
  db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
644
- S::Site.stubs(:published_revision).returns(@revision)
644
+ @site.stubs(:published_revision).returns(@revision)
645
645
  @w = PieceClass1.field :w, :index => { :weight => 100 }
646
646
  WeightedPiece = Class.new(PieceClass1)
647
647
  WeightedPiece.field :w, :index => { :weight => 1}
648
- index = Site.index :weighted do
648
+ index = @site.index :weighted do
649
649
  end
650
650
  @page1.pages << WeightedPiece.new(:w => "findme")
651
651
  @page2.pages << PieceClass2.new(:h => "findme findme")
@@ -674,7 +674,7 @@ describe "Search" do
674
674
  db2.expects(:<<).with(@page1)
675
675
  db1.expects(:close)
676
676
  db2.expects(:close)
677
- S::Site.indexer(@revision) do |indexer|
677
+ @site.indexer(@revision) do |indexer|
678
678
  indexer.length.must_equal 2
679
679
  indexer << @page1
680
680
  end