Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

replace legacy spec

ulfertsc9c31a8d41ed
diff --git a/spec/controllers/wiki_controller_spec.rb b/spec/controllers/wiki_controller_spec.rb
index 0bfbf044620..a161d338370 100644
--- a/spec/controllers/wiki_controller_spec.rb
+++ b/spec/controllers/wiki_controller_spec.rb
@@ -34,6 +34,7 @@ describe WikiController, type: :controller do
shared_let(:project) do
create(:project).tap(&:reload)
end
+ shared_let(:wiki) { project.wiki }
shared_let(:existing_page) do
create(:wiki_page, wiki_id: project.wiki.id, title: 'ExistingPage')
@@ -47,7 +48,29 @@ describe WikiController, type: :controller do
describe 'actions' do
before do
allow(controller).to receive(:set_localization)
- login_as admin
+ end
+
+ current_user { admin }
+
+ describe 'index' do
+ before do
+ get :index, params: { project_id: project.identifier }
+ end
+
+ it 'is successful' do
+ expect(response)
+ .to have_http_status(:ok)
+ end
+
+ it 'renders the index template' do
+ expect(response)
+ .to render_template(:index)
+ end
+
+ it 'assigns pages' do
+ expect(assigns[:pages])
+ .to eq project.wiki.pages
+ end
end
shared_examples_for "a 'new' action" do
@@ -251,11 +274,109 @@ describe WikiController, type: :controller do
end
describe 'edit' do
- it 'will link to a parent page if it was set' do
- get 'edit', params: { project_id: project, id: 'foobar' }, flash: { _related_wiki_page_id: 1234 }
+ let(:permissions) { %i[view_wiki_pages edit_wiki_pages] }
+
+ let(:params) do
+ { project_id: project, id: existing_page.title }
+ end
+ let(:flash) do
+ {}
+ end
+
+ current_user { create(:user, member_in_project: project, member_with_permissions: permissions) }
+
+ before do
+ get :edit, params:, flash:
+ end
+
+ context 'with an existing wiki page' do
+ let(:params) do
+ { project_id: project, id: existing_page.title }
+ end
+
+ it 'is sucessful' do
+ expect(response)
+ .to have_http_status(:ok)
+ end
+
+ it 'renders the edit template' do
+ expect(response)
+ .to render_template :edit
+ end
+
+ it 'assigns the page' do
+ expect(assigns[:page])
+ .to eq existing_page
+
+ expect(assigns[:page])
+ .not_to be_changed
+ end
+ end
+
+ context 'with an existing wiki page that is protected' do
+ let(:params) do
+ existing_page.update_column(:protected, true)
+ { project_id: project, id: existing_page.title }
+ end
+
+ it 'is forbiddend' do
+ expect(response)
+ .to have_http_status(:forbidden)
+ end
+ end
+
+ context 'with an existing wiki page that is protected and having the necessary permission' do
+ let(:permissions) do
+ existing_page.update_column(:protected, true)
+
+ %i[view_wiki_pages edit_wiki_pages protect_wiki_pages]
+ end
+
+ it 'is sucessful' do
+ expect(response)
+ .to have_http_status(:ok)
+ end
- page = assigns[:page]
- expect(page.parent_id).to eq 1234
+ it 'renders the edit template' do
+ expect(response)
+ .to render_template :edit
+ end
+
+ it 'assigns the page' do
+ expect(assigns[:page])
+ .to eq existing_page
+
+ expect(assigns[:page])
+ .not_to be_changed
+ end
+ end
+
+ context 'with a related wiki page in the flash and a non existing wiki page' do
+ let(:flash) { { _related_wiki_page_id: 1234 } }
+ let(:params) do
+ { project_id: project, id: 'foobar' }
+ end
+
+ it 'is sucessful' do
+ expect(response)
+ .to have_http_status(:ok)
+ end
+
+ it 'renders the edit template' do
+ expect(response)
+ .to render_template :edit
+ end
+
+ it 'assigns @page to a new wiki page with the parent id set' do
+ expect(assigns[:page])
+ .to be_a WikiPage
+
+ expect(assigns[:page])
+ .to be_new_record
+
+ expect(assigns[:page].parent_id)
+ .to eql flash[:_related_wiki_page_id]
+ end
end
end
@@ -363,26 +484,521 @@ describe WikiController, type: :controller do
end
describe 'destroy' do
- describe 'successful action' do
- context 'when it is not the only wiki page' do
- let(:wiki) { project.wiki }
- let(:redirect_page_after_destroy) { wiki.find_page(wiki.start_page) || wiki.pages.first }
+ shared_let(:parent_page) { create(:wiki_page, wiki:) }
+ shared_let(:child_page) { create(:wiki_page, wiki:, parent: parent_page) }
- before do
- create :wiki_page, wiki:
- end
+ let(:redirect_page_after_destroy) { wiki.find_page(wiki.start_page) || wiki.pages.first }
- it 'redirects to wiki#index' do
- delete :destroy, params: { project_id: project, id: existing_page }
- expect(response).to redirect_to action: 'index', project_id: project, id: redirect_page_after_destroy
- end
+ let(:params) do
+ { project_id: project, id: existing_page }
+ end
+
+ subject do
+ delete :destroy, params: params
+
+ response
+ end
+
+ context 'when it is not the only wiki page' do
+ it 'redirects to wiki#index' do
+ expect(subject)
+ .to redirect_to action: 'index', project_id: project, id: redirect_page_after_destroy
end
- context 'when it is the only wiki page' do
- it 'redirects to projects#show' do
- delete :destroy, params: { project_id: project, id: existing_page }
- expect(response).to redirect_to project_path(project)
- end
+ it 'destroys the page' do
+ expect { subject }
+ .to change { WikiPage.where(id: existing_page.id).count }
+ .from(1)
+ .to(0)
+ end
+ end
+
+ context 'when it is the only wiki page' do
+ before do
+ WikiPage.where.not(id: existing_page.id).destroy_all
+ end
+
+ it 'redirects to projects#show' do
+ expect(subject)
+ .to redirect_to project_path(project)
+ end
+
+ it 'destroys the page' do
+ expect { subject }
+ .to change { WikiPage.where(id: existing_page.id).count }
+ .from(1)
+ .to(0)
+ end
+ end
+
+ context 'when destroying a child' do
+ let(:params) do
+ { project_id: project, id: child_page }
+ end
+
+ it 'redirects to wiki#index' do
+ expect(subject)
+ .to redirect_to action: 'index', project_id: project, id: redirect_page_after_destroy
+ end
+
+ it 'destroys the page' do
+ expect { subject }
+ .to change { WikiPage.where(id: child_page.id).count }
+ .from(1)
+ .to(0)
+ end
+ end
+
+ context 'when destroying a parent without specifying todo' do
+ let(:params) do
+ { project_id: project, id: parent_page }
+ end
+
+ it 'responds with success' do
+ expect(subject)
+ .to have_http_status(:ok)
+ end
+
+ it 'destroys the page' do
+ expect { subject }
+ .not_to change(WikiPage, :count)
+ end
+ end
+
+ context 'when destroying a parent with nullify' do
+ let(:params) do
+ { project_id: project, id: parent_page, todo: 'nullify' }
+ end
+
+ it 'redirects to wiki#index' do
+ expect(subject)
+ .to redirect_to action: 'index', project_id: project, id: redirect_page_after_destroy
+ end
+
+ it 'destroys the page' do
+ expect { subject }
+ .to change { WikiPage.where(id: parent_page.id).count }
+ .from(1)
+ .to(0)
+ end
+
+ it 'sets the parent_id of the child to nil' do
+ subject
+
+ expect(child_page.parent_id)
+ .to be_nil
+ end
+ end
+
+ context 'when destroying a parent with todo = destroy' do
+ let(:params) do
+ { project_id: project, id: parent_page, todo: 'destroy' }
+ end
+
+ it 'redirects to wiki#index' do
+ expect(subject)
+ .to redirect_to action: 'index', project_id: project, id: redirect_page_after_destroy
+ end
+
+ it 'destroys the page' do
+ expect { subject }
+ .to change { WikiPage.where(id: [parent_page, child_page]).count }
+ .from(2)
+ .to(0)
+ end
+ end
+
+ context 'when destroying a parent with reassign' do
+ let(:params) do
+ { project_id: project, id: parent_page, todo: 'reassign', reassign_to_id: existing_page.id }
+ end
+
+ it 'redirects to wiki#index' do
+ expect(subject)
+ .to redirect_to action: 'index', project_id: project, id: redirect_page_after_destroy
+ end
+
+ it 'destroys the page' do
+ expect { subject }
+ .to change { WikiPage.where(id: parent_page).count }
+ .from(1)
+ .to(0)
+ end
+
+ it 'sets the parent_id of the child to the specified page' do
+ subject
+
+ expect(child_page.parent_id)
+ .to eq existing_page.id
+ end
+ end
+ end
+
+ describe 'rename' do
+ shared_let(:parent_page) { create(:wiki_page, wiki:) }
+ shared_let(:child_page) { create(:wiki_page, wiki:, parent: parent_page) }
+
+ let(:permissions) { %i[view_wiki_pages rename_wiki_pages edit_wiki_pages] }
+
+ let(:params) do
+ { project_id: project, id: existing_page.title }
+ end
+
+ let(:request) do
+ get :rename, params:
+ end
+
+ current_user { create(:user, member_in_project: project, member_with_permissions: permissions) }
+
+ subject do
+ request
+
+ response
+ end
+
+ context 'when getting for a page' do
+ it 'is success' do
+ expect(subject)
+ .to have_http_status(:ok)
+ end
+
+ it 'renders the template' do
+ expect(subject)
+ .to render_template :rename
+ end
+ end
+
+ context 'when getting for a child page' do
+ let(:params) do
+ { project_id: project, id: child_page.title }
+ end
+
+ it 'is success' do
+ expect(subject)
+ .to have_http_status(:ok)
+ end
+
+ it 'renders the template' do
+ expect(subject)
+ .to render_template :rename
+ end
+ end
+
+ context 'when getting for a page without permissions' do
+ let(:permissions) { %i[view_wiki_pages] }
+
+ it 'is forbidden' do
+ expect(subject)
+ .to have_http_status(:forbidden)
+ end
+ end
+
+ context 'when patching with redirect' do
+ let(:new_title) { 'The new page title' }
+ let!(:old_title) { existing_page.title }
+
+ let(:params) do
+ {
+ project_id: project,
+ id: existing_page.title,
+ page: {
+ title: new_title,
+ redirect_existing_links: 1
+ }
+ }
+ end
+
+ let(:request) do
+ patch :rename, params:
+ end
+
+ it 'redirects to the show page with the altered name' do
+ expect(subject)
+ .to redirect_to action: 'show', project_id: project.identifier, id: 'the-new-page-title'
+ end
+
+ it 'renames the page' do
+ subject
+
+ expect(existing_page.reload.title)
+ .to eql new_title
+ end
+
+ it 'finds the page by the old name' do
+ subject
+
+ expect(wiki.find_page(old_title))
+ .to eql existing_page
+ end
+ end
+
+ context 'when patching without redirect' do
+ let(:new_title) { 'The new page title' }
+ let!(:old_title) { existing_page.title }
+
+ let(:params) do
+ {
+ project_id: project,
+ id: existing_page.title,
+ page: {
+ title: new_title,
+ redirect_existing_links: '0'
+ }
+ }
+ end
+
+ let(:request) do
+ patch :rename, params:
+ end
+
+ it 'redirects to the show page with the altered name' do
+ expect(subject)
+ .to redirect_to action: 'show', project_id: project.identifier, id: 'the-new-page-title'
+ end
+
+ it 'renames the page' do
+ subject
+
+ expect(existing_page.reload.title)
+ .to eql new_title
+ end
+
+ it 'does not find the page by the old name' do
+ subject
+
+ expect(wiki.find_page(old_title))
+ .to be_nil
+ end
+ end
+ end
+
+ describe 'diffs' do
+ let!(:journal_from) { existing_content.journals.last }
+ let!(:journal_to) do
+ existing_content.text = 'new_text'
+ existing_content.save
+
+ existing_content.journals.reload.last
+ end
+
+ let(:permissions) { %i[view_wiki_pages view_wiki_edits] }
+
+ let(:params) do
+ {
+ project_id: project,
+ id: existing_page.title,
+ version: journal_to.version,
+ version_from: journal_from.version
+ }
+ end
+
+ let(:request) do
+ get :diff, params:
+ end
+
+ current_user { create(:user, member_in_project: project, member_with_permissions: permissions) }
+
+ subject do
+ request
+
+ response
+ end
+
+ it 'is success' do
+ expect(subject)
+ .to have_http_status(:ok)
+ end
+
+ it 'renders the template' do
+ expect(subject)
+ .to render_template :diff
+ end
+
+ it 'assigns html_diff' do
+ subject
+
+ expect(assigns[:html_diff])
+ .to be_a(String)
+ end
+ end
+
+ describe 'annotates' do
+ let!(:journal_from) { existing_content.journals.last }
+ let!(:journal_to) do
+ existing_content.text = 'new_text'
+ existing_content.save
+
+ existing_content.journals.reload.last
+ end
+
+ let(:permissions) { %i[view_wiki_pages view_wiki_edits] }
+
+ let(:params) do
+ { project_id: project, id: existing_page.title, version: journal_to.version }
+ end
+
+ let(:request) do
+ get :annotate, params:
+ end
+
+ current_user { create(:user, member_in_project: project, member_with_permissions: permissions) }
+
+ subject do
+ request
+
+ response
+ end
+
+ it 'is success' do
+ expect(subject)
+ .to have_http_status(:ok)
+ end
+
+ it 'renders the template' do
+ expect(subject)
+ .to render_template :annotate
+ end
+ end
+
+ describe 'export' do
+ let(:permissions) { %i[view_wiki_pages export_wiki_pages] }
+
+ current_user { create(:user, member_in_project: project, member_with_permissions: permissions) }
+
+ before do
+ get :export, params: { project_id: project.identifier }
+ end
+
+ it 'is successful' do
+ expect(response)
+ .to have_http_status(:ok)
+ end
+
+ it 'assigns pages' do
+ expect(assigns[:pages])
+ .to eq project.wiki.pages
+ end
+
+ it 'is an html response' do
+ expect(response.content_type)
+ .to eq 'text/html'
+ end
+
+ context 'for an unauthorized user' do
+ let(:permissions) { %i[view_wiki_pages] }
+
+ it 'prevents access' do
+ expect(response)
+ .to have_http_status(:forbidden)
+ end
+ end
+ end
+
+ describe 'protect' do
+ let(:permissions) { %i[view_wiki_pages protect_wiki_pages] }
+
+ let(:params) do
+ { project_id: project, id: existing_page.title, protected: '1' }
+ end
+
+ let(:request) do
+ post :protect, params:
+ end
+
+ current_user { create(:user, member_in_project: project, member_with_permissions: permissions) }
+
+ subject do
+ request
+ response
+ end
+
+ context 'with an existing wiki page' do
+ it 'set the protected property of the page' do
+ expect { subject }
+ .to change { existing_page.reload.protected? }
+ .from(false)
+ .to(true)
+ end
+
+ it 'redirects to the show page' do
+ expect(subject)
+ .to redirect_to action: 'show', project_id: project.identifier, id: existing_page.title.downcase
+ end
+ end
+
+ context 'with an existing wiki page that is protected' do
+ let(:permissions) do
+ existing_page.update_column :protected, true
+
+ %i[view_wiki_pages protect_wiki_pages]
+ end
+
+ let(:params) do
+ { project_id: project, id: existing_page.title, protected: '0' }
+ end
+
+ it 'set the protected property of the page' do
+ expect { subject }
+ .to change { existing_page.reload.protected? }
+ .from(true)
+ .to(false)
+ end
+
+ it 'redirects to the show page' do
+ expect(subject)
+ .to redirect_to action: 'show', project_id: project.identifier, id: existing_page.title.downcase
+ end
+ end
+
+ context 'with an existing wiki page but missing permissions' do
+ let(:permissions) do
+ %i[view_wiki_pages]
+ end
+
+ it 'does not change the protected property of the page' do
+ expect { subject }
+ .not_to change { existing_page.reload.protected? }
+ end
+
+ it 'return forbidden' do
+ expect(subject)
+ .to have_http_status(:forbidden)
+ end
+ end
+ end
+
+ describe 'history' do
+ let(:permissions) { %i[view_wiki_edits] }
+
+ current_user { create(:user, member_in_project: project, member_with_permissions: permissions) }
+
+ before do
+ get :history, params: { project_id: project.identifier, id: existing_page.title }
+ end
+
+ it 'is successful' do
+ expect(response)
+ .to have_http_status(:ok)
+ end
+
+ it 'renders the template' do
+ expect(response)
+ .to render_template :history
+ end
+
+ it 'assigns versions' do
+ expect(assigns[:versions])
+ .to eq existing_content.journals
+ end
+
+ context 'for a non existing page' do
+ before do
+ get :history, params: { project_id: project.identifier, id: 'bogus' }
+ end
+
+ it 'states not found' do
+ expect(response)
+ .to have_http_status(:not_found)
end
end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index ff8843b643f..ab07920592e 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -192,6 +192,38 @@ describe Project, type: :model do
end
end
+ describe '#members' do
+ let(:role) { create(:role) }
+ let(:active_user) { create(:user) }
+ let!(:active_member) { create(:member, project:, user: active_user, roles: [role]) }
+
+ let(:inactive_user) { create(:user, status: Principal.statuses[:locked]) }
+ let!(:inactive_member) { create(:member, project:, user: inactive_user, roles: [role]) }
+
+ it 'only includes active members' do
+ expect(project.members)
+ .to eq [active_member]
+ end
+ end
+
+ include_examples 'creates an audit trail on destroy' do
+ subject { create(:attachment) }
+ end
+
+ describe '#users' do
+ let(:role) { create(:role) }
+ let(:active_user) { create(:user) }
+ let!(:active_member) { create(:member, project:, user: active_user, roles: [role]) }
+
+ let(:inactive_user) { create(:user, status: Principal.statuses[:locked]) }
+ let!(:inactive_member) { create(:member, project:, user: inactive_user, roles: [role]) }
+
+ it 'only includes active users' do
+ expect(project.users)
+ .to eq [active_user]
+ end
+ end
+
include_examples 'creates an audit trail on destroy' do
subject { create(:attachment) }
end
diff --git a/spec_legacy/fixtures/wiki_contents.yml b/spec_legacy/fixtures/wiki_contents.yml
deleted file mode 100644
index 7ed34b46284..00000000000
--- a/spec_legacy/fixtures/wiki_contents.yml
+++ /dev/null
@@ -1,122 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2022 the OpenProject GmbH
-#
-# 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 COPYRIGHT and LICENSE files for more details.
-#++
-
----
-wiki_contents_001:
- text: |-
- h1. CookBook documentation
-
- Some updated [[documentation]] here with gzipped history
- updated_at: 2007-03-07 00:10:51 +01:00
- page_id: 1
- id: 1
- lock_version: 3
- author_id: 1
-wiki_contents_002:
- text: |-
- h1. Another page
-
- This is a link to a ticket: #2
- And this is an included page:
- {{include(Page with an inline image)}}
- updated_at: 2007-03-08 00:18:07 +01:00
- page_id: 2
- id: 2
- lock_version: 1
- author_id: 1
-wiki_contents_003:
- text: |-
- h1. Start page
-
- E-commerce web site start page
- updated_at: 2007-03-08 00:18:07 +01:00
- page_id: 3
- id: 3
- lock_version: 1
- author_id: 1
-wiki_contents_004:
- text: |-
- h1. Page with an inline image
-
- This is an inline image:
-
- !logo.gif!
- updated_at: 2007-03-08 00:18:07 +01:00
- page_id: 4
- id: 4
- lock_version: 1
- author_id: 1
-wiki_contents_005:
- text: |-
- h1. Child page 1
-
- This is a child page
- updated_at: 2007-03-08 00:18:07 +01:00
- page_id: 5
- id: 5
- lock_version: 1
- author_id: 1
-wiki_contents_006:
- text: |-
- h1. Child page 2
-
- This is a child page
- updated_at: 2007-03-08 00:18:07 +01:00
- page_id: 6
- id: 6
- lock_version: 1
- author_id: 1
-wiki_contents_007:
- text: This is a child page
- updated_at: 2007-03-08 00:18:07 +01:00
- page_id: 7
- id: 7
- lock_version: 1
- author_id: 1
-wiki_contents_008:
- text: This is a parent page
- updated_at: 2007-03-08 00:18:07 +01:00
- page_id: 8
- id: 8
- lock_version: 1
- author_id: 1
-wiki_contents_009:
- text: This is a child page
- updated_at: 2007-03-08 00:18:07 +01:00
- page_id: 9
- id: 9
- lock_version: 1
- author_id: 1
-wiki_contents_010:
- text: Page with cyrillic title
- updated_at: 2007-03-08 00:18:07 +01:00
- page_id: 10
- id: 10
- lock_version: 1
- author_id: 1
-
diff --git a/spec_legacy/fixtures/wiki_pages.yml b/spec_legacy/fixtures/wiki_pages.yml
deleted file mode 100644
index bbc0806e15f..00000000000
--- a/spec_legacy/fixtures/wiki_pages.yml
+++ /dev/null
@@ -1,109 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2022 the OpenProject GmbH
-#
-# 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 COPYRIGHT and LICENSE files for more details.
-#++
-
----
-wiki_pages_001:
- created_at: 2007-03-07 00:08:07 +01:00
- title: CookBook documentation
- slug: cookbook-documentation
- id: 1
- wiki_id: 1
- protected: true
- parent_id:
-wiki_pages_002:
- created_at: 2007-03-08 00:18:07 +01:00
- title: Another page
- slug: another-page
- id: 2
- wiki_id: 1
- protected: false
- parent_id:
-wiki_pages_003:
- created_at: 2007-03-08 00:18:07 +01:00
- title: Start page
- slug: start-page
- id: 3
- wiki_id: 2
- protected: false
- parent_id:
-wiki_pages_004:
- created_at: 2007-03-08 00:18:07 +01:00
- title: Page with an inline image
- slug: page-with-an-inline-image
- id: 4
- wiki_id: 1
- protected: false
- parent_id: 1
-wiki_pages_005:
- created_at: 2007-03-08 00:18:07 +01:00
- title: Child 1
- slug: child-1
- id: 5
- wiki_id: 1
- protected: false
- parent_id: 2
-wiki_pages_006:
- created_at: 2007-03-08 00:18:07 +01:00
- title: Child 2
- slug: child-2
- id: 6
- wiki_id: 1
- protected: false
- parent_id: 2
-wiki_pages_007:
- created_at: 2007-03-08 00:18:07 +01:00
- title: Child page 1
- slug: child-page-1
- id: 7
- wiki_id: 2
- protected: false
- parent_id: 8
-wiki_pages_008:
- created_at: 2007-03-08 00:18:07 +01:00
- title: Parent page
- slug: parent-page
- id: 8
- wiki_id: 2
- protected: false
- parent_id:
-wiki_pages_009:
- created_at: 2007-03-08 00:18:07 +01:00
- title: Child page 2
- slug: child-page-2
- id: 9
- wiki_id: 2
- protected: false
- parent_id: 8
-wiki_pages_010:
- created_at: 2007-03-08 00:18:07 +01:00
- title: Этика менеджмента
- slug: etika-mieniedzhmienta
- id: 10
- wiki_id: 1
- protected: false
- parent_id:
diff --git a/spec_legacy/fixtures/wikis.yml b/spec_legacy/fixtures/wikis.yml
deleted file mode 100644
index 216ef63afc9..00000000000
--- a/spec_legacy/fixtures/wikis.yml
+++ /dev/null
@@ -1,40 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2022 the OpenProject GmbH
-#
-# 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 COPYRIGHT and LICENSE files for more details.
-#++
-
----
-wiki_menu_item_001:
- status: 1
- start_page: CookBook documentation
- project_id: 1
- id: 1
-wiki_menu_item_002:
- status: 1
- start_page: Start page
- project_id: 2
- id: 2
-
diff --git a/spec_legacy/functional/wiki_controller_spec.rb b/spec_legacy/functional/wiki_controller_spec.rb
deleted file mode 100644
index ec018fcd652..00000000000
--- a/spec_legacy/functional/wiki_controller_spec.rb
+++ /dev/null
@@ -1,279 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2022 the OpenProject GmbH
-#
-# 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 COPYRIGHT and LICENSE files for more details.
-#++
-require_relative '../legacy_spec_helper'
-require 'wiki_controller'
-
-describe WikiController, type: :controller do
- render_views
-
- fixtures :all
-
- before do
- User.current = nil
- end
-
- def wiki
- Project.first.wiki
- end
-
- def redirect_page
- wiki.find_page(wiki.start_page) || wiki.pages.first
- end
-
- it 'histories with one version' do
- create :wiki_content_journal,
- journable_id: 2,
- data: build(:journal_wiki_content_journal,
- text: "h1. Another page\n\n\nthis is a link to ticket: #2")
- get :history, params: { project_id: 1, id: 'Another page' }
- assert_response :success
- assert_template 'history'
- refute_nil assigns(:versions)
- assert_equal 1, assigns(:versions).size
- assert_select 'input[type=submit][name=commit]', false
- end
-
- it 'diffs' do
- journal_from = create :wiki_content_journal,
- journable_id: 1,
- data: build(:journal_wiki_content_journal,
- text: 'h1. CookBook documentation')
- journal_to = create :wiki_content_journal,
- journable_id: 1,
- data: build(:journal_wiki_content_journal,
- text: "h1. CookBook documentation\n\n\nSome updated [[documentation]] here...")
-
- get :diff,
- params: { project_id: 1, id: 'CookBook documentation', version: journal_to.version, version_from: journal_from.version }
- assert_response :success
- assert_template 'diff'
- assert_select 'ins', attributes: { class: 'diffins' },
- content: /updated/
- end
-
- it 'annotates' do
- create :wiki_content_journal,
- journable_id: 1,
- data: build(:journal_wiki_content_journal,
- text: 'h1. CookBook documentation')
- journal_to = create :wiki_content_journal,
- journable_id: 1,
- data: build(:journal_wiki_content_journal,
- text: "h1. CookBook documentation\n\n\nSome [[documentation]] here...")
-
- get :annotate, params: { project_id: 1, id: 'CookBook documentation', version: journal_to.version }
- assert_response :success
- assert_template 'annotate'
- # Line 1
- assert_select 'tr',
- child: { tag: 'th', attributes: { class: 'line-num' }, content: '1' },
- child: { tag: 'td', attributes: { class: 'author' }, content: /John Smith/ },
- child: { tag: 'td', content: /h1\. CookBook documentation/ }
- # Line 2
- assert_select 'tr',
- child: { tag: 'th', attributes: { class: 'line-num' }, content: '2' },
- child: { tag: 'td', attributes: { class: 'author' }, content: /redMine Admin/ },
- child: { tag: 'td', content: /Some updated \[\[documentation\]\] here/ }
- end
-
- it 'gets rename' do
- session[:user_id] = 2
- get :rename, params: { project_id: 1, id: 'Another page' }
- assert_response :success
- assert_template 'rename'
- end
-
- it 'gets rename child page' do
- session[:user_id] = 2
- get :rename, params: { project_id: 1, id: 'Child 1' }
- assert_response :success
- assert_template 'rename'
- end
-
- it 'renames with redirect' do
- session[:user_id] = 2
- patch :rename, params: { project_id: 1, id: 'Another page',
- page: { title: 'Another renamed page',
- redirect_existing_links: 1 } }
- assert_redirected_to action: 'show', project_id: 'ecookbook', id: 'another-renamed-page'
- # Check redirects
- refute_nil wiki.find_page('Another page')
- assert_nil wiki.find_page('Another page', with_redirect: false)
- end
-
- it 'renames without redirect' do
- session[:user_id] = 2
- patch :rename, params: { project_id: 1, id: 'another-page',
- page: { title: 'Another renamed page',
- redirect_existing_links: '0' } }
- assert_redirected_to action: 'show', project_id: 'ecookbook', id: 'another-renamed-page'
- # Check that there's no redirects
- assert_nil wiki.find_page('Another page')
- end
-
- it 'destroys child' do
- session[:user_id] = 2
- delete :destroy, params: { project_id: 1, id: 'Child 1' }
- assert_redirected_to action: 'index', project_id: 'ecookbook', id: redirect_page
- end
-
- it 'destroys parent' do
- session[:user_id] = 2
- assert_no_difference('WikiPage.count') do
- delete :destroy, params: { project_id: 1, id: 'Another page' }
- end
- assert_response :success
- assert_template 'destroy'
- end
-
- it 'destroys parent with nullify' do
- session[:user_id] = 2
- assert_difference('WikiPage.count', -1) do
- delete :destroy, params: { project_id: 1, id: 'Another page', todo: 'nullify' }
- end
- assert_redirected_to action: 'index', project_id: 'ecookbook', id: redirect_page
- assert_nil WikiPage.find_by(id: 2)
- end
-
- it 'destroys parent with cascade' do
- session[:user_id] = 2
- assert_difference('WikiPage.count', -3) do
- delete :destroy, params: { project_id: 1, id: 'Another page', todo: 'destroy' }
- end
- assert_redirected_to action: 'index', project_id: 'ecookbook', id: redirect_page
- assert_nil WikiPage.find_by(id: 2)
- assert_nil WikiPage.find_by(id: 5)
- end
-
- it 'destroys parent with reassign' do
- session[:user_id] = 2
- assert_difference('WikiPage.count', -1) do
- delete :destroy, params: { project_id: 1, id: 'Another page', todo: 'reassign', reassign_to_id: 1 }
- end
- assert_redirected_to action: 'index', project_id: 'ecookbook', id: redirect_page
- assert_nil WikiPage.find_by(id: 2)
- assert_equal WikiPage.find(1), WikiPage.find_by(id: 5).parent
- end
-
- it 'indexes' do
- get :index, params: { project_id: 'ecookbook' }
- assert_response :success
- assert_template 'index'
- pages = assigns(:pages)
- refute_nil pages
- assert_equal wiki.pages.size, pages.size
-
- assert_select 'ul', attributes: { class: 'pages-hierarchy' },
- child: { tag: 'li', child: { tag: 'a', attributes: { href: '/projects/ecookbook/wiki/CookBook%20documentation' },
- content: 'CookBook documentation' },
- child: { tag: 'ul',
- child: { tag: 'li',
- child: { tag: 'a', attributes: { href: '/projects/ecookbook/wiki/Page%20with%20an%20inline%20image' },
- content: 'Page with an inline image' } } } },
- child: { tag: 'li', child: { tag: 'a', attributes: { href: '/projects/ecookbook/wiki/Another%20page' },
- content: 'Another page' } }
- end
-
- it 'indexes should include atom link' do
- get :index, params: { project_id: 'ecookbook' }
- assert_select 'a', attributes: { href: '/projects/ecookbook/activity.atom?show_wiki_edits=1' }
- end
-
- context 'GET :export' do
- context 'with an authorized user to export the wiki' do
- before do
- session[:user_id] = 2
- get :export, params: { project_id: 'ecookbook' }
- end
-
- it { is_expected.to respond_with :success }
- it { should_assign_to :pages }
- it { should_respond_with_content_type 'text/html' }
-
- it 'exports all of the wiki pages to a single html file' do
- assert_select 'a[name=?]', 'cookbook-documentation'
- assert_select 'a[name=?]', 'another-page'
- assert_select 'a[name=?]', 'page-with-an-inline-image'
- end
- end
-
- context 'with an unauthorized user' do
- before do
- get :export, params: { project_id: 'ecookbook' }
-
- it { is_expected.to respond_with :redirect }
- it { is_expected.to redirect_to('wiki index') { { action: 'show', project_id: @project, id: nil } } }
- end
- end
- end
-
- it 'protects page' do
- page = WikiPage.find_by(wiki_id: 1, title: 'Another page')
- assert !page.protected?
- session[:user_id] = 2
- post :protect, params: { project_id: 1, id: page.title, protected: '1' }
- assert_redirected_to action: 'show', project_id: 'ecookbook', id: 'another-page'
- assert page.reload.protected?
- end
-
- it 'unprotects page' do
- page = WikiPage.find_by(wiki_id: 1, title: 'CookBook documentation')
- assert page.protected?
- session[:user_id] = 2
- post :protect, params: { project_id: 1, id: page.title, protected: '0' }
- assert_redirected_to action: 'show', project_id: 'ecookbook', id: 'cookbook-documentation'
- assert !page.reload.protected?
- end
-
- it 'edits unprotected page' do
- # Non members can edit unprotected wiki pages
- session[:user_id] = 4
- get :edit, params: { project_id: 1, id: 'Another page' }
- assert_response :success
- assert_template 'edit'
- end
-
- it 'edits protected page by nonmember' do
- # Non members can't edit protected wiki pages
- session[:user_id] = 4
- get :edit, params: { project_id: 1, id: 'CookBook documentation' }
- assert_response 403
- end
-
- it 'edits protected page by member' do
- session[:user_id] = 2
- get :edit, params: { project_id: 1, id: 'CookBook documentation' }
- assert_response :success
- assert_template 'edit'
- end
-
- it 'histories of non existing page should return 404' do
- get :history, params: { project_id: 1, id: 'Unknown page' }
- assert_response 404
- end
-end
diff --git a/spec_legacy/unit/project_spec.rb b/spec_legacy/unit/project_spec.rb
index c6f8d991ce8..5f476171b84 100644
--- a/spec_legacy/unit/project_spec.rb
+++ b/spec_legacy/unit/project_spec.rb
@@ -34,43 +34,6 @@ describe Project, type: :model do
User.current = nil
end
- it { is_expected.to validate_presence_of :name }
-
- context 'associations' do
- it { is_expected.to have_many :members }
- it { is_expected.to have_many(:users).through(:members) }
- it { is_expected.to have_many :member_principals }
- it { is_expected.to have_many(:principals).through(:member_principals) }
- it { is_expected.to have_many :enabled_modules }
- it { is_expected.to have_many :work_packages }
- it { is_expected.to have_many(:work_package_changes).through(:work_packages) }
- it { is_expected.to have_many :versions }
- it { is_expected.to have_many :time_entries }
- it { is_expected.to have_many :queries }
- it { is_expected.to have_many :news }
- it { is_expected.to have_many :categories }
- it { is_expected.to have_many :forums }
- it { is_expected.to have_many(:changesets).through(:repository) }
-
- it { is_expected.to have_one :repository }
- it { is_expected.to have_one :wiki }
-
- it { is_expected.to have_and_belong_to_many :types }
- it { is_expected.to have_and_belong_to_many :work_package_custom_fields }
- end
-
- it 'memberses should be active users' do
- Project.all.each do |project|
- assert_nil project.members.detect { |m| !(m.principal.is_a?(User) && m.principal.active?) }
- end
- end
-
- it 'userses should be active users' do
- Project.all.each do |project|
- assert_nil project.users.detect { |u| !(u.is_a?(User) && u.active?) }
- end
- end
-
it 'parents' do
p = Project.find(6).parent
assert p.is_a?(Project)
diff --git a/spec_legacy/unit/user_spec.rb b/spec_legacy/unit/user_spec.rb
index 1bba4058b76..9b929fcd9b5 100644
--- a/spec_legacy/unit/user_spec.rb
+++ b/spec_legacy/unit/user_spec.rb
@@ -164,54 +164,6 @@ describe User, type: :model do
end
end
- if ldap_configured?
- describe '#try_to_login using LDAP' do
- context 'with failed connection to the LDAP server' do
- it 'returns nil' do
- @auth_source = LdapAuthSource.find(1)
- allow_any_instance_of(AuthSource).to receive(:initialize_ldap_con).and_raise(Net::LDAP::Error, 'Cannot connect')
-
- assert_equal nil, User.try_to_login('edavis', 'wrong')
- end
- end
-
- context 'with an unsuccessful authentication' do
- it 'returns nil' do
- assert_equal nil, User.try_to_login('edavis', 'wrong')
- end
- end
-
- context 'on the fly registration' do
- before do
- @auth_source = LdapAuthSource.find(1)
- end
-
- context 'with a successful authentication' do
- it "creates a new user account if it doesn't exist" do
- assert_difference('User.count') do
- user = User.try_to_login('edavis', '123456')
- assert !user.admin?
- end
- end
-
- it 'retrieves existing user' do
- user = User.try_to_login('edavis', '123456')
- user.admin = true
- user.save!
-
- assert_no_difference('User.count') do
- user = User.try_to_login('edavis', '123456')
- assert user.admin?
- end
- end
- end
- end
- end
-
- else
- puts 'Skipping LDAP tests.'
- end
-
it 'returns existing or new anonymous' do
anon = User.anonymous
assert !anon.new_record?