test/unit/test_alias.rb in spontaneous-0.2.0.alpha7 vs test/unit/test_alias.rb in spontaneous-0.2.0.beta1

- old
+ new

@@ -3,17 +3,17 @@ require File.expand_path('../../test_helper', __FILE__) class AliasTest < MiniTest::Spec def assert_same_content(c1, c2) - assert_equal c1.length, c2.length + assert_equal c2.length, c1.length c1 = c1.dup.sort { |a, b| a.id <=> b.id } c2 = c2.dup.sort { |a, b| a.id <=> b.id } c1.each_with_index do |a, i| b = c2[i] - assert_equal a.id, b.id - assert_equal a.class, b.class + assert_equal b.id, a.id + assert_equal b.class, a.class end end context "Aliases:" do setup do @@ -23,17 +23,17 @@ @renderer = S::Output::Template::Renderer.new(false) S::Output.renderer = @renderer Content.delete - class ::Page < Spontaneous::Page - field :title - box :box1 - box :box2 - end + Page.field :title + Page.box :box1 + Page.box :box2 + # class ::Page < Spontaneous::Page + # end - class ::Piece < Spontaneous::Piece; end + # class ::Piece < Spontaneous::Piece; end class ::A < ::Piece field :a_field1 field :a_field2 field :image, :image @@ -96,11 +96,11 @@ class ::MultipleAlias < ::Piece alias_of :AA, :B end class ::ProcAlias < ::Piece - alias_of proc { Spontaneous::Site.root.children } + alias_of proc { Content.root.children } end @root = ::Page.create @aliases = ::Page.create(:slug => "aliases").reload @root.box1 << @aliases @@ -114,15 +114,15 @@ @root.box1 << @bb @root.save.reload end teardown do - [:Page, :Piece, :A, :AA, :AAA, :B, :BB, :AAlias, :AAAlias, :AAAAlias, :BBAlias, :BAlias, :MultipleAlias, :ProcAlias].each do |c| + [:A, :AA, :AAA, :B, :BB, :AAlias, :AAAlias, :AAAAlias, :BBAlias, :BAlias, :MultipleAlias, :ProcAlias].each do |c| Object.send(:remove_const, c) rescue nil end Content.delete - FileUtils.rm_r(@site.root) + teardown_site end context "All alias" do context "class methods" do should "provide a list of available instances that includes all subclasses" do @@ -157,11 +157,11 @@ @page.box1 << A.new @page.box1 << AA.new @page.box2 << A.new @page.box2 << AA.new } - @page.save.reload + @page = @page.save.reload end teardown do Object.send(:remove_const, 'X') rescue nil Object.send(:remove_const, 'XX') rescue nil @@ -173,12 +173,17 @@ alias_of :A, :container => Proc.new { S::Site['#thepage'].box1 } end class ::XX < ::Piece alias_of :AA, :container => Proc.new { S::Site['#thepage'].box1 } end - Set.new(X.targets).should == Set.new(@page.box1.select { |p| A === p }) - Set.new(XX.targets).should == Set.new(@page.box1.select { |p| AA === p }) + targets = lambda { |a, target| + [(a.targets), @page.box1.select { |p| target === p }].map { |a| Set.new(a) } + } + expected, actual = targets.call(X, A) + actual.should == expected + expected, actual = targets.call(XX, AA) + actual.should == expected end should "allow for selecting only content from a range of boxes" do class ::X < ::Piece alias_of :A, :container => Proc.new { [S::Site['#thepage'].box1, S::Site['#thepage'].box2] } @@ -320,9 +325,10 @@ # should "have an independent style setting" should "not delete their target when deleted" do @a_alias.destroy Content[@a.id].should == @a end + should "be deleted when target deleted" do @a.destroy Content[@a_alias.id].should be_nil end