2011-07-26 01:02:13 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2011-11-26 05:33:57 +00:00
|
|
|
describe Locomotive::MainMenuCell do
|
2011-07-26 01:02:13 +00:00
|
|
|
|
2011-11-26 06:24:34 +00:00
|
|
|
let(:menu) { render_cell('locomotive/main_menu', :show) }
|
2011-07-26 01:02:13 +00:00
|
|
|
|
|
|
|
describe 'show menu' do
|
|
|
|
|
2012-02-16 00:32:37 +00:00
|
|
|
before(:all) { reset_cell }
|
2011-07-26 01:02:13 +00:00
|
|
|
|
2012-02-16 00:32:37 +00:00
|
|
|
it 'has 3 items' do
|
|
|
|
menu.should have_selector('li.entry', :count => 3)
|
2011-07-26 01:02:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a link to go to the contents' do
|
|
|
|
menu.should have_link('Contents')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a link to go the settings' do
|
|
|
|
menu.should have_link('Settings')
|
|
|
|
end
|
|
|
|
|
2012-02-16 00:32:37 +00:00
|
|
|
it 'has a link to go the foo tab' do
|
|
|
|
menu.should have_link('My FOO menu')
|
|
|
|
end
|
|
|
|
|
2011-07-26 01:02:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'add a new menu item' do
|
|
|
|
|
2012-02-16 00:32:37 +00:00
|
|
|
before(:all) do
|
|
|
|
reset_cell(:main => 'settings', :sub => 'site')
|
2011-11-26 06:24:34 +00:00
|
|
|
Locomotive::MainMenuCell.update_for(:testing_add) { |m| m.add(:my_link, :label => 'Shop', :url => 'http://www.locomotivecms.com') }
|
2011-07-26 01:02:13 +00:00
|
|
|
end
|
|
|
|
|
2012-02-16 00:32:37 +00:00
|
|
|
it 'has 4 items now' do
|
|
|
|
menu.should have_selector('li.entry', :count => 4)
|
2011-07-26 01:02:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a new link' do
|
|
|
|
menu.should have_link('Shop')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'remove a new menu item' do
|
|
|
|
|
2012-02-16 00:32:37 +00:00
|
|
|
before(:all) do
|
|
|
|
reset_cell(:main => 'settings', :sub => 'site')
|
2011-11-26 06:24:34 +00:00
|
|
|
Locomotive::MainMenuCell.update_for(:testing_remove) { |m| m.remove(:settings) }
|
2011-07-26 01:02:13 +00:00
|
|
|
end
|
|
|
|
|
2012-02-16 00:32:37 +00:00
|
|
|
it 'has only 2 items' do
|
|
|
|
menu.should have_selector('li.entry', :count => 2)
|
2011-07-26 01:02:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not have the link to go to the settings' do
|
|
|
|
menu.should_not have_link('Settings')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'modify an existing menu item' do
|
|
|
|
|
2012-02-16 00:32:37 +00:00
|
|
|
before(:all) do
|
|
|
|
reset_cell(:main => 'settings', :sub => 'site')
|
2011-11-26 06:24:34 +00:00
|
|
|
Locomotive::MainMenuCell.update_for(:testing_update) { |m| m.modify(:settings, { :label => 'Modified !' }) }
|
2011-07-26 01:02:13 +00:00
|
|
|
end
|
|
|
|
|
2012-02-16 00:32:37 +00:00
|
|
|
it 'still has 3 items' do
|
|
|
|
menu.should have_selector('li.entry', :count => 3)
|
2011-07-26 01:02:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a modified menu item' do
|
|
|
|
menu.should_not have_link('Settings')
|
|
|
|
menu.should have_link('Modified !')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2011-08-13 23:24:02 +00:00
|
|
|
after(:all) do
|
2012-02-16 00:32:37 +00:00
|
|
|
reset_cell
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_cell(attributes = {})
|
|
|
|
::Locomotive.send(:remove_const, 'MainMenuCell')
|
|
|
|
|
|
|
|
cell_path = File.join(File.dirname(__FILE__), '../../../app/cells/locomotive/main_menu_cell.rb')
|
|
|
|
load cell_path
|
|
|
|
|
|
|
|
cell_path = File.join(File.dirname(__FILE__), '../../dummy/app/cells/locomotive/main_menu_cell.rb')
|
|
|
|
load cell_path
|
|
|
|
|
|
|
|
unless attributes.empty?
|
|
|
|
Locomotive::MainMenuCell.any_instance.stubs(:sections).returns(attributes)
|
|
|
|
end
|
2011-08-13 23:24:02 +00:00
|
|
|
end
|
|
|
|
|
2011-11-26 05:33:57 +00:00
|
|
|
end
|