test/unit/test_changesets.rb in spontaneous-0.2.0.beta4 vs test/unit/test_changesets.rb in spontaneous-0.2.0.beta5
- old
+ new
@@ -26,31 +26,43 @@
after do
Content.delete_revision(@revision) rescue nil
Content.delete_revision(@revision+1) rescue nil
Content.delete
+ @site.must_publish_all!(false)
teardown_site
end
+ def outstanding_changes
+ S::Change.outstanding(@site)
+ end
+
it "flag if the site has never been published" do
root = Page.create(:title => "root")
5.times { |i| root.things << Page.create(:title => "Page #{i+1}") }
- result = S::Change.outstanding
+ result = outstanding_changes
assert result.key?(:published_revision)
result[:published_revision].must_equal 0
assert result[:first_publish]
end
+ it "honors the site must_publish_all? flag" do
+ @site.must_publish_all!
+ root = Page.create(:title => "root")
+ result = outstanding_changes
+ result[:must_publish_all].must_equal true
+ end
+
it "list all newly created pages" do
root = Page.create(:title => "root")
root[:first_published_at] = root[:last_published_at] = root.modified_at + 1000
root.save
5.times { |i| root.things << Page.create(:title => "Page #{i+1}") }
- result = S::Change.outstanding
+ result = outstanding_changes
result.must_be_instance_of(Hash)
pages = result[:changes]
pages.must_be_instance_of(Array)
pages.length.must_equal 5
@@ -66,11 +78,11 @@
# force root to appear in the modified lists -- need this because otherwise the changes happen
# more quickly than the resolution of the timestamps can register
root[:first_published_at] = root[:last_published_at] = root.modified_at - 1000
root.things << Piece.new
root.save.reload
- result = S::Change.outstanding[:changes]
+ result = outstanding_changes[:changes]
result.length.must_equal 1
result.first.page.must_equal root
end
it "not list pages that have been published" do
@@ -81,11 +93,11 @@
5.times { |i| root.things << Page.create(:title => "Page #{i+1}") }
root.save
Content.publish(@revision+1, [root.id, root.things.first.id])
- result = S::Change.outstanding[:changes]
+ result = outstanding_changes[:changes]
result.length.must_equal 4
Set.new(result.map(&:page_id).flatten).must_equal Set.new(root.things[1..-1].map(&:id))
end
it "group unpublished parents with their children" do
@@ -108,11 +120,11 @@
pages = [root, page1, new_child1, new_parent, new_child2, new_child3]
pages.each(&:save)
Content.publish(@revision+1, [root.id])
- result = S::Change.outstanding[:changes]
+ result = outstanding_changes[:changes]
result.length.must_equal 5
id_groups = result.map { |change|
[change.page.id, change.dependent.map(&:id)]
@@ -146,11 +158,11 @@
pages = [root, page1, new_child1, new_parent, new_child2, new_child3]
pages.each(&:save)
Content.publish(@revision+1, [root.id])
- result = S::Change.outstanding[:changes]
+ result = outstanding_changes[:changes]
e = nil
begin
pages = Spontaneous::Change.include_dependencies([new_child3])
Content.publish(@revision+2, pages)
@@ -172,11 +184,11 @@
new_child1 = Page.new(:title => "New Child 1")
page1.things << new_child1
root.save
Content.publish(@revision+1, [root.id])
- result = S::Change.outstanding[:changes]
+ result = outstanding_changes[:changes]
change = result.detect { |change| change.page.id == new_child1.id }
change.export.must_equal({
:id => new_child1.id,
:title => new_child1.title.value,
:url => new_child1.path,
@@ -210,11 +222,11 @@
new_child1 = Page.new(:title => "New Child 1")
page1.things << new_child1
root.save
last = Time.now + 100
::Content.filter(:id => new_child1.id).update(:modified_at => last)
- result = S::Change.outstanding[:changes]
+ result = outstanding_changes[:changes]
assert result.first.modified_at > result.last.modified_at, "Change list in incorrect order"
end
it "provide information on side effects of publishing page with path changes" do
root = Page.create(:title => "root")
@@ -233,11 +245,11 @@
stub_time(later)
old_slug = page1.slug
page1.slug = "changed"
page1.save
- result = S::Change.outstanding[:changes]
+ result = outstanding_changes[:changes]
change = result.detect { |change| change.page.id == page1.id }
change.export[:side_effects].must_equal({
:slug => [{ :count => 1, :created_at => later.httpdate, :old_value => old_slug, :new_value => "changed"}]
})
@@ -259,11 +271,11 @@
later = @now + 10
stub_time(later)
page1.hide!
page1.reload
- result = S::Change.outstanding[:changes]
+ result = outstanding_changes[:changes]
change = result.detect { |change| change.page.id == page1.id }
change.export[:side_effects].must_equal({
:visibility => [{ :count => 1, :created_at => later.httpdate, :old_value => false, :new_value => true}]
})
end
@@ -279,10 +291,10 @@
page.save
piece.save
lock = Spontaneous::PageLock.create(:page_id => page.id, :content_id => piece.id, :field_id => piece.async.id, :description => "Update Lock")
assert page.locked_for_update?
- result = S::Change.outstanding[:changes]
+ result = outstanding_changes[:changes]
change = result.detect { |change| change.page.id == page.id }
change.export[:update_locks].must_equal [{
id: lock.id,
content_id: piece.id,
field_id: piece.async.id,