spontaneous 0.2.0.beta5 → 0.2.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +39 -0
- data/Gemfile +2 -0
- data/Readme.markdown +4 -4
- data/application/css/core.css.scss +144 -43
- data/application/css/definitions.css.scss +50 -16
- data/application/css/dialogue.css.scss +5 -2
- data/application/css/editing.css.scss +7 -7
- data/application/css/font.css.scss +1 -1
- data/application/css/meta.css.scss +6 -6
- data/application/css/popover.css.scss +6 -6
- data/application/css/top.css.scss +8 -1
- data/application/js/add_alias_dialogue.js +137 -36
- data/application/js/add_home_dialogue.js +10 -10
- data/application/js/ajax.js +26 -26
- data/application/js/authentication.js +2 -2
- data/application/js/box.js +21 -10
- data/application/js/box_container.js +13 -7
- data/application/js/compatibility.js +19 -17
- data/application/js/conflicted_field_dialogue.js +5 -5
- data/application/js/content.js +22 -16
- data/application/js/content_area.js +62 -33
- data/application/js/dialogue.js +16 -16
- data/application/js/dom.js +9 -10
- data/application/js/edit_panel.js +25 -20
- data/application/js/editing.js +21 -8
- data/application/js/entry.js +1 -1
- data/application/js/extensions.js +11 -11
- data/application/js/field/boolean.js +6 -6
- data/application/js/field/date.js +1 -1
- data/application/js/field/file.js +17 -17
- data/application/js/field/image.js +27 -27
- data/application/js/field/markdown.js +72 -71
- data/application/js/field/select.js +9 -9
- data/application/js/field/string.js +3 -3
- data/application/js/field/webvideo.js +2 -2
- data/application/js/field_preview.js +3 -0
- data/application/js/init.js +3 -2
- data/application/js/jquery-selection-position.js +13 -13
- data/application/js/location.js +17 -12
- data/application/js/login.js +2 -2
- data/application/js/meta_view/user_admin.js +101 -101
- data/application/js/metadata.js +1 -1
- data/application/js/page.js +2 -2
- data/application/js/page_browser.js +13 -13
- data/application/js/page_entry.js +1 -1
- data/application/js/panel/root_menu.js +10 -10
- data/application/js/popover.js +6 -5
- data/application/js/popover_view.js +5 -5
- data/application/js/preview.js +10 -4
- data/application/js/progress.js +6 -6
- data/application/js/properties.js +35 -6
- data/application/js/publish.js +43 -43
- data/application/js/require.js +14 -14
- data/application/js/services.js +3 -3
- data/application/js/sharded_upload.js +9 -8
- data/application/js/side_bar.js +5 -5
- data/application/js/state.js +2 -2
- data/application/js/status_bar.js +6 -6
- data/application/js/top_bar.js +97 -65
- data/application/js/types.js +9 -6
- data/application/js/upload.js +4 -4
- data/application/js/upload_manager.js +21 -21
- data/application/js/user.js +1 -1
- data/application/js/vendor/jquery.velocity.min.js +7 -0
- data/application/js/views.js +32 -8
- data/application/js/views/box_view.js +51 -31
- data/application/js/views/page_piece_view.js +17 -15
- data/application/js/views/page_view.js +54 -43
- data/application/js/views/piece_view.js +44 -37
- data/application/static/font/fontawesome-webfont-4f0022f25672c7f501c339cbf98d9117.ttf +0 -0
- data/application/views/index.erb +1 -0
- data/db/migrations/20130114120000_create_revision_tables.rb +2 -1
- data/db/migrations/20130813111009_increase_path_length.rb +11 -2
- data/db/migrations/20140506171823_add_index_to_target_id.rb +11 -0
- data/db/migrations/20140514090204_add_content_hash.rb +59 -0
- data/db/migrations/20140519150253_add_content_hash_timestamp.rb +20 -0
- data/lib/spontaneous.rb +0 -1
- data/lib/spontaneous/asset/environment.rb +77 -15
- data/lib/spontaneous/box.rb +21 -0
- data/lib/spontaneous/capistrano/deploy.rb +1 -1
- data/lib/spontaneous/capistrano/sync.rb +8 -7
- data/lib/spontaneous/change.rb +4 -2
- data/lib/spontaneous/cli/fields.rb +7 -3
- data/lib/spontaneous/cli/generate.rb +2 -0
- data/lib/spontaneous/cli/init.rb +24 -93
- data/lib/spontaneous/cli/init/db.rb +94 -0
- data/lib/spontaneous/cli/init/mysql.rb +17 -0
- data/lib/spontaneous/cli/init/postgresql.rb +33 -0
- data/lib/spontaneous/cli/init/sqlite.rb +14 -0
- data/lib/spontaneous/cli/site.rb +45 -20
- data/lib/spontaneous/collections/box_set.rb +3 -0
- data/lib/spontaneous/collections/entry_set.rb +43 -4
- data/lib/spontaneous/collections/field_set.rb +14 -2
- data/lib/spontaneous/data_mapper.rb +40 -7
- data/lib/spontaneous/data_mapper/content_model.rb +1 -1
- data/lib/spontaneous/data_mapper/content_model/associations.rb +63 -12
- data/lib/spontaneous/data_mapper/content_model/timestamps.rb +9 -14
- data/lib/spontaneous/data_mapper/content_table.rb +4 -2
- data/lib/spontaneous/data_mapper/dataset.rb +31 -2
- data/lib/spontaneous/data_mapper/scope.rb +37 -20
- data/lib/spontaneous/errors.rb +6 -0
- data/lib/spontaneous/facet.rb +20 -10
- data/lib/spontaneous/field/base.rb +8 -1
- data/lib/spontaneous/field/file.rb +28 -3
- data/lib/spontaneous/field/image.rb +2 -0
- data/lib/spontaneous/field/update.rb +6 -0
- data/lib/spontaneous/field/webvideo/vimeo.rb +6 -1
- data/lib/spontaneous/field/webvideo/vine.rb +1 -1
- data/lib/spontaneous/field/webvideo/youtube.rb +1 -1
- data/lib/spontaneous/generators/site.rb +6 -4
- data/lib/spontaneous/generators/site/.gitignore +1 -0
- data/lib/spontaneous/generators/site/Gemfile.tt +3 -3
- data/lib/spontaneous/generators/site/config/{indexes.rb.tt → initializers/indexes.rb.tt} +0 -0
- data/lib/spontaneous/generators/site/config/initializers/publishing.rb.tt +78 -0
- data/lib/spontaneous/generators/site/{config/database.yml.tt → db/mysql2.yml.tt} +7 -6
- data/lib/spontaneous/generators/site/db/postgres.yml.tt +25 -0
- data/lib/spontaneous/generators/site/db/sqlite3.yml.tt +18 -0
- data/lib/spontaneous/generators/site/public/humans.txt.tt +14 -0
- data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +51 -0
- data/lib/spontaneous/loader.rb +1 -1
- data/lib/spontaneous/logger.rb +1 -1
- data/lib/spontaneous/media/image/optimizer.rb +1 -1
- data/lib/spontaneous/media/image/processor.rb +11 -2
- data/lib/spontaneous/media/image/renderable.rb +2 -0
- data/lib/spontaneous/model.rb +3 -0
- data/lib/spontaneous/model/box/allowed_types.rb +17 -4
- data/lib/spontaneous/model/core.rb +36 -3
- data/lib/spontaneous/model/core/aliases.rb +5 -2
- data/lib/spontaneous/model/core/boxes.rb +6 -0
- data/lib/spontaneous/model/core/cascading_change.rb +38 -0
- data/lib/spontaneous/model/core/content_hash.rb +171 -0
- data/lib/spontaneous/model/core/entries.rb +0 -19
- data/lib/spontaneous/model/core/fields.rb +11 -0
- data/lib/spontaneous/model/core/modifications.rb +22 -21
- data/lib/spontaneous/model/core/render.rb +3 -0
- data/lib/spontaneous/model/core/serialisation.rb +18 -17
- data/lib/spontaneous/model/page.rb +35 -8
- data/lib/spontaneous/model/page/page_tree.rb +20 -8
- data/lib/spontaneous/model/page/paths.rb +79 -50
- data/lib/spontaneous/model/page/singleton.rb +71 -0
- data/lib/spontaneous/model/page/site_map.rb +2 -1
- data/lib/spontaneous/model/page/site_timestamps.rb +2 -2
- data/lib/spontaneous/model/piece.rb +10 -0
- data/lib/spontaneous/output/context.rb +13 -6
- data/lib/spontaneous/output/format.rb +30 -5
- data/lib/spontaneous/output/helpers/script_helper.rb +8 -0
- data/lib/spontaneous/output/helpers/stylesheet_helper.rb +7 -0
- data/lib/spontaneous/output/renderable.rb +16 -0
- data/lib/spontaneous/output/store.rb +1 -1
- data/lib/spontaneous/output/template/renderer.rb +2 -2
- data/lib/spontaneous/page_piece.rb +25 -1
- data/lib/spontaneous/prototypes/box_prototype.rb +13 -0
- data/lib/spontaneous/prototypes/field_prototype.rb +7 -4
- data/lib/spontaneous/publishing.rb +10 -5
- data/lib/spontaneous/publishing/immediate.rb +32 -349
- data/lib/spontaneous/publishing/pipeline.rb +43 -0
- data/lib/spontaneous/publishing/progress.rb +186 -0
- data/lib/spontaneous/publishing/publish.rb +107 -0
- data/lib/spontaneous/publishing/rerender.rb +17 -0
- data/lib/spontaneous/publishing/revision.rb +53 -18
- data/lib/spontaneous/publishing/simultaneous.rb +1 -1
- data/lib/spontaneous/publishing/steps.rb +154 -0
- data/lib/spontaneous/publishing/steps/activate_revision.rb +45 -0
- data/lib/spontaneous/publishing/steps/archive_old_revisions.rb +22 -0
- data/lib/spontaneous/publishing/steps/base_step.rb +49 -0
- data/lib/spontaneous/publishing/steps/copy_static_files.rb +74 -0
- data/lib/spontaneous/publishing/steps/create_revision_directory.rb +24 -0
- data/lib/spontaneous/publishing/steps/generate_rackup_file.rb +51 -0
- data/lib/spontaneous/publishing/steps/generate_search_indexes.rb +24 -0
- data/lib/spontaneous/publishing/steps/render_revision.rb +69 -0
- data/lib/spontaneous/publishing/steps/write_revision_file.rb +43 -0
- data/lib/spontaneous/rack/back.rb +3 -1
- data/lib/spontaneous/rack/back/alias.rb +9 -8
- data/lib/spontaneous/rack/front.rb +1 -1
- data/lib/spontaneous/rack/middleware.rb +7 -4
- data/lib/spontaneous/rack/middleware/transaction.rb +14 -0
- data/lib/spontaneous/rack/page_controller.rb +23 -8
- data/lib/spontaneous/revision.rb +5 -10
- data/lib/spontaneous/schema.rb +5 -0
- data/lib/spontaneous/server.rb +3 -1
- data/lib/spontaneous/site.rb +17 -10
- data/lib/spontaneous/site/publishing.rb +25 -3
- data/lib/spontaneous/site/state.rb +7 -3
- data/lib/spontaneous/tasks/database.rake +5 -10
- data/lib/spontaneous/utils/database/mysql_dumper.rb +5 -1
- data/lib/spontaneous/version.rb +1 -1
- data/spontaneous.gemspec +4 -3
- data/test/fixtures/example_application/config/initializers/initializer1.rb +1 -0
- data/test/fixtures/example_application/config/initializers/initializer2.rb +1 -0
- data/test/fixtures/example_application/config/initializers/publishing.rb +13 -0
- data/test/fixtures/search/config/{indexes.rb → initializers/indexes.rb} +0 -0
- data/test/fixtures/serialisation/root_hash.yaml.erb +10 -4
- data/test/functional/test_application.rb +10 -0
- data/test/functional/test_back.rb +23 -5
- data/test/functional/test_cli.rb +98 -34
- data/test/functional/test_front.rb +7 -3
- data/test/test_helper.rb +35 -28
- data/test/unit/test_alias.rb +20 -3
- data/test/unit/test_assets.rb +58 -30
- data/test/unit/test_changesets.rb +20 -12
- data/test/unit/test_content_hash.rb +496 -0
- data/test/unit/test_context.rb +28 -1
- data/test/unit/test_controllers.rb +96 -61
- data/test/unit/test_crypt.rb +1 -8
- data/test/unit/test_datamapper.rb +95 -19
- data/test/unit/test_features.rb +1 -4
- data/test/unit/test_fields.rb +61 -12
- data/test/unit/test_generators.rb +39 -2
- data/test/unit/test_images.rb +3 -1
- data/test/unit/test_modifications.rb +224 -219
- data/test/unit/test_output_store.rb +10 -0
- data/test/unit/{test_formats.rb → test_outputs.rb} +75 -6
- data/test/unit/test_page.rb +61 -15
- data/test/unit/test_plugins.rb +2 -42
- data/test/unit/test_publishing_pipeline.rb +1050 -0
- data/test/unit/test_render.rb +30 -0
- data/test/unit/test_revisions.rb +110 -2
- data/test/unit/test_schema.rb +4 -0
- data/test/unit/test_search.rb +1 -1
- data/test/unit/test_serialisation.rb +6 -1
- data/test/unit/test_singletons.rb +159 -0
- data/test/unit/test_site.rb +71 -44
- metadata +140 -86
- data/application/static/font/fontawesome-webfont-1c66a4738b40ef0f6b1abca0ba9a796d.ttf +0 -0
- data/test/unit/test_publishing.rb +0 -330
@@ -0,0 +1,496 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path('../../test_helper', __FILE__)
|
4
|
+
|
5
|
+
# The guiding principle of the content hash is that if it renders the same then
|
6
|
+
# it should give the same content hash.
|
7
|
+
describe "Content Hash" do
|
8
|
+
let(:page_class) { Page }
|
9
|
+
let(:piece_class) { Piece }
|
10
|
+
let(:root) { page_class.create }
|
11
|
+
let(:piece) { piece_class.new }
|
12
|
+
let(:hashes) { [] }
|
13
|
+
let(:now) { Time.now }
|
14
|
+
|
15
|
+
def assert_uniq_hashes(n)
|
16
|
+
hashes.compact.uniq.length.must_equal n
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
Timecop.freeze(now)
|
21
|
+
@site = setup_site
|
22
|
+
page_class.field :title
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
Content.delete
|
27
|
+
teardown_site
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "Field" do
|
31
|
+
before do
|
32
|
+
page_class.field :title
|
33
|
+
end
|
34
|
+
let(:field) { root.title }
|
35
|
+
|
36
|
+
it "has a different content hash for different value" do
|
37
|
+
field.value = "original"
|
38
|
+
hash1 = field.calculate_content_hash
|
39
|
+
field.value = "different"
|
40
|
+
hash2 = field.calculate_content_hash
|
41
|
+
hash2.wont_equal hash1
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns the same hash if the value is reverted" do
|
45
|
+
field.value = "original"
|
46
|
+
hash1 = field.calculate_content_hash
|
47
|
+
field.value = "different"
|
48
|
+
field.value = "original"
|
49
|
+
hash2 = field.calculate_content_hash
|
50
|
+
hash2.must_equal hash1
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "Box" do
|
55
|
+
let(:box) { piece.box1 }
|
56
|
+
|
57
|
+
before do
|
58
|
+
piece_class.field :field1
|
59
|
+
piece_class.box :box1 do
|
60
|
+
field :field1
|
61
|
+
field :field2
|
62
|
+
end
|
63
|
+
piece.save
|
64
|
+
end
|
65
|
+
|
66
|
+
it "updates the hash for any field change" do
|
67
|
+
hashes << box.calculate_content_hash
|
68
|
+
box.field1 = "changed"
|
69
|
+
hashes << box.calculate_content_hash
|
70
|
+
box.field2 = "changed again"
|
71
|
+
hashes << box.calculate_content_hash
|
72
|
+
hashes.uniq.length.must_equal 3
|
73
|
+
end
|
74
|
+
|
75
|
+
it "updates the hash if an entry is added" do
|
76
|
+
hashes << box.calculate_content_hash
|
77
|
+
added = piece_class.new
|
78
|
+
box << added
|
79
|
+
hashes << box.calculate_content_hash
|
80
|
+
hashes.uniq.length.must_equal 2
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "with entries" do
|
84
|
+
before do
|
85
|
+
hashes << box.calculate_content_hash
|
86
|
+
@added1 = piece_class.create(field1: "added1")
|
87
|
+
@added2 = piece_class.create(field1: "added2")
|
88
|
+
box << @added1
|
89
|
+
box << @added2
|
90
|
+
hashes << box.calculate_content_hash
|
91
|
+
end
|
92
|
+
|
93
|
+
it "gives the same hash if new entries are deleted" do
|
94
|
+
box.entries[0].destroy
|
95
|
+
hashes << box.calculate_content_hash
|
96
|
+
box.entries[0].destroy
|
97
|
+
hashes << box.calculate_content_hash
|
98
|
+
hashes.uniq.length.must_equal 3
|
99
|
+
hashes.first.must_equal hashes.last
|
100
|
+
end
|
101
|
+
|
102
|
+
it "updates the hash if entries are reordered" do
|
103
|
+
@added2.update_position(0)
|
104
|
+
hashes << box.calculate_content_hash
|
105
|
+
hashes.uniq.length.must_equal 3
|
106
|
+
end
|
107
|
+
|
108
|
+
it "preserves the hash if an identical entry is added as a replacement" do
|
109
|
+
hashes.clear
|
110
|
+
hashes << box.calculate_content_hash
|
111
|
+
box.entries.last.destroy
|
112
|
+
hashes << box.calculate_content_hash
|
113
|
+
box << piece_class.create(field1: "added2")
|
114
|
+
hashes << box.calculate_content_hash
|
115
|
+
hashes.uniq.length.must_equal 2
|
116
|
+
hashes.first.must_equal hashes.last
|
117
|
+
end
|
118
|
+
|
119
|
+
it "returns an empty hash if empty & has no fields" do
|
120
|
+
piece_class.box :box2
|
121
|
+
box = piece_class.new.box2
|
122
|
+
box.calculate_content_hash.must_equal ""
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "PagePiece" do
|
127
|
+
let(:box) { piece.box1 }
|
128
|
+
let(:new_page) { page_class.create }
|
129
|
+
|
130
|
+
before do
|
131
|
+
root
|
132
|
+
hashes << box.calculate_content_hash
|
133
|
+
box << new_page
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should give identical values for #calculate_content_hash! and #calculate_content_hash" do
|
137
|
+
piece = box.first
|
138
|
+
piece.calculate_content_hash.must_equal piece.content_hash
|
139
|
+
piece.calculate_content_hash.must_equal piece.calculate_content_hash!
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should update the boxes content hash if a page is added" do
|
143
|
+
box << new_page
|
144
|
+
hashes << box.calculate_content_hash
|
145
|
+
hashes.uniq.length.must_equal 2
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should not change the box content hash if the page is updated" do
|
149
|
+
box << new_page
|
150
|
+
hashes << box.calculate_content_hash
|
151
|
+
new_page.update(title: "something different")
|
152
|
+
hashes << box.calculate_content_hash
|
153
|
+
hashes.uniq.length.must_equal 2
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "Piece" do
|
160
|
+
before do
|
161
|
+
piece_class.field :field1, default: "original"
|
162
|
+
piece_class.field :field2, default: "original"
|
163
|
+
piece_class.box :box1 do
|
164
|
+
field :box_field1
|
165
|
+
end
|
166
|
+
piece_class.box :box2
|
167
|
+
hashes << piece.calculate_content_hash
|
168
|
+
end
|
169
|
+
|
170
|
+
it "updates the hash for any field change" do
|
171
|
+
piece.field1 = "changed"
|
172
|
+
hashes << piece.calculate_content_hash
|
173
|
+
piece.field2 = "changed again"
|
174
|
+
hashes << piece.calculate_content_hash
|
175
|
+
hashes.uniq.length.must_equal 3
|
176
|
+
end
|
177
|
+
|
178
|
+
it "updates the hash for any visibility change" do
|
179
|
+
piece.hide!
|
180
|
+
hashes << piece.calculate_content_hash
|
181
|
+
hashes.uniq.length.must_equal 2
|
182
|
+
end
|
183
|
+
|
184
|
+
it "has the same hash if the field values are the same" do
|
185
|
+
piece.field1 = "changed 1"
|
186
|
+
piece.field2 = "changed 2"
|
187
|
+
hashes << piece.calculate_content_hash
|
188
|
+
piece.field1 = "original"
|
189
|
+
piece.field2 = "original"
|
190
|
+
hashes << piece.calculate_content_hash
|
191
|
+
hashes.uniq.length.must_equal 2
|
192
|
+
hashes[0].must_equal hashes[2]
|
193
|
+
end
|
194
|
+
|
195
|
+
it "gives identical hashes for different entries with same type & fields" do
|
196
|
+
one = piece_class.create(field1: "a", field2: "b")
|
197
|
+
two = piece_class.create(field1: "a", field2: "b")
|
198
|
+
one.calculate_content_hash.must_equal two.calculate_content_hash
|
199
|
+
end
|
200
|
+
|
201
|
+
it "is dependent on box hashes" do
|
202
|
+
piece.box2.expects(:content_hash).returns("notverylikely")
|
203
|
+
hashes << piece.calculate_content_hash
|
204
|
+
hashes.uniq.length.must_equal 2
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "Page" do
|
209
|
+
let(:middle) { page_class.create(slug: 'middle', title: 'middle') }
|
210
|
+
let(:page) { page_class.create(slug: 'child', title: 'original') }
|
211
|
+
|
212
|
+
before do
|
213
|
+
page_class.box :box1
|
214
|
+
page_class.box :box2, generated: true
|
215
|
+
root.box1 << middle
|
216
|
+
middle.box1 << page
|
217
|
+
root.save
|
218
|
+
middle.save
|
219
|
+
page.save
|
220
|
+
hashes << page.calculate_content_hash
|
221
|
+
end
|
222
|
+
|
223
|
+
it "calculates the correct content hash at creation" do
|
224
|
+
hashes.clear
|
225
|
+
page = page_class.create(slug: 'funny', title: 'haha')
|
226
|
+
hashes << page.content_hash
|
227
|
+
page.save
|
228
|
+
hashes << page.content_hash
|
229
|
+
hashes.uniq.length.must_equal 1
|
230
|
+
end
|
231
|
+
|
232
|
+
it "updates the content hash when field values change" do
|
233
|
+
page.title = 'different'
|
234
|
+
hashes << page.calculate_content_hash
|
235
|
+
hashes.uniq.length.must_equal 2
|
236
|
+
end
|
237
|
+
|
238
|
+
it "updates the hash for any visibility change" do
|
239
|
+
page.hide!
|
240
|
+
hashes << page.calculate_content_hash
|
241
|
+
hashes.uniq.length.must_equal 2
|
242
|
+
end
|
243
|
+
|
244
|
+
it "reverts the content hash when field values are reverted" do
|
245
|
+
page.title = 'different'
|
246
|
+
hashes << page.calculate_content_hash
|
247
|
+
page.title = 'original'
|
248
|
+
hashes << page.calculate_content_hash
|
249
|
+
hashes.uniq.length.must_equal 2
|
250
|
+
hashes.first.must_equal hashes.last
|
251
|
+
end
|
252
|
+
|
253
|
+
it "is dependent on box hashes" do
|
254
|
+
page.box1.expects(:content_hash).returns('unlikely')
|
255
|
+
hashes << page.calculate_content_hash
|
256
|
+
hashes.uniq.length.must_equal 2
|
257
|
+
end
|
258
|
+
|
259
|
+
it "skips boxes marked as 'generated'" do
|
260
|
+
page.box2.stubs(:calculate_content_hash).returns('unlikely')
|
261
|
+
hashes << page.calculate_content_hash
|
262
|
+
hashes.uniq.length.must_equal 1
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
describe "Alias" do
|
267
|
+
let(:page1) { page_class.create(slug: "page1", title: "Page 1") }
|
268
|
+
let(:page2) { page_class.create(slug: "page2", title: "Page 2") }
|
269
|
+
before do
|
270
|
+
class ::PieceAlias < ::Piece
|
271
|
+
alias_of :Page
|
272
|
+
field :title
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
after do
|
277
|
+
Object.send :remove_const, :PieceAlias
|
278
|
+
end
|
279
|
+
|
280
|
+
it "aliases of same content with same fields must have same hashes" do
|
281
|
+
al1 = PieceAlias.create(target: page1, title: "the same")
|
282
|
+
al2 = PieceAlias.create(target: page1, title: "the same")
|
283
|
+
al1.content_hash.must_equal al2.content_hash
|
284
|
+
end
|
285
|
+
|
286
|
+
it "aliases of same content with different fields must have different hashes" do
|
287
|
+
al1 = PieceAlias.create(target: page1, title: "the same")
|
288
|
+
al2 = PieceAlias.create(target: page1, title: "different")
|
289
|
+
al1.content_hash.wont_equal al2.content_hash
|
290
|
+
end
|
291
|
+
|
292
|
+
it "aliases of different content with same fields must have different hashes" do
|
293
|
+
al1 = PieceAlias.create(target: page1, title: "the same")
|
294
|
+
al2 = PieceAlias.create(target: page2, title: "the same")
|
295
|
+
al1.content_hash.wont_equal al2.content_hash
|
296
|
+
end
|
297
|
+
|
298
|
+
it "aliases of different content with different fields must have different hashes" do
|
299
|
+
al1 = PieceAlias.create(target: page1, title: "the same")
|
300
|
+
al2 = PieceAlias.create(target: page2, title: "different")
|
301
|
+
al1.content_hash.wont_equal al2.content_hash
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
describe "Content Tree" do
|
306
|
+
let(:middle) { page_class.create(slug: 'middle', title: 'middle') }
|
307
|
+
let(:page) { page_class.create(slug: 'page', title: 'original') }
|
308
|
+
let(:child) { piece_class.create(field1: 'child') }
|
309
|
+
let(:grand_child) { piece_class.create(field1: 'grand child') }
|
310
|
+
|
311
|
+
before do
|
312
|
+
page_class.box :box1 do
|
313
|
+
field :field1
|
314
|
+
end
|
315
|
+
piece_class.box :box1 do
|
316
|
+
field :field1
|
317
|
+
end
|
318
|
+
piece_class.field :field1
|
319
|
+
root.box1 << middle
|
320
|
+
middle.box1 << page
|
321
|
+
page.box1 << child
|
322
|
+
child.box1 << grand_child
|
323
|
+
[root, middle, page, child, grand_child].each do |content|
|
324
|
+
content.save ; content.reload
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
it "sets the content_hash attribute of pages on create" do
|
329
|
+
page[:content_hash].must_equal page.calculate_content_hash
|
330
|
+
end
|
331
|
+
|
332
|
+
it "sets the content_hash attribute of pieces on create" do
|
333
|
+
child[:content_hash].must_equal child.calculate_content_hash
|
334
|
+
end
|
335
|
+
|
336
|
+
it "sets the content_hash_changed to true" do
|
337
|
+
child[:content_hash_changed].must_equal true
|
338
|
+
end
|
339
|
+
|
340
|
+
it "updates the page hash when page box fields change" do
|
341
|
+
hashes << page.content_hash
|
342
|
+
page.box1.field1 = "different"
|
343
|
+
page.save
|
344
|
+
hashes << page.reload[:content_hash]
|
345
|
+
assert_uniq_hashes 2
|
346
|
+
end
|
347
|
+
|
348
|
+
it "updates the owning page hash when child pieces are updated" do
|
349
|
+
hashes << page[:content_hash]
|
350
|
+
child.field1 = "different"
|
351
|
+
child.save
|
352
|
+
hashes << page.reload[:content_hash]
|
353
|
+
assert_uniq_hashes 2
|
354
|
+
end
|
355
|
+
|
356
|
+
it "updates the owning page hash when child pieces hidden" do
|
357
|
+
hashes << page[:content_hash]
|
358
|
+
child.hide!
|
359
|
+
hashes << page.reload[:content_hash]
|
360
|
+
assert_uniq_hashes 2
|
361
|
+
end
|
362
|
+
|
363
|
+
it "updates the owning page hash when boxes of child pieces are updated" do
|
364
|
+
hashes << page.content_hash
|
365
|
+
child.box1.field1 = "different"
|
366
|
+
child.save
|
367
|
+
hashes << page.reload[:content_hash]
|
368
|
+
assert_uniq_hashes 2
|
369
|
+
end
|
370
|
+
|
371
|
+
it "updates the owning page hash when children of child pieces are updated" do
|
372
|
+
hashes << page[:content_hash]
|
373
|
+
grand_child.box1.field1 = "different"
|
374
|
+
grand_child.save
|
375
|
+
hashes << page.reload[:content_hash]
|
376
|
+
assert_uniq_hashes 2
|
377
|
+
end
|
378
|
+
|
379
|
+
it "doesn't update the parent page hash when a child page is added" do
|
380
|
+
hashes << middle[:content_hash]
|
381
|
+
middle.box1 << page_class.create(slug: "added", title: "added")
|
382
|
+
middle.save
|
383
|
+
hashes << middle.reload[:content_hash]
|
384
|
+
assert_uniq_hashes 1
|
385
|
+
end
|
386
|
+
|
387
|
+
it "doesn't update the parent page hash when a child page is added to an entry" do
|
388
|
+
hashes << page[:content_hash]
|
389
|
+
Content.scope do
|
390
|
+
grand_child.box1 << page_class.create(slug: "added", title: "added")
|
391
|
+
grand_child.save
|
392
|
+
end
|
393
|
+
hashes << page.reload[:content_hash]
|
394
|
+
assert_uniq_hashes 1
|
395
|
+
end
|
396
|
+
|
397
|
+
it "doesn't update the parent page hash when the child page is updated" do
|
398
|
+
page_class.dataset.filter(id: middle.id).update(content_hash: "generated")
|
399
|
+
grand_child.box1.field1 = "different"
|
400
|
+
grand_child.save
|
401
|
+
middle.reload.content_hash.must_equal "generated"
|
402
|
+
end
|
403
|
+
|
404
|
+
it "doesn't cascade content modifications up the page tree when a new page is added" do
|
405
|
+
page.reload
|
406
|
+
ancestors = page.ancestors
|
407
|
+
page_class.dataset.filter(id: ancestors.map(&:id)).update(content_hash: "generated")
|
408
|
+
page.box1 << page_class.new(slug: "added")
|
409
|
+
page.save
|
410
|
+
ancestors.map { |a| a.reload.content_hash }.must_equal ["generated"]*ancestors.length
|
411
|
+
end
|
412
|
+
|
413
|
+
it "updates the page hash when its slug changes" do
|
414
|
+
hashes << page.content_hash
|
415
|
+
page.update(slug: "wow-im-different")
|
416
|
+
hashes << page.reload.content_hash
|
417
|
+
hashes.length.must_equal 2
|
418
|
+
hashes.uniq.length.must_equal 2
|
419
|
+
end
|
420
|
+
|
421
|
+
it "doesn't update the child hash when the parent slug changes" do
|
422
|
+
hashes << page.content_hash
|
423
|
+
middle.update(slug: "wow-im-different")
|
424
|
+
hashes << page.reload.content_hash
|
425
|
+
hashes.length.must_equal 2
|
426
|
+
hashes.uniq.length.must_equal 1
|
427
|
+
end
|
428
|
+
|
429
|
+
it "updates the parent page hash if child pages are re-ordered" do
|
430
|
+
page2 = page_class.new(slug: 'page3', title: 'page2')
|
431
|
+
middle.box1 << page2
|
432
|
+
middle.save
|
433
|
+
page2.save
|
434
|
+
page2.reload
|
435
|
+
middle.reload
|
436
|
+
hashes << middle.content_hash
|
437
|
+
page2.update_position(0)
|
438
|
+
hashes << middle.reload[:content_hash]
|
439
|
+
hashes.length.must_equal 2
|
440
|
+
hashes.uniq.length.must_equal 2
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
describe "content_hash_changed" do
|
445
|
+
let(:page) { page_class.create(title: "something")}
|
446
|
+
|
447
|
+
describe "before publishing" do
|
448
|
+
it "sets the changed flag when content_hash differs" do
|
449
|
+
page.update(title: "different")
|
450
|
+
page.content_hash_changed.must_equal true
|
451
|
+
end
|
452
|
+
|
453
|
+
it "sets the content hash changed timestamp" do
|
454
|
+
later = now + 3239
|
455
|
+
Timecop.travel(later) do
|
456
|
+
page.update(title: "different")
|
457
|
+
end
|
458
|
+
(page.content_hash_changed_at - later).must_be :<=, 1
|
459
|
+
end
|
460
|
+
|
461
|
+
it "keeps the flag set no matter what" do
|
462
|
+
page.update(title: "different")
|
463
|
+
page.content_hash_changed.must_equal true
|
464
|
+
page.update(title: "something")
|
465
|
+
page.content_hash_changed.must_equal true
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
describe "after publishing" do
|
470
|
+
before do
|
471
|
+
page.update(published_content_hash: page.calculate_content_hash, content_hash_changed: false)
|
472
|
+
end
|
473
|
+
|
474
|
+
it "sets the changed flag when content_hash differs" do
|
475
|
+
page.update(title: "different")
|
476
|
+
page.content_hash_changed.must_equal true
|
477
|
+
end
|
478
|
+
|
479
|
+
it "sets the content hash changed timestamp" do
|
480
|
+
later = now + 3239
|
481
|
+
Timecop.travel(later) do
|
482
|
+
page.update(title: "different")
|
483
|
+
end
|
484
|
+
(page.content_hash_changed_at - later).must_be :<=, 1
|
485
|
+
end
|
486
|
+
|
487
|
+
it "leaves the changed flag when content_hash differs" do
|
488
|
+
original_title = page.title.value
|
489
|
+
page.update(title: "different")
|
490
|
+
page.content_hash_changed.must_equal true
|
491
|
+
page.update(title: original_title)
|
492
|
+
page.content_hash_changed.must_equal false
|
493
|
+
end
|
494
|
+
end
|
495
|
+
end
|
496
|
+
end
|