test/unit/test_changesets.rb in spontaneous-0.2.0.beta5 vs test/unit/test_changesets.rb in spontaneous-0.2.0.beta6
- old
+ new
@@ -7,14 +7,15 @@
before do
@now = Time.now
@site = setup_site
- stub_time(@now)
+ Timecop.freeze(@now)
@revision = 1
Content.delete
+ Spontaneous::State.delete
class ::Page
field :title, :string, :default => "New Page"
box :things
end
@@ -23,10 +24,11 @@
box :things
end
end
after do
+ Timecop.return
Content.delete_revision(@revision) rescue nil
Content.delete_revision(@revision+1) rescue nil
Content.delete
@site.must_publish_all!(false)
teardown_site
@@ -53,13 +55,14 @@
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
+ Content.publish(@revision)
+
5.times { |i| root.things << Page.create(:title => "Page #{i+1}") }
result = outstanding_changes
result.must_be_instance_of(Hash)
@@ -73,13 +76,10 @@
end
it "not list new pieces as available for publish" do
root = Page.create(:title => "root")
Content.publish(@revision)
- # 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 = outstanding_changes[:changes]
result.length.must_equal 1
result.first.page.must_equal root
@@ -217,15 +217,18 @@
Content.publish(@revision)
root.reload
page1 = Page.new(:title => "Page 1")
root.things << page1
+ root.save.reload
+ page1.save.reload
+ last = Time.now + 100
+ Timecop.travel(last)
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)
+ page1.save
+ new_child1.save
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
@@ -236,22 +239,25 @@
page1 = Page.new(:title => "Page 1")
root.things << page1
new_child1 = Page.new(:title => "New Child 1")
page1.things << new_child1
root.save
+ new_child1.save
Content.publish(@revision)
+ page1.reload
later = @now + 10
- stub_time(later)
+ Timecop.travel(later)
old_slug = page1.slug
page1.slug = "changed"
- page1.save
+ page1.save.reload
result = outstanding_changes[:changes]
change = result.detect { |change| change.page.id == page1.id }
+ refute change.nil?
change.export[:side_effects].must_equal({
:slug => [{ :count => 1, :created_at => later.httpdate, :old_value => old_slug, :new_value => "changed"}]
})
end
@@ -265,17 +271,19 @@
new_child1 = Page.new(:title => "New Child 1")
page1.things << new_child1
root.save
Content.publish(@revision)
+ page1.reload
later = @now + 10
- stub_time(later)
+ Timecop.travel(later)
page1.hide!
- page1.reload
+
result = outstanding_changes[:changes]
change = result.detect { |change| change.page.id == page1.id }
+ refute change.nil?
change.export[:side_effects].must_equal({
:visibility => [{ :count => 1, :created_at => later.httpdate, :old_value => false, :new_value => true}]
})
end