test/unit/test_page.rb in spontaneous-0.2.0.beta9 vs test/unit/test_page.rb in spontaneous-0.2.0.beta10
- old
+ new
@@ -140,10 +140,23 @@
p.slug.wont_equal ""
p.save
p.reload.slug.wont_equal ""
end
+ it 'can be given a type specific root' do
+ class Page
+ def default_slug_root
+ 'fishies'
+ end
+ end
+ o = Page.create
+ p = Page.create
+ p.save
+ p.slug.must_match /^fishies/
+ p.has_generated_slug?.must_equal true
+ end
+
it "be made URL safe" do
o = Page.create
p = Page.create
p.slug = " something's illegal and ugly!!"
p.slug.must_equal "somethings-illegal-and-ugly"
@@ -474,9 +487,43 @@
it "provide a list of pages at any depth" do
@t.at_depth(2).must_equal [@r, @s]
@p.at_depth(1).must_equal [@q]
lambda { @p.at_depth(2) }.must_raise(ArgumentError)
+ end
+
+ describe 'custom path roots' do
+ before do
+ Page.box :custom do
+ def path_origin
+ root
+ end
+ end
+ Page.box :custom_string do
+ def path_origin
+ "/"
+ end
+ end
+ Page.box :sections
+ @parent = @p
+ @child = Page.create(slug: 'child')
+ @parent.sections << @child
+ @child.path.must_equal '/child'
+ end
+
+ it "defines child paths according to the custom path root" do
+ page = Page.create(slug: 'balloon')
+ @child.custom << page
+ page.save.reload
+ page.path.must_equal '/balloon'
+ end
+
+ it "allows for string based path origins" do
+ page = Page.create(slug: 'balloon')
+ @child.custom_string << page
+ page.save.reload
+ page.path.must_equal '/balloon'
+ end
end
end
describe "page pieces" do
before do