OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/spec/controllers/wiki_menu_items_controller_...

134 lines
5.7 KiB

#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe WikiMenuItemsController do
let(:current_user) { FactoryGirl.create(:admin) }
# create project with wiki
let(:project) { FactoryGirl.create(:project).reload } # a wiki is created for project, but the object doesn't know of it (FIXME?)
let(:wiki) { project.wiki }
let(:wiki_page) { FactoryGirl.create(:wiki_page, :wiki => wiki) } # first wiki page without child pages
let!(:top_level_wiki_menu_item) { FactoryGirl.create(:wiki_menu_item, :wiki => wiki, :title => wiki_page.title) }
before :each do
# log in user
User.stub(:current).and_return current_user
end
describe :edit do
# more wiki pages with menu items
let(:another_wiki_page) { FactoryGirl.create(:wiki_page, :wiki => wiki) } # second wiki page with two child pages
let!(:another_wiki_page_top_level_wiki_menu_item) { FactoryGirl.create(:wiki_menu_item, :wiki => wiki, :title => another_wiki_page.title) }
# child pages of another_wiki_page
let(:child_page) { FactoryGirl.create(:wiki_page, :parent => another_wiki_page, :wiki => wiki) }
let!(:child_page_wiki_menu_item) { FactoryGirl.create(:wiki_menu_item, :wiki => wiki, :title => child_page.title) }
let(:another_child_page) { FactoryGirl.create(:wiki_page, :parent => another_wiki_page, :wiki => wiki) }
let!(:another_child_page_wiki_menu_item) { FactoryGirl.create(:wiki_menu_item, :wiki => wiki, :title => another_child_page.title, :parent => top_level_wiki_menu_item) }
let(:grand_child_page) { FactoryGirl.create(:wiki_page, :parent => child_page, :wiki => wiki) }
let!(:grand_child_page_wiki_menu_item) { FactoryGirl.create(:wiki_menu_item, :wiki => wiki, :title => grand_child_page.title) }
context 'when no parent wiki menu item has been configured yet' do
context 'and it is a child page' do
before { get :edit, project_id: project.id, id: child_page.title }
subject { response }
it 'preselects the wiki menu item of the parent page as parent wiki menu item option' do
assigns['selected_parent_menu_item_id'].should == another_wiki_page_top_level_wiki_menu_item.id
# see FIXME in menu_helper.rb
end
end
context 'and it is a grand child page the parent of which is not a main item' do
before do
# ensure the parent page of grand_child_page is not a main item
child_page_wiki_menu_item.tap {|page| page.parent = top_level_wiki_menu_item}.save
get :edit, project_id: project.id, id: grand_child_page.title
end
subject { response }
it 'preselects the wiki menu item of the grand parent page as parent wiki menu item option' do
assigns['selected_parent_menu_item_id'].should == another_wiki_page_top_level_wiki_menu_item.id
end
end
end
context 'when a parent wiki menu item has already been configured' do
before { get :edit, project_id: project.id, id: another_child_page.title }
subject { response }
it 'preselects the parent wiki menu item that is already assigned' do
assigns['selected_parent_menu_item_id'].should == top_level_wiki_menu_item.id
end
end
end
shared_context 'there is one more wiki page with a child page' do
let!(:another_wiki_page) { FactoryGirl.create(:wiki_page, :wiki => wiki) } # second wiki page with two child pages
let!(:child_page) { FactoryGirl.create(:wiki_page, :parent => another_wiki_page, :wiki => wiki) }
end
describe :select_main_menu_item do
include_context 'there is one more wiki page with a child page'
before { get :select_main_menu_item, project_id: project, id: wiki_page.title }
subject { assigns['possible_wiki_pages'] }
context 'when selecting a new wiki page to replace the current main menu item' do
it { should include another_wiki_page }
it { should include child_page }
it { should_not include wiki_page }
end
end
describe :replace_main_menu_item do
include_context 'there is one more wiki page with a child page'
let(:selected_page) { child_page }
before do
post :replace_main_menu_item, project_id: project,
id: wiki_page.id,
wiki_page: { id: selected_page.id }
end
it 'destroys the current wiki menu item' do
wiki_page.menu_item.should be_nil
end
it 'creates a new main menu item for the selected wiki page' do
selected_page.menu_item.should be_present
selected_page.menu_item.parent.should be_nil
end
end
end