spec/helpers/admin/node_helper_spec.rb in radiant-0.9.1 vs spec/helpers/admin/node_helper_spec.rb in radiant-1.0.0.rc1
- old
+ new
@@ -1,19 +1,24 @@
require File.dirname(__FILE__) + "/../../spec_helper"
describe Admin::NodeHelper do
+ dataset :users_and_pages
before :each do
- @controller = mock("controller")
@cookies = {}
+ @errors = mock("errors")
helper.stub!(:cookies).and_return(@cookies)
helper.stub!(:homepage).and_return(nil)
@page = mock_model(Page)
+ @page.stub!(:sheet?).and_return(false) # core extension alters the behavior
+ helper.stub!(:image).and_return('')
+ helper.stub!(:admin?).and_return(true)
+ helper.instance_variable_set(:@page, @page)
end
it "should render a sitemap node" do
- helper.should_receive(:render).with(:partial => "node", :locals => {:level => 0, :simple => false, :page => @page}).and_return(@current_node)
+ helper.should_receive(:render).with(:partial => "admin/pages/node", :locals => {:level => 0, :simple => false, :page => @page}).and_return(@current_node)
helper.render_node(@page)
helper.assigns[:current_node] == @page
end
it "should show all nodes when on the remove action" do
@@ -99,7 +104,57 @@
:class => 'busy', :id => "busy_1",
:alt => "", :title => "",
:style => 'display: none;')
helper.spinner
end
+
+ describe "#child_link_for" do
+ it "should disable the menu when there are no allowable children" do
+ @page.stub!(:allowed_children).and_return([])
+ helper.child_link_for(@page).should match('<span class="action disabled">')
+ end
+
+ it "should link to Page#new when there is one allowable child" do
+ @page.stub!(:allowed_children).and_return([Page])
+ helper.child_link_for(@page).should match(Regexp.escape(new_admin_page_child_path(@page, :page_class => 'Page')))
+ end
+
+ it "should show the menu when there are multiple allowable children" do
+ @page.stub!(:allowed_children).and_return([Page,FileNotFoundPage])
+ helper.child_link_for(@page).should match("#allowed_children_#{@page.id}")
+ end
+ end
+
+ describe "#children_for" do
+ it "should not show virtual pages to designers" do
+ helper.stub!(:admin?).and_return(false)
+ @page.stub!(:allowed_children).and_return([Page, ArchivePage, FileNotFoundPage])
+ helper.children_for(@page).flatten.should_not include(FileNotFoundPage)
+ end
+ end
+
+ describe '#clean_page_description' do
+ it "should remove all whitespace (except single spaces) from the given page's description" do
+ @page.stub!(:description).and_return(%{
+ This is the description for the
+ current page!
+ })
+ helper.clean_page_description(@page).should == 'This is the description for the current page!'
+ end
+ end
+
+ describe '#child_menu_for' do
+ it "should be empty if there are no options" do
+ helper.stub!(:children_for).and_return([])
+ helper.child_menu_for(@page).should be_nil
+ end
+
+ it "should list options if there are any" do
+ helper.stub!(:children_for).and_return([Page, FileNotFoundPage])
+ @page.stub!(:default_child).and_return(Page)
+ menu = helper.child_menu_for(@page)
+ menu.should match(/Normal Page/)
+ end
+ end
+
end
\ No newline at end of file