test/slow/test_visibility.rb in spontaneous-0.1.0.alpha1 vs test/slow/test_visibility.rb in spontaneous-0.2.0.alpha1
- old
+ new
@@ -1,16 +1,23 @@
# encoding: UTF-8
-require 'test_helper'
+require File.expand_path('../../test_helper', __FILE__)
class VisibilityTest < MiniTest::Spec
+
+ def setup
+ @site = setup_site
+ end
+
+ def teardown
+ teardown_site
+ end
+
context "Content" do
setup do
- Spontaneous.database = DB
- Spontaneous::Schema.reset!
Content.delete
class ::R < Page; end
R.box :pages
class ::P < Page; end
P.box :things
@@ -28,17 +35,29 @@
e = P.new(:uid => "#{i}.#{j}.#{k}", :slug => "#{i}-#{j}-#{k}")
d.pages << e
2.times do |l|
e.things << E.new(:uid => "#{i}.#{j}.#{k}.#{l}")
end
- d.save
+ e.save
end
+ # puts "-->"
+ # puts d.id
+ # p [:things, d.class, d.pages.schema_id.to_s, P.boxes.things.schema_id.to_s]
+ # p c.unordered_children.map { |p| [p.parent_id, p.box_sid.to_s, p.uid] }
+ # p c.children.map { |p| p.box_sid.to_s }
+ # puts "--<"
+ # c.save
+ # d.save
end
- c.save
end
@root.save
@root.reload
+ # puts "-->"
+ # p [:things, @root.pages.first.class, @root.pages.first.things.schema_id.to_s, P.boxes.things.schema_id.to_s]
+ # p @root.pages.first.unordered_children.map { |p| [p.box_sid.to_s, p.uid] }
+ # p @root.pages.first.children.map { |p| p.box_sid.to_s }
+ # puts "--<"
@child = Page.uid("0")
end
teardown do
[:R, :P, :E].each do |k|
@@ -105,12 +124,12 @@
end
end
should "hide all descendents of page content" do
piece = Content.first(:uid => "0.0")
- f = Piece.new(:uid => "0.0.X")
- piece << f
+ f = E.new(:uid => "0.0.X")
+ piece.pages << f
piece.save
piece.reload
piece.hide!
Content.all.each do |c|
@@ -161,12 +180,14 @@
should "not reveal child content that was hidden before its parent" do
piece1 = Content.first(:uid => "0.0.0.0")
piece2 = Content.first(:uid => "0.0.0.1")
parent = Content.first(:uid => "0.0.0")
- piece1.container.should == parent
- piece2.container.should == parent
+ piece1.owner.should == parent
+ piece2.owner.should == parent
+ piece1.container.should == parent.things
+ piece2.container.should == parent.things
piece1.hide!
parent.hide!
parent.reload.visible?.should be_false
piece1.reload.visible?.should be_false
piece2.reload.visible?.should be_false
@@ -185,10 +206,16 @@
lambda { @root.hide! }.must_raise(RuntimeError)
@root.visible?.should be_true
end
end
+ context "top-level searches" do
+ should "return a list of visible pages" do
+ @root.pages.first.hide!
+ P.visible.count.should == 9
+ end
+ end
context "visibility scoping" do
setup do
# S.database.logger = ::Logger.new($stdout)
end
@@ -212,10 +239,12 @@
end
should "only show visibile pieces" do
page = Content.first(:uid => "1")
page.pieces.length.should == 4
+ page.things.pieces.length.should == 4
+ page.things.count.should == 4
page.pieces.first.hide!
page.reload
Content.with_visible do
page.pieces.length.should == 3
page.pieces.first.id.should_not == page.id
@@ -226,25 +255,29 @@
should "stop modification of pieces" do
page = Content.first(:uid => "1")
Content.with_visible do
# would like to make sure we're raising a predictable error
# but 1.9 changes the typeerror to a runtime error
- lambda { page.pieces << Piece.new }.must_raise(TypeError, RuntimeError)
- lambda { page << Piece.new }.must_raise(TypeError, RuntimeError)
+ lambda { page.things << Piece.new }.must_raise(TypeError, RuntimeError)
end
end
should "ensure that no hidden content can be returned" do
@root.reload
@root.children.first.children.length.should == 8
@root.children.first.pieces.first.hide!
- # p @root.children.first.children.map { |c| c.visible? }
@root.reload
Content.with_visible do
@root.children.first.children.length.should == 6
end
- # p @root.children.map { |c| c.uid }
- # p @root.children.first.children.length
+ end
+
+ should "hide pages without error" do
+ @root.pages.first.hide!
+ @root.reload
+ Content.with_visible do
+ pieces = @root.pages.pieces.map { |p| p }
+ end
end
end
end
end