Fix broken tests && add more tests

pull/4764/head
Henriette Dinger 8 years ago
parent a5e3f3223d
commit 36a3b722ba
  1. 18
      config/initializers/menus.rb
  2. 2
      features/projects/archive.feature
  3. 5
      lib/redmine/menu_manager/menu_helper.rb
  4. 1
      lib/redmine/menu_manager/top_menu_helper.rb
  5. 65
      spec/features/menu_items/work_packages_menu_item_spec.rb

@ -46,7 +46,8 @@ Redmine::MenuManager.map :top_menu do |menu|
if: Proc.new {
(User.current.logged? || !Setting.login_required?) &&
User.current.allowed_to?(:view_news, nil, global: true)
}
},
omit_path_check: true
menu.push :time_sheet,
{ controller: '/time_entries', project_id: nil, action: 'index' },
context: :modules,
@ -54,14 +55,16 @@ Redmine::MenuManager.map :top_menu do |menu|
if: Proc.new {
(User.current.logged? || !Setting.login_required?) &&
User.current.allowed_to?(:view_time_entries, nil, global: true)
}
},
omit_path_check: true
menu.push :help, OpenProject::Static::Links.help_link,
last: true,
caption: '',
html: { accesskey: OpenProject::AccessKeys.key_for(:help),
title: I18n.t('label_help'),
class: 'icon5 icon-help1',
target: '_blank' }
target: '_blank' },
omit_path_check: true
# work packages menu will be added by
# Redmine::MenuManager::TopMenuHelper#render_work_packages_top_menu_node
@ -132,13 +135,16 @@ Redmine::MenuManager.map :account_menu do |menu|
menu.push :administration,
{ controller: '/admin', action: 'projects' },
html: { class: 'hidden-for-mobile' },
if: Proc.new { User.current.admin? }
if: Proc.new { User.current.admin? },
omit_path_check: true
menu.push :my_account,
{ controller: '/my', action: 'account' },
html: { class: 'hidden-for-mobile' },
if: Proc.new { User.current.logged? }
if: Proc.new { User.current.logged? },
omit_path_check: true
menu.push :logout, :signout_path,
if: Proc.new { User.current.logged? }
if: Proc.new { User.current.logged? },
omit_path_check: true
end
Redmine::MenuManager.map :application_menu do |_menu|

@ -51,7 +51,7 @@ Feature: Navigating to reports page
When I go to the page of the project called "SubProject"
Then I should see "403"
When I go to the projects admin page
When I select "all" from "status"
When I select "All" from "status"
And I click on "Unarchive" within "tbody > tr:nth-of-type(1)"
Then I should be on the projects admin page
And I should see "ParentProject"

@ -79,7 +79,10 @@ module Redmine::MenuManager::MenuHelper
Redmine::MenuManager.loose :project_menu do |menu|
query_menu_items.each do |query_menu_item|
# url = project_work_packages_path(project, query_id: query_menu_item.navigatable_id) does not work because the authorization check fails
url = { controller: '/work_packages', action: 'index', state: nil, params: { query_id: query_menu_item.navigatable_id } }
url = { controller: '/work_packages',
action: 'index',
state: nil,
params: { query_id: query_menu_item.navigatable_id } }
menu.push query_menu_item.unique_name,
url,
param: :project_id,

@ -33,7 +33,6 @@ module Redmine::MenuManager::TopMenuHelper
include Redmine::MenuManager::TopMenu::ProjectsMenu
def render_top_menu_left(project)
items = split_top_menu_into_main_or_more_menus(project)
content_tag :ul, id: 'account-nav-left', class: 'menu_root account-nav hidden-for-mobile' do
[render_main_top_menu_nodes(items[:main]),

@ -31,6 +31,7 @@ require 'spec_helper'
feature 'Work packages top menu items', js: true, selenium: true do
include WorkPackagesFilterHelper
let(:user) { FactoryGirl.create :user }
let(:project) { FactoryGirl.create(:project, is_public: false) }
let(:new_wp_item) { I18n.t('label_work_package_new') }
let(:all_wp_item) { I18n.t('label_all') }
@ -53,20 +54,16 @@ feature 'Work packages top menu items', js: true, selenium: true do
end
end
before do |ex|
before do
allow(User).to receive(:current).and_return user
if ex.metadata.key?(:allowed_to)
allow(user).to receive(:allowed_to?).and_return(ex.metadata[:allowed_to])
end
visit root_path
end
context 'as an admin' do
let(:work_packages) { find(:css, '#work-packages-menu') }
let(:user) { FactoryGirl.create :admin }
before do
visit root_path
work_packages.click
end
@ -114,11 +111,27 @@ feature 'Work packages top menu items', js: true, selenium: true do
click_link watched_wp_item
expect(page).to have_current_path(work_packages_watched_path)
end
it 'visits the projects new work package page' do
visit project_path(project)
work_packages.click
expect(page).to have_content(new_wp_item)
click_link new_wp_item
expect(page).to have_current_path(new_project_work_packages_path(project))
end
end
context 'as a user with permissions', allowed_to: true do
context 'as a user with permissions' do
let(:user) { FactoryGirl.create(:user, member_in_project: project, member_through_role: role) }
let(:role) {
FactoryGirl.create(:role, permissions: [:create_work_packages,
:add_work_packages,
:view_work_packages])
}
let(:work_packages) { find(:css, '#work-packages-menu') }
before do
visit root_path
work_packages.click
end
@ -133,16 +146,48 @@ feature 'Work packages top menu items', js: true, selenium: true do
end
context 'as a user without any permission', allowed_to: false do
before do
visit root_path
end
it 'shows no top menu entry Work packages' do
has_menu_items
expect(page).not_to have_css('#work-packages-menu')
end
end
context 'as an anonymous user' do
let(:user) { FactoryGirl.create :anonymous }
context 'as a user who is logged in but is not allowed to add work packages' do
let(:user) { FactoryGirl.create(:user, member_in_project: project, member_through_role: role) }
let(:role) { FactoryGirl.create(:role, permissions: [:view_work_packages]) }
let(:work_packages) { find(:css, '#work-packages-menu') }
before do
visit root_path
work_packages.click
end
it 'displays no add new work package option' do
has_menu_items(all_wp_item,
assigned_wp_item,
reported_wp_item,
responsible_wp_item,
watched_wp_item)
end
end
context 'as a user who is not logged in' do
let(:user) { FactoryGirl.create(:anonymous) }
let(:role) {
FactoryGirl.create(:anonymous_role,
permissions: [:create_work_packages,
:add_work_packages,
:view_work_packages])
}
let(:work_packages) { find(:css, '#work-packages-menu') }
before do
role
visit root_path
work_packages.click
end

Loading…
Cancel
Save