spontaneous 0.2.0.alpha7 → 0.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. data/Gemfile +10 -4
  2. data/Readme.markdown +1 -1
  3. data/application/css/definitions.css.scss +5 -0
  4. data/application/css/dialogue.css.scss +62 -0
  5. data/application/js/content.js +1 -1
  6. data/application/js/dom.js +1 -1
  7. data/application/js/event_source.js +3 -0
  8. data/application/js/{field_types/date_field.js → field/date.js} +2 -2
  9. data/application/js/{field_types/file_field.js → field/file.js} +2 -2
  10. data/application/js/{field_types/image_field.js → field/image.js} +54 -20
  11. data/application/js/{field_types/long_string_field.js → field/long_string.js} +2 -2
  12. data/application/js/{field_types/markdown_field.js → field/markdown.js} +2 -2
  13. data/application/js/{field_types/select_field.js → field/select.js} +2 -2
  14. data/application/js/{field_types/string_field.js → field/string.js} +21 -7
  15. data/application/js/{field_types/webvideo_field.js → field/webvideo.js} +2 -2
  16. data/application/js/field.js +2 -2
  17. data/application/js/publish.js +99 -19
  18. data/application/js/spontaneous.js +8 -8
  19. data/application/js/top_bar.js +6 -4
  20. data/db/migrations/20130109125023_add_page_publish_lock.rb +17 -0
  21. data/db/migrations/20130111161934_convert_bcrypt_passwords.rb +22 -0
  22. data/db/migrations/20130114120000_create_revision_tables.rb +106 -0
  23. data/db/migrations/20130116220423_add_index_to_archive.rb +9 -0
  24. data/lib/spontaneous/box.rb +53 -18
  25. data/lib/spontaneous/box_style.rb +2 -3
  26. data/lib/spontaneous/change.rb +39 -13
  27. data/lib/spontaneous/cli/fields.rb +29 -0
  28. data/lib/spontaneous/cli/init.rb +2 -2
  29. data/lib/spontaneous/cli/migrate.rb +0 -1
  30. data/lib/spontaneous/cli/server.rb +14 -10
  31. data/lib/spontaneous/cli/site.rb +20 -9
  32. data/lib/spontaneous/cli.rb +8 -6
  33. data/lib/spontaneous/collections/box_set.rb +11 -0
  34. data/lib/spontaneous/collections/field_set.rb +24 -1
  35. data/lib/spontaneous/concern.rb +37 -0
  36. data/lib/spontaneous/config.rb +3 -4
  37. data/lib/spontaneous/crypt/version.rb +130 -0
  38. data/lib/spontaneous/crypt.rb +84 -0
  39. data/lib/spontaneous/data_mapper/content_model/associations.rb +199 -0
  40. data/lib/spontaneous/data_mapper/content_model/column_accessors.rb +52 -0
  41. data/lib/spontaneous/data_mapper/content_model/instance_hooks.rb +34 -0
  42. data/lib/spontaneous/data_mapper/content_model/serialization.rb +54 -0
  43. data/lib/spontaneous/data_mapper/content_model/timestamps.rb +39 -0
  44. data/lib/spontaneous/data_mapper/content_model.rb +343 -0
  45. data/lib/spontaneous/data_mapper/content_table.rb +103 -0
  46. data/lib/spontaneous/data_mapper/dataset.rb +194 -0
  47. data/lib/spontaneous/data_mapper/scope.rb +195 -0
  48. data/lib/spontaneous/data_mapper.rb +161 -0
  49. data/lib/spontaneous/facet.rb +2 -2
  50. data/lib/spontaneous/field/base.rb +418 -0
  51. data/lib/spontaneous/field/date.rb +54 -0
  52. data/lib/spontaneous/{field_version.rb → field/field_version.rb} +1 -1
  53. data/lib/spontaneous/field/file.rb +100 -0
  54. data/lib/spontaneous/{field_types/image_field.rb → field/image.rb} +33 -33
  55. data/lib/spontaneous/{field_types/location_field.rb → field/location.rb} +2 -2
  56. data/lib/spontaneous/{field_types/long_string_field.rb → field/long_string.rb} +3 -3
  57. data/lib/spontaneous/field/markdown.rb +36 -0
  58. data/lib/spontaneous/{field_types/select_field.rb → field/select.rb} +4 -5
  59. data/lib/spontaneous/field/string.rb +17 -0
  60. data/lib/spontaneous/field/update.rb +156 -0
  61. data/lib/spontaneous/field/webvideo.rb +310 -0
  62. data/lib/spontaneous/field.rb +80 -0
  63. data/lib/spontaneous/generators/site/Gemfile.tt +2 -2
  64. data/lib/spontaneous/generators/site/config/environments/development.rb.tt +1 -1
  65. data/lib/spontaneous/generators/site/config/environments/production.rb.tt +1 -1
  66. data/lib/spontaneous/generators/site/lib/content.rb.tt +6 -0
  67. data/lib/spontaneous/generators/site/schema/box.rb.tt +3 -2
  68. data/lib/spontaneous/generators/site/schema/page.rb.tt +3 -1
  69. data/lib/spontaneous/generators/site/schema/piece.rb.tt +3 -1
  70. data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +3 -1
  71. data/lib/spontaneous/generators/site.rb +4 -3
  72. data/lib/spontaneous/image_size.rb +8 -1
  73. data/lib/spontaneous/layout.rb +5 -1
  74. data/lib/spontaneous/loader.rb +2 -5
  75. data/lib/spontaneous/media/file.rb +11 -2
  76. data/lib/spontaneous/media/temp_file.rb +23 -0
  77. data/lib/spontaneous/media.rb +20 -39
  78. data/lib/spontaneous/{plugins → model/box}/allowed_types.rb +38 -17
  79. data/lib/spontaneous/model/box.rb +18 -0
  80. data/lib/spontaneous/{plugins → model/core}/aliases.rb +10 -14
  81. data/lib/spontaneous/{plugins → model/core}/boxes.rb +2 -2
  82. data/lib/spontaneous/{plugins → model/core}/content_groups.rb +2 -2
  83. data/lib/spontaneous/model/core/editor_class.rb +4 -0
  84. data/lib/spontaneous/{plugins → model/core}/entries.rb +19 -7
  85. data/lib/spontaneous/{plugins → model/core}/entry.rb +3 -3
  86. data/lib/spontaneous/{plugins → model/core}/fields.rb +38 -5
  87. data/lib/spontaneous/{plugins → model/core}/instance_code.rb +2 -2
  88. data/lib/spontaneous/{plugins → model/core}/media.rb +2 -12
  89. data/lib/spontaneous/{plugins → model/core}/modifications.rb +7 -6
  90. data/lib/spontaneous/model/core/page_search.rb +36 -0
  91. data/lib/spontaneous/{plugins → model/core}/permissions.rb +4 -4
  92. data/lib/spontaneous/{plugins → model/core}/prototypes.rb +4 -4
  93. data/lib/spontaneous/{plugins → model/core}/publishing.rb +93 -115
  94. data/lib/spontaneous/{plugins → model/core}/render.rb +2 -2
  95. data/lib/spontaneous/{plugins → model/core}/schema_hierarchy.rb +7 -11
  96. data/lib/spontaneous/model/core/schema_id.rb +65 -0
  97. data/lib/spontaneous/{plugins → model/core}/schema_title.rb +2 -2
  98. data/lib/spontaneous/{plugins → model/core}/serialisation.rb +2 -2
  99. data/lib/spontaneous/{plugins → model/core}/styles.rb +2 -2
  100. data/lib/spontaneous/{plugins → model/core}/supertype.rb +2 -2
  101. data/lib/spontaneous/{plugins → model/core}/visibility.rb +7 -48
  102. data/lib/spontaneous/model/core.rb +143 -0
  103. data/lib/spontaneous/{plugins → model/page}/controllers.rb +3 -3
  104. data/lib/spontaneous/{plugins → model}/page/formats.rb +2 -2
  105. data/lib/spontaneous/{plugins → model/page}/layouts.rb +2 -2
  106. data/lib/spontaneous/model/page/locks.rb +14 -0
  107. data/lib/spontaneous/{plugins → model/page}/page_tree.rb +3 -3
  108. data/lib/spontaneous/{plugins → model/page}/paths.rb +30 -12
  109. data/lib/spontaneous/{plugins → model}/page/request.rb +2 -2
  110. data/lib/spontaneous/{plugins → model/page}/site_map.rb +2 -2
  111. data/lib/spontaneous/model/page/site_timestamps.rb +44 -0
  112. data/lib/spontaneous/{page.rb → model/page.rb} +49 -28
  113. data/lib/spontaneous/{piece.rb → model/piece.rb} +7 -6
  114. data/lib/spontaneous/model.rb +97 -0
  115. data/lib/spontaneous/output/context.rb +1 -1
  116. data/lib/spontaneous/output/format.rb +4 -0
  117. data/lib/spontaneous/output/template/renderer.rb +2 -2
  118. data/lib/spontaneous/output.rb +2 -2
  119. data/lib/spontaneous/page_lock.rb +62 -0
  120. data/lib/spontaneous/page_piece.rb +1 -1
  121. data/lib/spontaneous/permissions/access_key.rb +9 -4
  122. data/lib/spontaneous/permissions/user.rb +19 -9
  123. data/lib/spontaneous/permissions.rb +2 -5
  124. data/lib/spontaneous/plugins/application/facets.rb +1 -2
  125. data/lib/spontaneous/plugins/application/features.rb +1 -1
  126. data/lib/spontaneous/plugins/application/paths.rb +1 -1
  127. data/lib/spontaneous/plugins/application/render.rb +1 -1
  128. data/lib/spontaneous/plugins/application/serialisation.rb +1 -1
  129. data/lib/spontaneous/plugins/application/state.rb +30 -1
  130. data/lib/spontaneous/plugins/application/system.rb +12 -12
  131. data/lib/spontaneous/prototypes/box_prototype.rb +1 -1
  132. data/lib/spontaneous/prototypes/field_prototype.rb +3 -6
  133. data/lib/spontaneous/prototypes/style_prototype.rb +1 -1
  134. data/lib/spontaneous/publishing/immediate.rb +77 -49
  135. data/lib/spontaneous/publishing/revision.rb +355 -0
  136. data/lib/spontaneous/publishing/simultaneous.rb +10 -49
  137. data/lib/spontaneous/publishing.rb +1 -0
  138. data/lib/spontaneous/rack/around_back.rb +1 -1
  139. data/lib/spontaneous/rack/around_front.rb +2 -4
  140. data/lib/spontaneous/rack/around_preview.rb +1 -1
  141. data/lib/spontaneous/rack/back.rb +80 -63
  142. data/lib/spontaneous/rack/cacheable_file.rb +2 -2
  143. data/lib/spontaneous/rack/cookie_authentication.rb +1 -1
  144. data/lib/spontaneous/rack/front.rb +1 -1
  145. data/lib/spontaneous/rack/helpers.rb +8 -9
  146. data/lib/spontaneous/{page_controller.rb → rack/page_controller.rb} +1 -1
  147. data/lib/spontaneous/rack/public.rb +3 -3
  148. data/lib/spontaneous/rack.rb +15 -15
  149. data/lib/spontaneous/schema/uid.rb +4 -1
  150. data/lib/spontaneous/schema.rb +57 -24
  151. data/lib/spontaneous/search/database.rb +12 -1
  152. data/lib/spontaneous/search/index.rb +34 -6
  153. data/lib/spontaneous/search/results.rb +1 -1
  154. data/lib/spontaneous/server.rb +3 -3
  155. data/lib/spontaneous/simultaneous.rb +53 -0
  156. data/lib/spontaneous/{plugins/site → site}/features.rb +2 -2
  157. data/lib/spontaneous/{plugins/site → site}/helpers.rb +2 -3
  158. data/lib/spontaneous/{plugins/site → site}/hooks.rb +2 -2
  159. data/lib/spontaneous/{plugins/site → site}/instance.rb +4 -6
  160. data/lib/spontaneous/{plugins/site → site}/level.rb +2 -2
  161. data/lib/spontaneous/{plugins/site → site}/map.rb +4 -4
  162. data/lib/spontaneous/{plugins/site → site}/paths.rb +2 -2
  163. data/lib/spontaneous/site/publishing.rb +89 -0
  164. data/lib/spontaneous/{plugins/site → site}/schema.rb +4 -4
  165. data/lib/spontaneous/{plugins/site → site}/search.rb +2 -2
  166. data/lib/spontaneous/{plugins/site → site}/selectors.rb +15 -7
  167. data/lib/spontaneous/{plugins/site → site}/state.rb +2 -2
  168. data/lib/spontaneous/{plugins/site → site}/storage.rb +2 -2
  169. data/lib/spontaneous/{plugins/site → site}/url.rb +2 -2
  170. data/lib/spontaneous/site.rb +31 -14
  171. data/lib/spontaneous/state.rb +5 -6
  172. data/lib/spontaneous/style.rb +3 -2
  173. data/lib/spontaneous/utils/database/mysql_dumper.rb +13 -0
  174. data/lib/spontaneous/utils/database/postgres_dumper.rb +5 -0
  175. data/lib/spontaneous/version.rb +1 -1
  176. data/lib/spontaneous.rb +34 -89
  177. data/spontaneous.gemspec +112 -114
  178. data/test/experimental/test_crypt.rb +158 -0
  179. data/test/experimental/test_features.rb +3 -3
  180. data/test/fixtures/example_application/config/environments/development.rb +1 -1
  181. data/test/fixtures/example_application/lib/content.rb +5 -0
  182. data/test/fixtures/example_application/schema/page.rb +2 -1
  183. data/test/fixtures/example_application/schema/piece.rb +3 -2
  184. data/test/fixtures/serialisation/class_hash.yaml.erb +5 -5
  185. data/test/fixtures/serialisation/root_hash.yaml.erb +8 -0
  186. data/test/functional/test_application.rb +12 -1
  187. data/test/functional/test_back.rb +80 -48
  188. data/test/functional/test_front.rb +39 -46
  189. data/test/functional/test_user_manager.rb +3 -9
  190. data/test/javascript/test_markdown.rb +2 -2
  191. data/test/test_helper.rb +78 -23
  192. data/test/unit/test_alias.rb +21 -15
  193. data/test/unit/test_asset_bundler.rb +3 -3
  194. data/test/unit/test_assets.rb +2 -2
  195. data/test/unit/test_async.rb +7 -6
  196. data/test/unit/test_authentication.rb +43 -37
  197. data/test/unit/test_boxes.rb +46 -21
  198. data/test/unit/test_changesets.rb +65 -20
  199. data/test/unit/test_config.rb +9 -9
  200. data/test/unit/test_content.rb +50 -51
  201. data/test/unit/test_content_inheritance.rb +6 -20
  202. data/test/unit/test_datamapper.rb +1330 -0
  203. data/test/unit/test_datamapper_content.rb +214 -0
  204. data/test/unit/test_fields.rb +543 -54
  205. data/test/unit/test_formats.rb +2 -3
  206. data/test/unit/test_generators.rb +6 -6
  207. data/test/unit/test_helpers.rb +1 -1
  208. data/test/unit/test_image_size.rb +10 -5
  209. data/test/unit/test_images.rb +17 -18
  210. data/test/unit/test_layouts.rb +18 -3
  211. data/test/unit/test_media.rb +74 -49
  212. data/test/unit/test_modifications.rb +43 -43
  213. data/test/unit/test_page.rb +7 -10
  214. data/test/unit/test_permissions.rb +3 -10
  215. data/test/unit/test_piece.rb +5 -6
  216. data/test/unit/test_plugins.rb +7 -14
  217. data/test/unit/test_prototypes.rb +3 -3
  218. data/test/unit/test_publishing.rb +49 -27
  219. data/test/unit/test_render.rb +46 -15
  220. data/test/unit/test_revisions.rb +124 -127
  221. data/test/unit/test_schema.rb +53 -58
  222. data/test/unit/test_search.rb +64 -16
  223. data/test/unit/test_serialisation.rb +4 -11
  224. data/test/unit/test_site.rb +11 -12
  225. data/test/unit/test_structure.rb +2 -5
  226. data/test/unit/test_styles.rb +22 -24
  227. data/test/unit/test_type_hierarchy.rb +7 -5
  228. data/test/unit/test_visibility.rb +79 -55
  229. metadata +128 -102
  230. data/lib/sequel/plugins/content_table_inheritance.rb +0 -203
  231. data/lib/sequel/plugins/scoped_table_name.rb +0 -54
  232. data/lib/spontaneous/content.rb +0 -129
  233. data/lib/spontaneous/field_types/date_field.rb +0 -56
  234. data/lib/spontaneous/field_types/field.rb +0 -302
  235. data/lib/spontaneous/field_types/file_field.rb +0 -68
  236. data/lib/spontaneous/field_types/markdown_field.rb +0 -38
  237. data/lib/spontaneous/field_types/string_field.rb +0 -19
  238. data/lib/spontaneous/field_types/webvideo_field.rb +0 -313
  239. data/lib/spontaneous/field_types.rb +0 -38
  240. data/lib/spontaneous/generators/site/lib/site.rb.tt +0 -4
  241. data/lib/spontaneous/plugins/field/editor_class.rb +0 -13
  242. data/lib/spontaneous/plugins/page/site_timestamps.rb +0 -28
  243. data/lib/spontaneous/plugins/page_search.rb +0 -63
  244. data/lib/spontaneous/plugins/schema_id.rb +0 -68
  245. data/lib/spontaneous/plugins/site/publishing.rb +0 -75
  246. data/lib/spontaneous/rack/fiber_pool.rb +0 -26
  247. data/test/unit/test_table_scoping.rb +0 -80
@@ -4,12 +4,11 @@ require File.expand_path('../../test_helper', __FILE__)
4
4
 
5
5
 
6
6
  class SchemaTest < MiniTest::Spec
7
- include Spontaneous
8
-
9
-
10
7
  def setup
11
8
  @site = setup_site
12
9
  @site.schema_loader_class = Spontaneous::Schema::PersistentMap
10
+ S::Permissions::UserLevel.reset!
11
+ S::Permissions::UserLevel.stubs(:level_file).returns(File.expand_path('../../fixtures/permissions', __FILE__) / 'config/user_levels.yml')
13
12
  end
14
13
 
15
14
  def teardown
@@ -18,9 +17,9 @@ class SchemaTest < MiniTest::Spec
18
17
 
19
18
  context "Configurable names" do
20
19
  setup do
21
- class ::FunkyContent < Content; end
20
+ class ::FunkyContent < Piece; end
22
21
  class ::MoreFunkyContent < FunkyContent; end
23
- class ::ABCDifficultName < Content; end
22
+ class ::ABCDifficultName < Piece; end
24
23
 
25
24
  class ::CustomName < ABCDifficultName
26
25
  title "Some Name"
@@ -68,8 +67,10 @@ class SchemaTest < MiniTest::Spec
68
67
  layout :clean
69
68
  box :posts
70
69
  end
70
+ # force loading of map
71
+ @site.schema.map
71
72
  @instance = SchemaClass.new
72
- @uids = @site.uid
73
+ @uids = @site.schema.uids
73
74
  end
74
75
 
75
76
  teardown do
@@ -81,7 +82,7 @@ class SchemaTest < MiniTest::Spec
81
82
  # end
82
83
 
83
84
  should "be unique" do
84
- ids = (0..10000).map { Schema::UIDMap.generate }
85
+ ids = (0..10000).map { S::Schema::UIDMap.generate }
85
86
  ids.uniq.length.should == ids.length
86
87
  end
87
88
 
@@ -146,19 +147,19 @@ class SchemaTest < MiniTest::Spec
146
147
 
147
148
  context "lookups" do
148
149
  should "return classes" do
149
- Site.schema["xxxxxxxxxxxx"].should == SchemaClass
150
+ Site.schema.to_class("xxxxxxxxxxxx").should == SchemaClass
150
151
  end
151
152
  should "return fields" do
152
- Site.schema["ffffffffffff"].should == SchemaClass.field_prototypes[:description]
153
+ Site.schema.to_class("ffffffffffff").should == SchemaClass.field_prototypes[:description]
153
154
  end
154
155
  should "return boxes" do
155
- Site.schema["bbbbbbbbbbbb"].should == SchemaClass.box_prototypes[:posts]
156
+ Site.schema.to_class("bbbbbbbbbbbb").should == SchemaClass.box_prototypes[:posts]
156
157
  end
157
158
  should "return styles" do
158
- Site.schema["ssssssssssss"].should == SchemaClass.style_prototypes[:simple]
159
+ Site.schema.to_class("ssssssssssss").should == SchemaClass.style_prototypes[:simple]
159
160
  end
160
161
  should "return layouts" do
161
- Site.schema["llllllllllll"].should == SchemaClass.layout_prototypes[:clean]
162
+ Site.schema.to_class("llllllllllll").should == SchemaClass.layout_prototypes[:clean]
162
163
  end
163
164
  end
164
165
 
@@ -167,12 +168,10 @@ class SchemaTest < MiniTest::Spec
167
168
  context "schema verification" do
168
169
  setup do
169
170
  @site.schema.schema_map_file = File.expand_path('../../fixtures/schema/before.yml', __FILE__)
170
- class ::Page < Spontaneous::Page
171
- field :title
172
- end
171
+ Page.field :title
173
172
  class B < ::Page; end
174
- class C < Content; end
175
- class D < Content; end
173
+ class C < Piece; end
174
+ class D < Piece; end
176
175
  class O < Box; end
177
176
  B.field :description
178
177
  B.field :author
@@ -199,6 +198,7 @@ class SchemaTest < MiniTest::Spec
199
198
  # between tests
200
199
  # Schema.stubs(:classes).returns([B, C, D, O])
201
200
  # Schema.classes.should == [B, C, D, O]
201
+ @site.schema.map
202
202
  @uids = @site.schema.uids
203
203
  ::Page.schema_id.should == @uids["tttttttttttt"]
204
204
  B.schema_id.should == @uids["bbbbbbbbbbbb"]
@@ -224,7 +224,7 @@ class SchemaTest < MiniTest::Spec
224
224
  end
225
225
 
226
226
  should "detect addition of classes" do
227
- class E < Content; end
227
+ class E < ::Piece; end
228
228
  @site.schema.stubs(:classes).returns([B, C, D, E])
229
229
  exception = nil
230
230
  begin
@@ -477,8 +477,8 @@ class SchemaTest < MiniTest::Spec
477
477
  context "Transient (testing) maps" do
478
478
  setup do
479
479
  @site.schema.schema_loader_class = Spontaneous::Schema::TransientMap
480
- class V < Spontaneous::Piece; end
481
- class W < Spontaneous::Piece; end
480
+ class V < ::Piece; end
481
+ class W < ::Piece; end
482
482
  end
483
483
  teardown do
484
484
  self.class.send(:remove_const, :V)
@@ -503,7 +503,7 @@ class SchemaTest < MiniTest::Spec
503
503
 
504
504
  context "for inherited boxes" do
505
505
  setup do
506
- class ::A < Spontaneous::Piece
506
+ class ::A < ::Piece
507
507
  box :a
508
508
  end
509
509
  class ::B < ::A
@@ -529,13 +529,13 @@ class SchemaTest < MiniTest::Spec
529
529
 
530
530
  context "Schema groups" do
531
531
  setup do
532
- class ::A < Spontaneous::Page
532
+ class ::A < ::Page
533
533
  group :a, :b, :c
534
534
  box :cgroup do
535
535
  allow_group :c
536
536
  end
537
537
  end
538
- class ::B < Spontaneous::Piece
538
+ class ::B < ::Piece
539
539
  group :b, :c
540
540
  style :fish
541
541
  style :frog
@@ -544,7 +544,7 @@ class SchemaTest < MiniTest::Spec
544
544
  allow_groups :a, :c
545
545
  end
546
546
  end
547
- class ::C < Spontaneous::Piece
547
+ class ::C < ::Piece
548
548
  group :c
549
549
 
550
550
  box :bgroup do
@@ -571,10 +571,13 @@ class SchemaTest < MiniTest::Spec
571
571
 
572
572
  should "apply the options to all the included classes" do
573
573
  user = mock()
574
+ S::Permissions.stubs(:has_level?).with(user, S::Permissions::UserLevel.editor).returns(true)
574
575
  S::Permissions.stubs(:has_level?).with(user, S::Permissions::UserLevel.root).returns(true)
575
- A.boxes.cgroup.allowed_types(user).should == [A, B, C]
576
+ C.boxes.cgroup.allowed_types(user).should == [A, B, C]
577
+ S::Permissions.stubs(:has_level?).with(user, S::Permissions::UserLevel.editor).returns(true)
576
578
  S::Permissions.stubs(:has_level?).with(user, S::Permissions::UserLevel.root).returns(false)
577
- A.boxes.cgroup.allowed_types(user).should == []
579
+ C.boxes.cgroup.allowed_types(user).should == []
580
+ A.boxes.cgroup.allowed_types(user).should == [A, B, C]
578
581
  end
579
582
 
580
583
  should "allow for configuring styles" do
@@ -591,7 +594,7 @@ class SchemaTest < MiniTest::Spec
591
594
  @site.schema.delete(::B)
592
595
  Object.send(:remove_const, :B)
593
596
 
594
- class ::B < Spontaneous::Piece
597
+ class ::B < ::Piece
595
598
  group :b
596
599
  style :fish
597
600
  style :frog
@@ -612,7 +615,7 @@ class SchemaTest < MiniTest::Spec
612
615
  context "Map writing" do
613
616
  context "Non-existant maps" do
614
617
  def expected_schema
615
- classes = [ ::A, ::B]
618
+ classes = @site.schema.classes#[ Content::Page, Page, Content::Piece, Piece, ::A, ::B]
616
619
  expected = Hash[ classes.map { |klass| [ klass.schema_id.to_s, klass.schema_name ] } ]
617
620
  expected.merge!({
618
621
  A.field_prototypes[:title].schema_id.to_s => A.field_prototypes[:title].schema_name,
@@ -632,7 +635,7 @@ class SchemaTest < MiniTest::Spec
632
635
  ::FileUtils.rm_f(@map_file) if ::File.exists?(@map_file)
633
636
 
634
637
  @site.schema.schema_map_file = @map_file
635
- class ::A < Spontaneous::Page
638
+ class ::A < ::Page
636
639
  field :title
637
640
  field :introduction
638
641
  layout :sparse
@@ -640,7 +643,7 @@ class SchemaTest < MiniTest::Spec
640
643
  field :description
641
644
  end
642
645
  end
643
- class ::B < Spontaneous::Piece
646
+ class ::B < ::Piece
644
647
  field :location
645
648
  style :daring
646
649
  end
@@ -678,7 +681,7 @@ class SchemaTest < MiniTest::Spec
678
681
  FileUtils.mkdir_p(File.dirname(@map_file))
679
682
  FileUtils.cp(File.expand_path('../../fixtures/schema/resolvable.yml', __FILE__), @map_file)
680
683
  @site.schema.schema_map_file = @map_file
681
- class ::A < Spontaneous::Page
684
+ class ::A < ::Page
682
685
  field :title
683
686
  field :introduction
684
687
  layout :sparse
@@ -686,7 +689,7 @@ class SchemaTest < MiniTest::Spec
686
689
  field :description
687
690
  end
688
691
  end
689
- class ::B < Spontaneous::Piece
692
+ class ::B < ::Piece
690
693
  field :location
691
694
  field :duration
692
695
  style :daring
@@ -700,26 +703,10 @@ class SchemaTest < MiniTest::Spec
700
703
  Object.send(:remove_const, :B) rescue nil
701
704
  Object.send(:remove_const, :X) rescue nil
702
705
  Object.send(:remove_const, :Y) rescue nil
703
- S::Content.delete
706
+ ::Content.delete
704
707
  FileUtils.rm(@map_file) if ::File.exists?(@map_file) rescue nil
705
708
  end
706
709
 
707
- should "update the STI map after addition of classes" do
708
- ::A.sti_subclasses_array.should == [::A.schema_id.to_s]
709
- class ::X < ::A
710
- field :wild
711
- box :monkeys do
712
- field :banana
713
- end
714
- layout :rich
715
- end
716
- S.schema.validate!
717
- ::X.schema_id.should_not be_nil
718
- ::X.sti_key_array.should == [::X.schema_id.to_s]
719
- ::A.sti_subclasses_array.should == [::A.schema_id.to_s, ::X.schema_id.to_s]
720
- end
721
-
722
-
723
710
  should "be done automatically if only additions are found" do
724
711
  A.field :moose
725
712
  class ::X < ::A
@@ -760,7 +747,12 @@ class SchemaTest < MiniTest::Spec
760
747
 
761
748
  should "be done automatically if only boxes have been removed" do
762
749
  uid = A.boxes[:posts].schema_id.to_s
763
- A.stubs(:box_prototypes).returns(S::Collections::PrototypeSet.new)
750
+ Object.send :remove_const, :A
751
+ class ::A < ::Page
752
+ field :title
753
+ field :introduction
754
+ layout :sparse
755
+ end
764
756
  S.schema.stubs(:classes).returns([A, B])
765
757
  S.schema.reload!
766
758
  S.schema.validate!
@@ -768,12 +760,15 @@ class SchemaTest < MiniTest::Spec
768
760
  m.key?(uid).should be_false
769
761
  end
770
762
 
771
- should "be done automatically if only fields have been removed" do
772
- f1 = A.field_prototypes[:title]
773
- uid = f1.schema_id.to_s
774
- f2 = A.field_prototypes[:introduction]
775
- A.stubs(:field_prototypes).returns({:introduction => f2})
776
- A.stubs(:fields).returns([f2])
763
+ should "be done automatically if only fields have been removed xxx" do
764
+ uid = A.fields[:title].schema_id.to_s
765
+ S.schema.delete(::A)
766
+ Object.send :remove_const, :A
767
+ class ::A < ::Page
768
+ field :introduction
769
+ layout :sparse
770
+ box(:posts) { field :description }
771
+ end
777
772
  S.schema.reload!
778
773
  S.schema.validate!
779
774
  m = YAML.load_file(@map_file)
@@ -880,7 +875,7 @@ class SchemaTest < MiniTest::Spec
880
875
  instance.posts << piece1
881
876
  instance.posts << piece2
882
877
  instance.save
883
- instance = S::Content[instance.id]
878
+ instance = Content[instance.id]
884
879
  instance.posts.contents.length.should == 2
885
880
  Content.count.should == 3
886
881
  uid = A.boxes[:posts].schema_id.to_s
@@ -889,7 +884,7 @@ class SchemaTest < MiniTest::Spec
889
884
  S.schema.reload!
890
885
  S.schema.validate!
891
886
  Content.count.should == 1
892
- S::Content[instance.id].should == instance
887
+ Content[instance.id].should == instance
893
888
  end
894
889
 
895
890
  context "which isn't automatically resolvable" do
@@ -27,13 +27,13 @@ class SearchTest < MiniTest::Spec
27
27
 
28
28
  def self.startup
29
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))
30
+ # setup_site
31
+ # *ids = S::Page.schema_id, S::Piece.schema_id
32
+ # Object.const_set(:Site, Class.new(S::Site))
33
33
  end
34
34
 
35
35
  def self.shutdown
36
- Object.send(:remove_const, :Site) rescue nil
36
+ # Object.send(:remove_const, :Site) rescue nil
37
37
  end
38
38
 
39
39
  def setup
@@ -49,8 +49,8 @@ class SearchTest < MiniTest::Spec
49
49
  Content.delete
50
50
 
51
51
 
52
- class ::Piece < S::Piece; end
53
- class ::Page < S::Page; end
52
+ # class ::Piece < S::Piece; end
53
+ # class ::Page < S::Page; end
54
54
  b = ::Page.box :pages
55
55
  # instantiate box instance class to it gets added to schema
56
56
  ::Page.boxes.pages.instance_class.schema_id
@@ -68,7 +68,7 @@ class SearchTest < MiniTest::Spec
68
68
 
69
69
  @all_page_classes = [::Page, ::PageClass1, ::PageClass2, ::PageClass3, ::PageClass4, ::PageClass5, ::PageClass6]
70
70
  @all_piece_classes = [::Piece, ::PieceClass1, ::PieceClass2, ::PieceClass3]
71
- @all_box_classes = [ ::Page::PagesBox ]
71
+ @all_box_classes = [ ::Box, ::Page::PagesBox ]
72
72
  @all_classes = @all_page_classes + @all_piece_classes + @all_box_classes
73
73
 
74
74
  @root0 = ::Page.create(:uid => "root")
@@ -401,7 +401,7 @@ class SearchTest < MiniTest::Spec
401
401
  @l = ::PageClass1.boxes.pages.instance_class.field :l, :index => true
402
402
 
403
403
  @page1.a = "a value 1"
404
- @page1.pages.first.a = "a value 2"
404
+ @page1.pages.first.a = "a value 2"
405
405
  @page1.pages.l = "l value 1"
406
406
 
407
407
  @piece1 = PieceClass1.new(:g => "g value 1")
@@ -520,14 +520,14 @@ class SearchTest < MiniTest::Spec
520
520
  xapian.expects(:search).with('"value 2"', {}).returns(XapianFu::ResultSet.new(:mset => mset))
521
521
  xapian.expects(:flush)
522
522
 
523
- XapianFu::XapianDb.expects(:new).with({
523
+ XapianFu::XapianDb.expects(:new).with(has_entries({
524
524
  :dir => db_path,
525
525
  :create => true,
526
526
  :overwrite => true,
527
527
  :language => :english,
528
528
  :fields => @index1.fields,
529
529
  :spelling => true
530
- }).returns(xapian)
530
+ })).returns(xapian)
531
531
 
532
532
  db = @index1.create_db(@revision)
533
533
  assert File.directory?(db_path)
@@ -545,14 +545,14 @@ class SearchTest < MiniTest::Spec
545
545
  language :italian
546
546
  end
547
547
 
548
- XapianFu::XapianDb.expects(:new).with({
548
+ XapianFu::XapianDb.expects(:new).with(has_entries({
549
549
  :dir => db_path,
550
550
  :create => true,
551
551
  :overwrite => true,
552
552
  :language => :italian,
553
553
  :fields => index.fields,
554
554
  :spelling => true
555
- })
555
+ }))
556
556
 
557
557
  db = index.create_db(@revision)
558
558
 
@@ -562,7 +562,7 @@ class SearchTest < MiniTest::Spec
562
562
  stemmer false
563
563
  end
564
564
 
565
- XapianFu::XapianDb.expects(:new).with({
565
+ XapianFu::XapianDb.expects(:new).with(has_entries({
566
566
  :dir => db_path,
567
567
  :create => true,
568
568
  :overwrite => true,
@@ -571,7 +571,7 @@ class SearchTest < MiniTest::Spec
571
571
  :stopper => false,
572
572
  :fields => index.fields,
573
573
  :spelling => true
574
- })
574
+ }))
575
575
 
576
576
  db = index.create_db(@revision)
577
577
 
@@ -580,7 +580,7 @@ class SearchTest < MiniTest::Spec
580
580
 
581
581
  should "return (reasonable) results to searches" do
582
582
  db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
583
- Site.stubs(:published_revision).returns(@revision)
583
+ S::Site.stubs(:published_revision).returns(@revision)
584
584
  db = @index1.create_db(@revision)
585
585
  db << @page1
586
586
  db << @page2
@@ -590,7 +590,7 @@ class SearchTest < MiniTest::Spec
590
590
  results = @index1.search('+valeu', :limit => 1, :autocorrect => true)
591
591
  results.must_be_instance_of S::Search::Results
592
592
  results.each do |result|
593
- result.class.should < S::Page
593
+ result.class.should < Content::Page
594
594
  end
595
595
 
596
596
  results.corrected_query.should == '+value'
@@ -613,6 +613,54 @@ class SearchTest < MiniTest::Spec
613
613
  FileUtils.rm_r(db_path)
614
614
  end
615
615
 
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
+
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
663
+
616
664
  should "provide a convenient way to add documents to multiple indexes" do
617
665
  db1 = mock()
618
666
  db2 = mock()
@@ -5,7 +5,6 @@ require 'erb'
5
5
 
6
6
 
7
7
  class SerialisationTest < MiniTest::Spec
8
- include Spontaneous
9
8
 
10
9
  def setup
11
10
  @site = setup_site
@@ -18,13 +17,9 @@ class SerialisationTest < MiniTest::Spec
18
17
  context "Content" do
19
18
  setup do
20
19
  Content.delete
21
- class ::Page < Spontaneous::Page
22
- field :title, :string, :default => "New Page"
23
- end
20
+ Page.field :title, :string, :default => "New Page"
24
21
 
25
- class ::Piece < Spontaneous::Piece
26
- style :tepid
27
- end
22
+ Piece.style :tepid
28
23
 
29
24
  class ::SerialisedPage < ::Page
30
25
  field :direction, :title => "Pointing Direction", :comment => "NSEW" do
@@ -83,8 +78,6 @@ class SerialisationTest < MiniTest::Spec
83
78
  end
84
79
 
85
80
  teardown do
86
- Object.send(:remove_const, :Page)
87
- Object.send(:remove_const, :Piece)
88
81
  Object.send(:remove_const, :SerialisedPiece)
89
82
  Object.send(:remove_const, :SerialisedPage)
90
83
  end
@@ -95,7 +88,7 @@ class SerialisationTest < MiniTest::Spec
95
88
  pp SerialisedPiece.export; puts "="*60; pp @class_hash
96
89
  end
97
90
  # SerialisedPiece.export.should == @class_hash
98
- assert_hashes_equal(SerialisedPiece.export, @class_hash)
91
+ assert_hashes_equal(@class_hash, SerialisedPiece.export)
99
92
  end
100
93
  should "serialise to JSON" do
101
94
  Spot::deserialise_http(SerialisedPiece.serialise_http).should == @class_hash
@@ -103,7 +96,7 @@ class SerialisationTest < MiniTest::Spec
103
96
  should "include the title field name in the serialisation of page types" do
104
97
  SerialisedPage.export(nil)[:title_field].should == 'title'
105
98
  end
106
- should "use JS friendly names for type keys" do
99
+ should "use JS friendly names for type keys xxx" do
107
100
  class ::SerialisedPage
108
101
  class InnerClass < Piece
109
102
  end
@@ -4,7 +4,6 @@ require File.expand_path('../../test_helper', __FILE__)
4
4
 
5
5
 
6
6
  class SiteTest < MiniTest::Spec
7
- include Spontaneous
8
7
 
9
8
  def setup
10
9
  @site = setup_site
@@ -17,16 +16,8 @@ class SiteTest < MiniTest::Spec
17
16
  context "Site" do
18
17
  setup do
19
18
  Content.delete
20
- class ::Page < Spontaneous::Page
21
- field :title
22
- box :subpages
23
- end
24
- class ::Piece < Spontaneous::Piece; end
25
- end
26
-
27
- teardown do
28
- Object.send(:remove_const, :Page)
29
- Object.send(:remove_const, :Piece)
19
+ Page.field :title
20
+ Page.box :subpages
30
21
  end
31
22
 
32
23
  context "contents" do
@@ -170,7 +161,7 @@ class SiteTest < MiniTest::Spec
170
161
 
171
162
  context "Structure modification times" do
172
163
  setup do
173
- State.delete
164
+ S::State.delete
174
165
  # remove microseconds from time value
175
166
  @now = Time.at(Time.now.to_i)
176
167
  end
@@ -197,6 +188,14 @@ class SiteTest < MiniTest::Spec
197
188
  Site.modified_at.should == now
198
189
  end
199
190
 
191
+ should "be updated when a page's slug changes" do
192
+ root = ::Page.create
193
+ now = @now + 98
194
+ Time.stubs(:now).returns(now)
195
+ root.update(:slug => "updated-slug")
196
+ Site.modified_at.should == now
197
+ end
198
+
200
199
  should "not be updated when a piece is added" do
201
200
  now1 = @now + 24
202
201
  Time.stubs(:now).returns(now1)
@@ -16,10 +16,7 @@ class StructureTest < MiniTest::Spec
16
16
  context "content building" do
17
17
  setup do
18
18
  Content.delete
19
- class Page < Spot::Page
20
- field :title
21
- end
22
- class Piece < Spot::Piece; end
19
+ Page.field :title
23
20
  class ProjectPage < Page; end
24
21
  class Image < Piece; end
25
22
  class Project < Piece
@@ -53,7 +50,7 @@ class StructureTest < MiniTest::Spec
53
50
  end
54
51
 
55
52
  teardown do
56
- [:Page, :HomePage, :Project, :ProjectPage, :Image].each { |klass| StructureTest.send(:remove_const, klass) rescue nil }
53
+ [:HomePage, :Project, :ProjectPage, :Image].each { |klass| StructureTest.send(:remove_const, klass) rescue nil }
57
54
  end
58
55
 
59
56
  context "site content" do