require 'rails_helper'
describe Cms::ApplicationHelper, :type => :helper do
before(:each) do
helper.output_buffer = ''
end
describe '#sp_list_menu' do
it "should be able to find a menu by its name" do
menu = FactoryGirl.create(:spud_menu, :name => "Main")
2.times { |x| FactoryGirl.create(:spud_menu_item, :parent_id => menu.id, :spud_menu_id => menu.id, :url => "/") }
helper.sp_list_menu(:name => "Main", :active_class => "active")
expect(helper.output_buffer).to match /\
menu.id,:spud_menu_id => menu.id,:url => "/")}
helper.sp_list_menu(:name => menu.name,:id => "nav")
expect(helper.output_buffer).to match /id=\'nav\'/
end
it "should render nested menu items" do
menu = FactoryGirl.create(:spud_menu,:name => "Main2")
s = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")
s2 = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")
s3 = FactoryGirl.create(:spud_menu_item,:parent_type => "SpudMenuItem",:parent_id => s.id,:spud_menu_id => menu.id,:url => "/",:name => "SubItem")
helper.sp_list_menu(:name => "Main2")
expect(helper.output_buffer).to match /SubItem/
end
it "should respect max depth" do
menu = FactoryGirl.create(:spud_menu,:name => "Main4")
s = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")
s2 = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")
s3 = FactoryGirl.create(:spud_menu_item,:parent_type => "SpudMenuItem",:parent_id => s.id,:spud_menu_id => menu.id,:url => "/",:name => "SubItem")
helper.sp_list_menu(:name => "Main4",:max_depth => 1)
expect(helper.output_buffer).to_not match /SubItem/
end
end
describe '#sp_menu_with_seperator' do
it "should render a flattened list of links" do
menu = FactoryGirl.create(:spud_menu,:name => "Main3")
s = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")
s2 = FactoryGirl.create(:spud_menu_item,:parent_id => menu.id,:spud_menu_id => menu.id,:url => "/")
s3 = FactoryGirl.create(:spud_menu_item,:parent_type => "SpudMenuItem",:parent_id => s.id,:spud_menu_id => menu.id,:url => "/",:name => "SubItem")
content = helper.sp_menu_with_seperator(:name => "Main3")
expect(content).to match /SubItem/
expect(content).to_not match /\ page.id)
content = helper.sp_list_pages(:active_class => "active")
expect(content).to match /#{page.name}/
expect(content).to match /#{page2.name}/
expect(content).to match /#{page3.name}/
end
it "should assign id" do
page = FactoryGirl.create(:spud_page)
page2 = FactoryGirl.create(:spud_page)
content = helper.sp_list_pages(:id => "page_nav")
expect(content).to match /id=\'page_nav\'/
end
it "should be able to exclude certain pages" do
page = FactoryGirl.create(:spud_page)
page2 = FactoryGirl.create(:spud_page)
content = helper.sp_list_pages(:exclude => [page2.name])
expect(content).to match /#{page.name}/
expect(content).to_not match /#{page2.name}/
end
it "should respect max depth" do
page = FactoryGirl.create(:spud_page)
page2 = FactoryGirl.create(:spud_page)
page3 = FactoryGirl.create(:spud_page,:spud_page_id => page.id)
content = helper.sp_list_pages(:max_depth => 1)
expect(content).to match /#{page.name}/
expect(content).to match /#{page2.name}/
expect(content).to_not match /#{page3.name}/
end
it "should be able to list sub pages of a particular page" do
page = FactoryGirl.create(:spud_page)
page2 = FactoryGirl.create(:spud_page)
page3 = FactoryGirl.create(:spud_page,:spud_page_id => page.id)
content = helper.sp_list_pages(:start_page_id => page.id)
expect(content).to_not match /#{page.name}/
expect(content).to_not match /#{page2.name}/
expect(content).to match /#{page3.name}/
end
end
end