test/unit/test_content.rb in spontaneous-0.2.0.alpha2 vs test/unit/test_content.rb in spontaneous-0.2.0.alpha3

- old
+ new

@@ -6,19 +6,26 @@ class ContentTest < MiniTest::Spec context "Content:" do setup do @site = setup_site class Piece < Spontaneous::Piece; end + class Page < Spontaneous::Page; end class C < Piece; end + class P < Page; end C.box :things + P.box :box1 + P.box :box2 end teardown do teardown_site ContentTest.send(:remove_const, :Piece) rescue nil + ContentTest.send(:remove_const, :Page) rescue nil ContentTest.send(:remove_const, :C) rescue nil + ContentTest.send(:remove_const, :P) rescue nil end + context "Content instances" do should "evaluate instance code" do @instance = C.create({ :instance_code => "def monkey; 'magic'; end" }) @@ -35,54 +42,58 @@ teardown do Content.delete end should "be initialised empty" do - @instance.pieces.should == [] + @instance.contents.should == [] end + should "provide a #target method poiting to itself" do + @instance.target.should == @instance + end + should "accept addition of child content" do e = C.new @instance.things << e - @instance.pieces.length.should == 1 - @instance.things.pieces.length.should == 1 - @instance.pieces.first.should == e - @instance.pieces.first.container.should == @instance.things - @instance.pieces.first.owner.should == @instance - @instance.pieces.first.parent.should == @instance + @instance.contents.length.should == 1 + @instance.things.contents.length.should == 1 + @instance.contents.first.should == e + @instance.contents.first.container.should == @instance.things + @instance.contents.first.owner.should == @instance + @instance.contents.first.parent.should == @instance e.visibility_path.should == "#{@instance.id}" - @instance.pieces.first.visibility_path.should == "#{@instance.id}" + @instance.contents.first.visibility_path.should == "#{@instance.id}" end should "accept addition of multiple children" do e = C.new f = C.new @instance.things << e @instance.things << f - @instance.pieces.length.should == 2 - @instance.things.pieces.length.should == 2 - @instance.pieces.first.should == e - @instance.things.pieces.first.should == e - @instance.pieces.last.should == f - @instance.things.pieces.last.should == f - @instance.pieces.first.container.should == @instance.things - @instance.pieces.last.container.should == @instance.things - @instance.pieces.first.parent.should == @instance - @instance.pieces.last.parent.should == @instance - @instance.pieces.first.owner.should == @instance - @instance.pieces.last.owner.should == @instance - @instance.pieces.first.visibility_path.should == "#{@instance.id}" - @instance.pieces.last.visibility_path.should == "#{@instance.id}" + @instance.contents.length.should == 2 + @instance.things.contents.length.should == 2 + @instance.contents.first.should == e + @instance.things.contents.first.should == e + @instance.contents.last.should == f + @instance.things.contents.last.should == f + @instance.contents.first.container.should == @instance.things + @instance.contents.last.container.should == @instance.things + @instance.contents.first.parent.should == @instance + @instance.contents.last.parent.should == @instance + @instance.contents.first.owner.should == @instance + @instance.contents.last.owner.should == @instance + @instance.contents.first.visibility_path.should == "#{@instance.id}" + @instance.contents.last.visibility_path.should == "#{@instance.id}" end should "allow for a deep hierarchy" do e = C.new f = C.new @instance.things << e e.things << f - @instance.pieces.length.should == 1 - @instance.pieces.first.should == e + @instance.contents.length.should == 1 + @instance.contents.first.should == e e.owner.id.should == @instance.id e.parent.id.should == @instance.id e.container.should == @instance.things e.visibility_path.should == "#{@instance.id}" @@ -103,22 +114,22 @@ i = C[@instance.id] e = C[e.id] f = C[f.id] - i.pieces.length.should == 1 - i.pieces.first.should == e + i.contents.length.should == 1 + i.contents.first.should == e e.container.should == i.things e.owner.should == i e.parent.should == i f.container.should == e.things f.parent.should == e f.owner.should == e - e.entry.should == i.pieces.first - f.entry.should == e.pieces.first - e.pieces.first.should == f + e.entry.should == i.contents.first + f.entry.should == e.contents.first + e.contents.first.should == f end should "have a list of child nodes" do e = C.new f = C.new @@ -129,14 +140,39 @@ f.save i = C[@instance.id] e = C[e.id] f = C[f.id] - i.pieces.should == [e] - e.pieces.should == [f] + i.contents.should == [e] + e.contents.should == [f] end + should "provide a list of non-page contents" do + p = P.new + + c1 = C.new + c2 = C.new + c3 = C.new + p1 = P.new + p2 = P.new + p3 = P.new + + p.box1 << c1 + p.box1 << c2 + p.box1 << p1 + + p.box2 << p3 + p.box2 << c3 + + [p, c1, c2, c3, p1, p2, p3].each { |c| c.save; c.reload } + + p = P[p.id] + + p.pieces.should == [c1, c2, c3] + end + + should "allow for testing of position" do e = C.new f = C.new g = C.new @instance.things << e @@ -221,12 +257,12 @@ should "recurse" do @b.destroy C.count.should == 2 @a.reload - @a.pieces.length.should == 1 - @a.pieces.first.should == @d.reload + @a.contents.length.should == 1 + @a.contents.first.should == @d.reload C.all.map { |c| c.id }.sort.should == [@a, @d].map { |c| c.id }.sort end should "work through pieces" do @a.things.length.should == 2 @@ -289,9 +325,13 @@ should "re-set the visibility path" do @r.things.adopt(@b) @b.reload @b.visibility_path.should == @r.id.to_s + end + + should "ensure that child pages have their visibility paths updated" do + flunk "Implement this" end end context "identity map" do