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.
- data/Gemfile +10 -4
- data/Readme.markdown +1 -1
- data/application/css/definitions.css.scss +5 -0
- data/application/css/dialogue.css.scss +62 -0
- data/application/js/content.js +1 -1
- data/application/js/dom.js +1 -1
- data/application/js/event_source.js +3 -0
- data/application/js/{field_types/date_field.js → field/date.js} +2 -2
- data/application/js/{field_types/file_field.js → field/file.js} +2 -2
- data/application/js/{field_types/image_field.js → field/image.js} +54 -20
- data/application/js/{field_types/long_string_field.js → field/long_string.js} +2 -2
- data/application/js/{field_types/markdown_field.js → field/markdown.js} +2 -2
- data/application/js/{field_types/select_field.js → field/select.js} +2 -2
- data/application/js/{field_types/string_field.js → field/string.js} +21 -7
- data/application/js/{field_types/webvideo_field.js → field/webvideo.js} +2 -2
- data/application/js/field.js +2 -2
- data/application/js/publish.js +99 -19
- data/application/js/spontaneous.js +8 -8
- data/application/js/top_bar.js +6 -4
- data/db/migrations/20130109125023_add_page_publish_lock.rb +17 -0
- data/db/migrations/20130111161934_convert_bcrypt_passwords.rb +22 -0
- data/db/migrations/20130114120000_create_revision_tables.rb +106 -0
- data/db/migrations/20130116220423_add_index_to_archive.rb +9 -0
- data/lib/spontaneous/box.rb +53 -18
- data/lib/spontaneous/box_style.rb +2 -3
- data/lib/spontaneous/change.rb +39 -13
- data/lib/spontaneous/cli/fields.rb +29 -0
- data/lib/spontaneous/cli/init.rb +2 -2
- data/lib/spontaneous/cli/migrate.rb +0 -1
- data/lib/spontaneous/cli/server.rb +14 -10
- data/lib/spontaneous/cli/site.rb +20 -9
- data/lib/spontaneous/cli.rb +8 -6
- data/lib/spontaneous/collections/box_set.rb +11 -0
- data/lib/spontaneous/collections/field_set.rb +24 -1
- data/lib/spontaneous/concern.rb +37 -0
- data/lib/spontaneous/config.rb +3 -4
- data/lib/spontaneous/crypt/version.rb +130 -0
- data/lib/spontaneous/crypt.rb +84 -0
- data/lib/spontaneous/data_mapper/content_model/associations.rb +199 -0
- data/lib/spontaneous/data_mapper/content_model/column_accessors.rb +52 -0
- data/lib/spontaneous/data_mapper/content_model/instance_hooks.rb +34 -0
- data/lib/spontaneous/data_mapper/content_model/serialization.rb +54 -0
- data/lib/spontaneous/data_mapper/content_model/timestamps.rb +39 -0
- data/lib/spontaneous/data_mapper/content_model.rb +343 -0
- data/lib/spontaneous/data_mapper/content_table.rb +103 -0
- data/lib/spontaneous/data_mapper/dataset.rb +194 -0
- data/lib/spontaneous/data_mapper/scope.rb +195 -0
- data/lib/spontaneous/data_mapper.rb +161 -0
- data/lib/spontaneous/facet.rb +2 -2
- data/lib/spontaneous/field/base.rb +418 -0
- data/lib/spontaneous/field/date.rb +54 -0
- data/lib/spontaneous/{field_version.rb → field/field_version.rb} +1 -1
- data/lib/spontaneous/field/file.rb +100 -0
- data/lib/spontaneous/{field_types/image_field.rb → field/image.rb} +33 -33
- data/lib/spontaneous/{field_types/location_field.rb → field/location.rb} +2 -2
- data/lib/spontaneous/{field_types/long_string_field.rb → field/long_string.rb} +3 -3
- data/lib/spontaneous/field/markdown.rb +36 -0
- data/lib/spontaneous/{field_types/select_field.rb → field/select.rb} +4 -5
- data/lib/spontaneous/field/string.rb +17 -0
- data/lib/spontaneous/field/update.rb +156 -0
- data/lib/spontaneous/field/webvideo.rb +310 -0
- data/lib/spontaneous/field.rb +80 -0
- data/lib/spontaneous/generators/site/Gemfile.tt +2 -2
- data/lib/spontaneous/generators/site/config/environments/development.rb.tt +1 -1
- data/lib/spontaneous/generators/site/config/environments/production.rb.tt +1 -1
- data/lib/spontaneous/generators/site/lib/content.rb.tt +6 -0
- data/lib/spontaneous/generators/site/schema/box.rb.tt +3 -2
- data/lib/spontaneous/generators/site/schema/page.rb.tt +3 -1
- data/lib/spontaneous/generators/site/schema/piece.rb.tt +3 -1
- data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +3 -1
- data/lib/spontaneous/generators/site.rb +4 -3
- data/lib/spontaneous/image_size.rb +8 -1
- data/lib/spontaneous/layout.rb +5 -1
- data/lib/spontaneous/loader.rb +2 -5
- data/lib/spontaneous/media/file.rb +11 -2
- data/lib/spontaneous/media/temp_file.rb +23 -0
- data/lib/spontaneous/media.rb +20 -39
- data/lib/spontaneous/{plugins → model/box}/allowed_types.rb +38 -17
- data/lib/spontaneous/model/box.rb +18 -0
- data/lib/spontaneous/{plugins → model/core}/aliases.rb +10 -14
- data/lib/spontaneous/{plugins → model/core}/boxes.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/content_groups.rb +2 -2
- data/lib/spontaneous/model/core/editor_class.rb +4 -0
- data/lib/spontaneous/{plugins → model/core}/entries.rb +19 -7
- data/lib/spontaneous/{plugins → model/core}/entry.rb +3 -3
- data/lib/spontaneous/{plugins → model/core}/fields.rb +38 -5
- data/lib/spontaneous/{plugins → model/core}/instance_code.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/media.rb +2 -12
- data/lib/spontaneous/{plugins → model/core}/modifications.rb +7 -6
- data/lib/spontaneous/model/core/page_search.rb +36 -0
- data/lib/spontaneous/{plugins → model/core}/permissions.rb +4 -4
- data/lib/spontaneous/{plugins → model/core}/prototypes.rb +4 -4
- data/lib/spontaneous/{plugins → model/core}/publishing.rb +93 -115
- data/lib/spontaneous/{plugins → model/core}/render.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/schema_hierarchy.rb +7 -11
- data/lib/spontaneous/model/core/schema_id.rb +65 -0
- data/lib/spontaneous/{plugins → model/core}/schema_title.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/serialisation.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/styles.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/supertype.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/visibility.rb +7 -48
- data/lib/spontaneous/model/core.rb +143 -0
- data/lib/spontaneous/{plugins → model/page}/controllers.rb +3 -3
- data/lib/spontaneous/{plugins → model}/page/formats.rb +2 -2
- data/lib/spontaneous/{plugins → model/page}/layouts.rb +2 -2
- data/lib/spontaneous/model/page/locks.rb +14 -0
- data/lib/spontaneous/{plugins → model/page}/page_tree.rb +3 -3
- data/lib/spontaneous/{plugins → model/page}/paths.rb +30 -12
- data/lib/spontaneous/{plugins → model}/page/request.rb +2 -2
- data/lib/spontaneous/{plugins → model/page}/site_map.rb +2 -2
- data/lib/spontaneous/model/page/site_timestamps.rb +44 -0
- data/lib/spontaneous/{page.rb → model/page.rb} +49 -28
- data/lib/spontaneous/{piece.rb → model/piece.rb} +7 -6
- data/lib/spontaneous/model.rb +97 -0
- data/lib/spontaneous/output/context.rb +1 -1
- data/lib/spontaneous/output/format.rb +4 -0
- data/lib/spontaneous/output/template/renderer.rb +2 -2
- data/lib/spontaneous/output.rb +2 -2
- data/lib/spontaneous/page_lock.rb +62 -0
- data/lib/spontaneous/page_piece.rb +1 -1
- data/lib/spontaneous/permissions/access_key.rb +9 -4
- data/lib/spontaneous/permissions/user.rb +19 -9
- data/lib/spontaneous/permissions.rb +2 -5
- data/lib/spontaneous/plugins/application/facets.rb +1 -2
- data/lib/spontaneous/plugins/application/features.rb +1 -1
- data/lib/spontaneous/plugins/application/paths.rb +1 -1
- data/lib/spontaneous/plugins/application/render.rb +1 -1
- data/lib/spontaneous/plugins/application/serialisation.rb +1 -1
- data/lib/spontaneous/plugins/application/state.rb +30 -1
- data/lib/spontaneous/plugins/application/system.rb +12 -12
- data/lib/spontaneous/prototypes/box_prototype.rb +1 -1
- data/lib/spontaneous/prototypes/field_prototype.rb +3 -6
- data/lib/spontaneous/prototypes/style_prototype.rb +1 -1
- data/lib/spontaneous/publishing/immediate.rb +77 -49
- data/lib/spontaneous/publishing/revision.rb +355 -0
- data/lib/spontaneous/publishing/simultaneous.rb +10 -49
- data/lib/spontaneous/publishing.rb +1 -0
- data/lib/spontaneous/rack/around_back.rb +1 -1
- data/lib/spontaneous/rack/around_front.rb +2 -4
- data/lib/spontaneous/rack/around_preview.rb +1 -1
- data/lib/spontaneous/rack/back.rb +80 -63
- data/lib/spontaneous/rack/cacheable_file.rb +2 -2
- data/lib/spontaneous/rack/cookie_authentication.rb +1 -1
- data/lib/spontaneous/rack/front.rb +1 -1
- data/lib/spontaneous/rack/helpers.rb +8 -9
- data/lib/spontaneous/{page_controller.rb → rack/page_controller.rb} +1 -1
- data/lib/spontaneous/rack/public.rb +3 -3
- data/lib/spontaneous/rack.rb +15 -15
- data/lib/spontaneous/schema/uid.rb +4 -1
- data/lib/spontaneous/schema.rb +57 -24
- data/lib/spontaneous/search/database.rb +12 -1
- data/lib/spontaneous/search/index.rb +34 -6
- data/lib/spontaneous/search/results.rb +1 -1
- data/lib/spontaneous/server.rb +3 -3
- data/lib/spontaneous/simultaneous.rb +53 -0
- data/lib/spontaneous/{plugins/site → site}/features.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/helpers.rb +2 -3
- data/lib/spontaneous/{plugins/site → site}/hooks.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/instance.rb +4 -6
- data/lib/spontaneous/{plugins/site → site}/level.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/map.rb +4 -4
- data/lib/spontaneous/{plugins/site → site}/paths.rb +2 -2
- data/lib/spontaneous/site/publishing.rb +89 -0
- data/lib/spontaneous/{plugins/site → site}/schema.rb +4 -4
- data/lib/spontaneous/{plugins/site → site}/search.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/selectors.rb +15 -7
- data/lib/spontaneous/{plugins/site → site}/state.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/storage.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/url.rb +2 -2
- data/lib/spontaneous/site.rb +31 -14
- data/lib/spontaneous/state.rb +5 -6
- data/lib/spontaneous/style.rb +3 -2
- data/lib/spontaneous/utils/database/mysql_dumper.rb +13 -0
- data/lib/spontaneous/utils/database/postgres_dumper.rb +5 -0
- data/lib/spontaneous/version.rb +1 -1
- data/lib/spontaneous.rb +34 -89
- data/spontaneous.gemspec +112 -114
- data/test/experimental/test_crypt.rb +158 -0
- data/test/experimental/test_features.rb +3 -3
- data/test/fixtures/example_application/config/environments/development.rb +1 -1
- data/test/fixtures/example_application/lib/content.rb +5 -0
- data/test/fixtures/example_application/schema/page.rb +2 -1
- data/test/fixtures/example_application/schema/piece.rb +3 -2
- data/test/fixtures/serialisation/class_hash.yaml.erb +5 -5
- data/test/fixtures/serialisation/root_hash.yaml.erb +8 -0
- data/test/functional/test_application.rb +12 -1
- data/test/functional/test_back.rb +80 -48
- data/test/functional/test_front.rb +39 -46
- data/test/functional/test_user_manager.rb +3 -9
- data/test/javascript/test_markdown.rb +2 -2
- data/test/test_helper.rb +78 -23
- data/test/unit/test_alias.rb +21 -15
- data/test/unit/test_asset_bundler.rb +3 -3
- data/test/unit/test_assets.rb +2 -2
- data/test/unit/test_async.rb +7 -6
- data/test/unit/test_authentication.rb +43 -37
- data/test/unit/test_boxes.rb +46 -21
- data/test/unit/test_changesets.rb +65 -20
- data/test/unit/test_config.rb +9 -9
- data/test/unit/test_content.rb +50 -51
- data/test/unit/test_content_inheritance.rb +6 -20
- data/test/unit/test_datamapper.rb +1330 -0
- data/test/unit/test_datamapper_content.rb +214 -0
- data/test/unit/test_fields.rb +543 -54
- data/test/unit/test_formats.rb +2 -3
- data/test/unit/test_generators.rb +6 -6
- data/test/unit/test_helpers.rb +1 -1
- data/test/unit/test_image_size.rb +10 -5
- data/test/unit/test_images.rb +17 -18
- data/test/unit/test_layouts.rb +18 -3
- data/test/unit/test_media.rb +74 -49
- data/test/unit/test_modifications.rb +43 -43
- data/test/unit/test_page.rb +7 -10
- data/test/unit/test_permissions.rb +3 -10
- data/test/unit/test_piece.rb +5 -6
- data/test/unit/test_plugins.rb +7 -14
- data/test/unit/test_prototypes.rb +3 -3
- data/test/unit/test_publishing.rb +49 -27
- data/test/unit/test_render.rb +46 -15
- data/test/unit/test_revisions.rb +124 -127
- data/test/unit/test_schema.rb +53 -58
- data/test/unit/test_search.rb +64 -16
- data/test/unit/test_serialisation.rb +4 -11
- data/test/unit/test_site.rb +11 -12
- data/test/unit/test_structure.rb +2 -5
- data/test/unit/test_styles.rb +22 -24
- data/test/unit/test_type_hierarchy.rb +7 -5
- data/test/unit/test_visibility.rb +79 -55
- metadata +128 -102
- data/lib/sequel/plugins/content_table_inheritance.rb +0 -203
- data/lib/sequel/plugins/scoped_table_name.rb +0 -54
- data/lib/spontaneous/content.rb +0 -129
- data/lib/spontaneous/field_types/date_field.rb +0 -56
- data/lib/spontaneous/field_types/field.rb +0 -302
- data/lib/spontaneous/field_types/file_field.rb +0 -68
- data/lib/spontaneous/field_types/markdown_field.rb +0 -38
- data/lib/spontaneous/field_types/string_field.rb +0 -19
- data/lib/spontaneous/field_types/webvideo_field.rb +0 -313
- data/lib/spontaneous/field_types.rb +0 -38
- data/lib/spontaneous/generators/site/lib/site.rb.tt +0 -4
- data/lib/spontaneous/plugins/field/editor_class.rb +0 -13
- data/lib/spontaneous/plugins/page/site_timestamps.rb +0 -28
- data/lib/spontaneous/plugins/page_search.rb +0 -63
- data/lib/spontaneous/plugins/schema_id.rb +0 -68
- data/lib/spontaneous/plugins/site/publishing.rb +0 -75
- data/lib/spontaneous/rack/fiber_pool.rb +0 -26
- data/test/unit/test_table_scoping.rb +0 -80
data/test/unit/test_revisions.rb
CHANGED
@@ -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 <
|
25
|
+
class Page < ::Page
|
24
26
|
field :title, :string, :default => "New Page"
|
25
27
|
box :things
|
26
28
|
end
|
27
|
-
class 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.
|
77
|
+
Content.mapper.current_revision.should == 23
|
78
78
|
end
|
79
|
-
Content.
|
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
|
88
|
+
should "understand with_editable" do
|
90
89
|
Content.with_revision(23) do
|
91
|
-
Content.
|
90
|
+
Content.mapper.current_revision.should == 23
|
92
91
|
Content.with_editable do
|
93
|
-
Content.
|
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.
|
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.
|
106
|
+
Content.mapper.current_revision.should == 23
|
116
107
|
Content.with_revision(24) do
|
117
|
-
Content.
|
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.
|
116
|
+
Content.mapper.current_revision.should == 23
|
129
117
|
raise Exception.new
|
130
118
|
end
|
131
119
|
rescue Exception
|
132
120
|
end
|
133
|
-
Content.
|
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.
|
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.
|
143
|
+
Subclass.revision.should == 23
|
144
|
+
Subclass.mapper.current_revision.should == 23
|
157
145
|
# piece wasn't loaded until this point
|
158
|
-
Piece.
|
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
|
-
|
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
|
-
|
178
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
205
|
-
|
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
|
-
|
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
|
-
|
253
|
-
|
254
|
-
|
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
|
-
|
259
|
-
|
260
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
452
|
+
Revision.delete(Content, @revision+1)
|
456
453
|
end
|
457
454
|
teardown do
|
458
|
-
|
459
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
524
|
+
Revision.exists?(Content, @revision).should be_false
|
528
525
|
begin
|
529
|
-
|
530
|
-
|
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
|
-
|
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
|
-
|
538
|
+
Revision.patch(Content, @revision, [page])
|
542
539
|
Content.filter(:first_published_at => nil).count.should == 0
|
543
540
|
end
|
544
541
|
end
|