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
@@ -5,6 +5,8 @@ require File.expand_path('../../test_helper', __FILE__)
5
5
 
6
6
  class RevisionsTest < MiniTest::Spec
7
7
 
8
+ Revision = Spontaneous::Publishing::Revision
9
+
8
10
  def setup
9
11
  @now = Time.now
10
12
  @site = setup_site
@@ -20,11 +22,11 @@ class RevisionsTest < MiniTest::Spec
20
22
 
21
23
  Content.delete
22
24
 
23
- class Page < Spontaneous::Page
25
+ class Page < ::Page
24
26
  field :title, :string, :default => "New Page"
25
27
  box :things
26
28
  end
27
- class Piece < Spontaneous::Piece
29
+ class Piece < ::Piece
28
30
  box :things
29
31
  end
30
32
 
@@ -53,14 +55,13 @@ class RevisionsTest < MiniTest::Spec
53
55
  RevisionsTest.send(:remove_const, :Page) rescue nil
54
56
  RevisionsTest.send(:remove_const, :Piece) rescue nil
55
57
  Content.delete
56
- DB.logger = nil
57
58
  end
58
59
 
59
60
  context "data sources" do
60
61
 
61
62
  should "have the right names" do
62
- Content.revision_table(23).should == '__r00023_content'
63
- Content.revision_table(nil).should == 'content'
63
+ Content.revision_table(23).should == :'__r00023_content'
64
+ Content.revision_table(nil).should == :'content'
64
65
  end
65
66
 
66
67
  should "be recognisable" do
@@ -71,13 +72,11 @@ class RevisionsTest < MiniTest::Spec
71
72
  end
72
73
 
73
74
  should "be switchable within blocks" do
74
- Content.dataset.should be_content_revision
75
75
  Content.with_revision(23) do
76
76
  Content.revision.should ==23
77
- Content.dataset.should be_content_revision(23)
77
+ Content.mapper.current_revision.should == 23
78
78
  end
79
- Content.dataset.should be_content_revision
80
- Content.revision.should be_nil
79
+ Content.mapper.current_revision.should be_nil
81
80
  end
82
81
 
83
82
  should "know which revision is active" do
@@ -86,57 +85,46 @@ class RevisionsTest < MiniTest::Spec
86
85
  end
87
86
  end
88
87
 
89
- should "understand the with_editable" do
88
+ should "understand with_editable" do
90
89
  Content.with_revision(23) do
91
- Content.dataset.should be_content_revision(23)
90
+ Content.mapper.current_revision.should == 23
92
91
  Content.with_editable do
93
- Content.dataset.should be_content_revision
92
+ Content.mapper.current_revision.should be_nil
94
93
  end
95
- Content.dataset.should be_content_revision(23)
96
94
  end
97
- Content.dataset.should be_content_revision
98
95
  end
99
96
 
100
97
  should "understand with_published" do
101
- Site.stubs(:published_revision).returns(99)
98
+ S::Site.stubs(:published_revision).returns(99)
102
99
  Content.with_published do
103
- Content.dataset.should be_content_revision(99)
104
- Content.with_editable do
105
- Content.dataset.should be_content_revision
106
- end
107
- Content.dataset.should be_content_revision(99)
100
+ Content.mapper.current_revision.should == 99
108
101
  end
109
- Content.dataset.should be_content_revision
110
102
  end
111
103
 
112
104
  should "be stackable" do
113
- Content.dataset.should be_content_revision
114
105
  Content.with_revision(23) do
115
- Content.dataset.should be_content_revision(23)
106
+ Content.mapper.current_revision.should == 23
116
107
  Content.with_revision(24) do
117
- Content.dataset.should be_content_revision(24)
108
+ Content.mapper.current_revision.should == 24
118
109
  end
119
- Content.dataset.should be_content_revision(23)
120
110
  end
121
- Content.dataset.should be_content_revision
122
111
  end
123
112
 
124
113
  should "reset datasource after an exception" do
125
- Content.dataset.should be_content_revision
126
114
  begin
127
115
  Content.with_revision(23) do
128
- Content.dataset.should be_content_revision(23)
116
+ Content.mapper.current_revision.should == 23
129
117
  raise Exception.new
130
118
  end
131
119
  rescue Exception
132
120
  end
133
- Content.dataset.should be_content_revision
121
+ Content.mapper.current_revision.should be_nil
134
122
  end
135
123
 
136
124
  should "read revision from the environment if present" do
137
125
  ENV["SPOT_REVISION"] = '1001'
138
126
  Content.with_published do
139
- Content.dataset.should be_content_revision(1001)
127
+ Content.mapper.current_revision.should == 1001
140
128
  end
141
129
  ENV.delete("SPOT_REVISION")
142
130
  end
@@ -152,14 +140,11 @@ class RevisionsTest < MiniTest::Spec
152
140
 
153
141
  should "set all subclasses to use the same dataset" do
154
142
  Content.with_revision(23) do
155
- Subclass.revision.should ==23
156
- Subclass.dataset.should be_content_revision(23, Subclass.schema_id)
143
+ Subclass.revision.should == 23
144
+ Subclass.mapper.current_revision.should == 23
157
145
  # piece wasn't loaded until this point
158
- Piece.dataset.should be_content_revision(23)
159
- Piece.revision.should == 23
146
+ Piece.mapper.current_revision.should == 23
160
147
  end
161
- Subclass.dataset.should be_content_revision(nil, Subclass.schema_id)
162
- Piece.dataset.should be_content_revision(nil)
163
148
  end
164
149
  end
165
150
  end
@@ -167,76 +152,79 @@ class RevisionsTest < MiniTest::Spec
167
152
  context "content revisions" do
168
153
  setup do
169
154
  @revision = 1
155
+ Revision.history_dataset(Content).delete
156
+ Revision.archive_dataset(Content).delete
170
157
  end
158
+
171
159
  teardown do
172
- Content.delete_revision(@revision)
173
- Content.delete_revision(@revision+1) rescue nil
160
+ Revision.delete_all(Content)
174
161
  end
162
+
175
163
  should "be testable for existance" do
176
164
  Content.revision_exists?(@revision).should be_false
177
- Content.create_revision(@revision)
178
- Content.revision_exists?(@revision).should be_true
165
+ Revision.create(Content, @revision)
166
+ Revision.exists?(Content, @revision).should be_true
179
167
  end
168
+
169
+ should "not be deletable if their revision is nil" do
170
+ Revision.delete(Content, nil)
171
+ Content.db.table_exists?(:content).should be_true
172
+ end
173
+
180
174
  should "be deletable en masse" do
181
- tables = (1..10).map { |i| Content.revision_table(i).to_sym }
175
+ revisions = (1..10).to_a
176
+ tables = revisions.map { |i| Content.revision_table(i).to_sym }
177
+
178
+ revisions.each do |r|
179
+ Content.history_dataset.insert(:revision => r, :uid => "revision-#{r}")
180
+ Content.archive_dataset.insert(:revision => r, :uid => "archive-#{r}")
181
+ end
182
+
183
+ Content.history_dataset.count.should == 10
184
+ Content.archive_dataset.count.should == 10
185
+
182
186
  tables.each do |t|
183
- DB.create_table(t){Integer :id}
187
+ DB.create_table(t){Integer :id} rescue nil
184
188
  end
189
+
185
190
  tables.each do |t|
186
191
  DB.tables.include?(t).should be_true
187
192
  end
188
- Content.delete_all_revisions!
193
+
194
+ Revision.delete_all(Content)
195
+
189
196
  tables.each do |t|
190
197
  DB.tables.include?(t).should be_false
191
198
  end
199
+
200
+ Content.history_dataset.count.should == 0
201
+ Content.archive_dataset.count.should == 0
192
202
  end
193
203
 
194
204
  should "be creatable from current content" do
195
205
  DB.tables.include?(Content.revision_table(@revision).to_sym).should be_false
196
- Content.create_revision(@revision)
206
+ Revision.create(Content, @revision)
197
207
  DB.tables.include?(Content.revision_table(@revision).to_sym).should be_true
198
208
  count = Content.count
199
209
  Content.with_revision(@revision) do
200
210
  Content.count.should == count
201
211
  Content.all.each do |published|
212
+ published.revision.should == @revision
202
213
  Content.with_editable do
203
214
  e = Content[published.id]
204
- e.should == published
205
- end
206
- end
207
- end
208
- end
209
-
210
- should "be creatable from any revision" do
211
- revision = 2
212
- source_revision = @revision
213
- source_revision_count = nil
214
-
215
- Content.create_revision(source_revision)
216
-
217
- Content.with_revision(source_revision) do
218
- Content.first(:uid => "0").destroy
219
- source_revision_count = Content.count
220
- end
221
-
222
- Content.count.should == source_revision_count + 7
223
-
224
- Content.create_revision(revision, source_revision)
225
-
226
- Content.with_revision(revision) do
227
- Content.count.should == source_revision_count
228
- Content.all.each do |published|
229
-
230
- Content.with_revision(source_revision) do
231
- e = Content.first :id => published.id
232
- e.should == published
215
+ assert_content_equal(e, published, :revision)
216
+ e.revision.should be_nil
233
217
  end
234
218
  end
235
219
  end
220
+ Content.history_dataset(@revision).count.should == count
221
+ Content.history_dataset.select(:revision).group(:revision).all.should == [{:revision => 1}]
222
+ Content.archive_dataset(@revision).count.should == count
223
+ Content.archive_dataset.select(:revision).group(:revision).all.should == [{:revision => 1}]
236
224
  end
237
225
 
238
226
  should "have the correct indexes" do
239
- Content.create_revision(@revision)
227
+ Revision.create(Content, @revision)
240
228
  content_indexes = DB.indexes(:content)
241
229
  published_indexes = DB.indexes(Content.revision_table(@revision))
242
230
  # made slightly complex by the fact that the index names depend on the table names
@@ -244,24 +232,34 @@ class RevisionsTest < MiniTest::Spec
244
232
  assert_same_elements published_indexes.values, content_indexes.values
245
233
  end
246
234
 
235
+ should "only be kept until a new revision is available" do
236
+ (0..2).each do |r|
237
+ Revision.create(Content, @revision+r)
238
+ Content.history_dataset(@revision+r).count.should == 15
239
+ Content.archive_dataset(@revision+r).count.should == 15
240
+ end
241
+ Content.revision_tables.should == [:__r00001_content, :__r00002_content, :__r00003_content]
242
+ Revision.cleanup(Content, @revision+2, 2)
243
+ Content.revision_tables.should == [:__r00003_content]
244
+ Content.history_dataset(@revision).count.should == 0
245
+ Content.archive_dataset(@revision).count.should == 15
246
+ Content.history_dataset(@revision+2).count.should == 15
247
+ end
248
+
247
249
 
248
250
  context "incremental publishing" do
249
251
  setup do
250
252
  @initial_revision = 1
251
253
  @final_revision = 2
252
- Content.create_revision(@initial_revision)
253
- Content.delete_revision(@final_revision) rescue nil
254
- Content.delete_revision(@final_revision+1) rescue nil
254
+ Revision.create(Content, @initial_revision)
255
+ Revision.delete(Content, @final_revision) rescue nil
256
+ Revision.delete(Content, @final_revision+1) rescue nil
255
257
  end
256
258
 
257
259
  teardown do
258
- begin
259
- Content.delete_revision(@initial_revision)
260
- Content.delete_revision(@final_revision)
261
- Content.delete_revision(@final_revision+1)
262
- rescue
263
- end
264
- DB.logger = nil
260
+ Revision.create(Content, @initial_revision) rescue nil
261
+ Revision.delete(Content, @final_revision) rescue nil
262
+ Revision.delete(Content, @final_revision+1) rescue nil
265
263
  end
266
264
 
267
265
  should "duplicate changes to only a single item" do
@@ -273,14 +271,13 @@ class RevisionsTest < MiniTest::Spec
273
271
  editable2.label = "unpublished"
274
272
  editable2.save
275
273
  editable2.reload
276
- Content.publish(@final_revision, [editable1.id])
274
+ Revision.patch(Content, @final_revision, [editable1.id])
277
275
  editable1.reload
278
276
  Content.with_revision(@final_revision) do
279
277
  published = Content.first :id => editable1.id
280
278
  unpublished = Content.first :id => editable2.id
281
- assert_content_equal(published, editable1)
282
-
283
- unpublished.should_not == editable2
279
+ assert_content_equal(published, editable1, :revision)
280
+ assert_content_unequal(unpublished, editable2, :revision)
284
281
  end
285
282
  end
286
283
 
@@ -290,14 +287,14 @@ class RevisionsTest < MiniTest::Spec
290
287
 
291
288
  editable1.things << new_content
292
289
  editable1.save
293
- Content.publish(@final_revision, [editable1.id])
290
+ Revision.patch(Content, @final_revision, [editable1.id])
294
291
  new_content.reload
295
292
  editable1.reload
296
293
  Content.with_revision(@final_revision) do
297
294
  published1 = Content[editable1.id]
298
295
  published2 = Content[new_content.id]
299
- assert_content_equal(published2, new_content)
300
- assert_content_equal(published1, editable1)
296
+ assert_content_equal(published2, new_content, :revision)
297
+ assert_content_equal(published1, editable1, :revision)
301
298
  end
302
299
  end
303
300
 
@@ -305,11 +302,11 @@ class RevisionsTest < MiniTest::Spec
305
302
  editable1 = Content.first(:uid => '0')
306
303
  deleted = editable1.contents.first
307
304
  editable1.contents.first.destroy
308
- Content.publish(@final_revision, [editable1.id])
305
+ Revision.patch(Content, @final_revision, [editable1.id])
309
306
  editable1.reload
310
307
  Content.with_revision(@final_revision) do
311
308
  published1 = Content[editable1.id]
312
- assert_content_equal(published1, editable1)
309
+ assert_content_equal(published1, editable1, :revision)
313
310
  Content[deleted.id].should be_nil
314
311
  end
315
312
  end
@@ -320,14 +317,14 @@ class RevisionsTest < MiniTest::Spec
320
317
  editable1.things << new_page
321
318
  editable1.save
322
319
  new_page.save
323
- Content.publish(@final_revision, [editable1.id])
320
+ Revision.patch(Content, @final_revision, [editable1.id])
324
321
  new_page.reload
325
322
  editable1.reload
326
323
  Content.with_revision(@final_revision) do
327
324
  published1 = Content[editable1.id]
328
325
  published2 = Content[new_page.id]
329
326
  published2.should be_nil
330
- assert_content_equal(published1, editable1)
327
+ assert_content_equal(published1, editable1, :revision)
331
328
  end
332
329
  end
333
330
 
@@ -339,7 +336,7 @@ class RevisionsTest < MiniTest::Spec
339
336
  new_content = Piece.new(:uid => "new")
340
337
  editable2.things << new_content
341
338
  editable2.save
342
- Content.publish(@final_revision, [editable1.id])
339
+ Revision.patch(Content, @final_revision, [editable1.id])
343
340
  editable1.reload
344
341
  editable2.reload
345
342
  new_content.reload
@@ -347,43 +344,43 @@ class RevisionsTest < MiniTest::Spec
347
344
  published1 = Content.first :id => editable1.id
348
345
  Content.first(:uid => "added").should_not be_nil
349
346
  published3 = Content.first :id => editable2.id
350
- assert_content_equal(published1, editable1)
351
- published3.should_not == editable2
347
+ assert_content_equal(published1, editable1, :revision)
348
+ assert_content_unequal(published3, editable2, :revision)
352
349
  published3.uid.should_not == "new"
353
350
  end
354
- Content.publish(@final_revision+1, [editable2.id])
351
+ Revision.patch(Content, @final_revision+1, [editable2.id])
355
352
  editable1.reload
356
353
  editable2.reload
357
354
  new_content.reload
358
355
  Content.with_revision(@final_revision+1) do
359
356
  published1 = Content.first :id => editable1.id
360
- assert_content_equal(published1, editable1)
357
+ assert_content_equal(published1, editable1, :revision)
361
358
  published2 = Content.first :id => editable2.id
362
- assert_content_equal(published2, editable2)
359
+ assert_content_equal(published2, editable2, :revision)
363
360
  published3 = Content.first :id => editable2.contents.first.id
364
361
  # published3.should == editable2.contents.first
365
- assert_content_equal(published3, editable2.contents.first)
362
+ assert_content_equal(published3, editable2.contents.first, :revision)
366
363
  end
367
364
  end
368
365
 
369
- should "insert an entry value into the parent of a newly added page when that page is published" do
366
+ should "insert an entry value into the parent of a newly added page when that page is published aaa" do
370
367
  editable1 = Content.first(:uid => '0')
371
368
  new_page = Page.new(:uid => "new")
372
369
  editable1.things << new_page
373
370
  editable1.save
374
371
  new_page.save
375
- Content.publish(@final_revision, [new_page.id])
372
+ Revision.patch(Content, @final_revision, [new_page.id])
376
373
  new_page.reload
377
374
  editable1.reload
378
375
  Content.with_revision(@final_revision) do
379
376
  published1 = Content[editable1.id]
380
377
  published2 = Content[new_page.id]
381
- assert_content_equal(published2, new_page)
378
+ assert_content_equal(published2, new_page, :revision)
382
379
  editable1.entry_store.should == published1.entry_store
383
380
  end
384
381
  end
385
382
 
386
- should "choose a sensible position for entry into the parent of a newly added page xxx" do
383
+ should "choose a sensible position for entry into the parent of a newly added page" do
387
384
  editable1 = Content.first(:uid => '0')
388
385
  new_page1 = Page.new(:uid => "new1")
389
386
  new_page2 = Page.new(:uid => "new2")
@@ -392,7 +389,7 @@ class RevisionsTest < MiniTest::Spec
392
389
  editable1.save
393
390
  new_page1.save
394
391
  new_page2.save
395
- Content.publish(@final_revision, [new_page2.id])
392
+ Revision.patch(Content, @final_revision, [new_page2.id])
396
393
  new_page1.reload
397
394
  new_page2.reload
398
395
  editable1.reload
@@ -401,7 +398,7 @@ class RevisionsTest < MiniTest::Spec
401
398
  published2 = Content[new_page1.id]
402
399
  published3 = Content[new_page2.id]
403
400
  published2.should be_nil
404
- assert_content_equal(published3, new_page2)
401
+ assert_content_equal(published3, new_page2, :revision)
405
402
  editable1.entry_store.reject { |e| e[0] == new_page1.id }.should == published1.entry_store
406
403
  end
407
404
  end
@@ -415,7 +412,7 @@ class RevisionsTest < MiniTest::Spec
415
412
  editable1.save
416
413
  new_page1.save
417
414
  new_page2.save
418
- Content.publish(@final_revision, [editable1.id, new_page2.id])
415
+ Revision.patch(Content, @final_revision, [editable1.id, new_page2.id])
419
416
  new_page1.reload
420
417
  new_page2.reload
421
418
  editable1.reload
@@ -424,8 +421,8 @@ class RevisionsTest < MiniTest::Spec
424
421
  published2 = Content[new_page1.id]
425
422
  published3 = Content[new_page2.id]
426
423
  published2.should be_nil
427
- assert_content_equal(published3, new_page2)
428
- assert_content_equal(published1, editable1)
424
+ assert_content_equal(published3, new_page2, :revision)
425
+ assert_content_equal(published1, editable1, :revision)
429
426
  end
430
427
  end
431
428
 
@@ -434,7 +431,7 @@ class RevisionsTest < MiniTest::Spec
434
431
  piece = page.things.first
435
432
  child = piece.things.first
436
433
  page.things.first.destroy
437
- Content.publish(@final_revision, [page.id])
434
+ Revision.patch(Content, @final_revision, [page.id])
438
435
 
439
436
  Content.with_revision(@final_revision) do
440
437
  published_parent = Content[page.id]
@@ -452,18 +449,18 @@ class RevisionsTest < MiniTest::Spec
452
449
  context "publication timestamps" do
453
450
  setup do
454
451
  @revision = 1
455
- Content.delete_revision(@revision+1)
452
+ Revision.delete(Content, @revision+1)
456
453
  end
457
454
  teardown do
458
- Content.delete_revision(@revision)
459
- Content.delete_revision(@revision+1)
455
+ Revision.delete(Content, @revision)
456
+ Revision.delete(Content, @revision+1)
460
457
  end
461
458
 
462
459
  should "set correct timestamps on first publish" do
463
460
  first = Content.first
464
461
  first.reload.first_published_at.should be_nil
465
462
  first.reload.last_published_at.should be_nil
466
- Content.publish(@revision)
463
+ Revision.create(Content, @revision)
467
464
  first.reload.first_published_at.to_i.should == @now.to_i
468
465
  first.reload.last_published_at.to_i.should == @now.to_i
469
466
  first.reload.first_published_revision.should == @revision
@@ -482,12 +479,12 @@ class RevisionsTest < MiniTest::Spec
482
479
  should "set correct timestamps on later publishes" do
483
480
  first = Content.first
484
481
  first.first_published_at.should be_nil
485
- Content.publish(@revision)
482
+ Revision.create(Content, @revision)
486
483
  first.reload.first_published_at.to_i.should == @now.to_i
487
484
  c = Content.create
488
485
  c.first_published_at.should be_nil
489
486
  stub_time(@now + 100)
490
- Content.publish(@revision+1)
487
+ Revision.create(Content, @revision+1)
491
488
  first.reload.first_published_at.to_i.should == @now.to_i
492
489
  first.reload.last_published_at.to_i.should == @now.to_i + 100
493
490
  Content.with_editable do
@@ -501,22 +498,22 @@ class RevisionsTest < MiniTest::Spec
501
498
  end
502
499
 
503
500
  should "not set publishing date for items not published" do
504
- Content.publish(@revision)
501
+ Revision.create(Content, @revision)
505
502
  page = Content.first
506
503
  page.uid = "fish"
507
504
  page.save
508
505
  added = Content.create
509
506
  added.first_published_at.should be_nil
510
- Content.publish(@revision+1, [page])
507
+ Revision.patch(Content, @revision+1, [page])
511
508
  page.first_published_at.to_i.should == @now.to_i
512
509
  added.first_published_at.should be_nil
513
510
  added.last_published_at.should be_nil
514
511
  end
515
512
 
516
- should "not set publishing dates if exception raised in passed block" do
513
+ should "not set publishing dates if exception raised in passed block xxx" do
517
514
  Content.first.first_published_at.should be_nil
518
515
  begin
519
- Content.publish(@revision) do
516
+ Revision.create(Content, @revision) do
520
517
  raise Exception
521
518
  end
522
519
  rescue Exception; end
@@ -524,21 +521,21 @@ class RevisionsTest < MiniTest::Spec
524
521
  end
525
522
 
526
523
  should "delete revision tables if exception raised in passed block" do
527
- Content.revision_exists?(@revision).should be_false
524
+ Revision.exists?(Content, @revision).should be_false
528
525
  begin
529
- Content.publish(@revision) do
530
- Content.revision_exists?(@revision).should be_true
526
+ Revision.create(Content, @revision) do
527
+ Revision.exists?(Content, @revision).should be_true
531
528
  Content.revision.should == @revision
532
529
  raise Exception
533
530
  end
534
531
  rescue Exception; end
535
- Content.revision_exists?(@revision).should be_false
532
+ Revision.exists?(Content, @revision).should be_false
536
533
  end
537
534
 
538
535
  should "always publish all if no previous revisions exist" do
539
536
  page = Content.first
540
537
  Content.filter(:first_published_at => nil).count.should == Content.count
541
- Content.publish(@revision, [page])
538
+ Revision.patch(Content, @revision, [page])
542
539
  Content.filter(:first_published_at => nil).count.should == 0
543
540
  end
544
541
  end