diff --git a/config/static_links.yml b/config/static_links.yml index fa15fd0bddc..9b02fee002c 100644 --- a/config/static_links.yml +++ b/config/static_links.yml @@ -39,6 +39,8 @@ disable_password_login: docker_installation: href: https://www.openproject.org/docs/installation-and-operations/installation/docker/ label: Docker installation +documents_docs: + href: https://www.openproject.org/docs/user-guide/documents/ enterprise_features: attribute_highlighting: href: https://www.openproject.org/docs/user-guide/work-packages/work-package-table-configuration/#attribute-highlighting-enterprise-add-on diff --git a/lib/tasks/delete_documents.rake b/lib/tasks/delete_documents.rake index 4409e4d1218..ab01c9c7b57 100644 --- a/lib/tasks/delete_documents.rake +++ b/lib/tasks/delete_documents.rake @@ -33,9 +33,9 @@ namespace :migrations do include Tasks::Shared::UserFeedback # rubocop:disable Rails/ApplicationRecord - class TemporaryDocument < ActiveRecord::Base + class TemporaryDocument < ActiveRecord::Base # rubocop:disable Lint/ConstantDefinitionInBlock belongs_to :project - belongs_to :category, class_name: "DocumentCategory" + belongs_to :type, class_name: "DocumentType", optional: true end # rubocop:enable Rails/ApplicationRecord diff --git a/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb b/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb index 1c547f56ba9..2803933a8fa 100644 --- a/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb +++ b/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb @@ -105,7 +105,7 @@ RSpec.describe RootSeeder, end include_examples "it creates records", model: Color, expected_count: 148 - include_examples "it creates records", model: DocumentCategory, expected_count: 3 + include_examples "it creates records", model: DocumentType, expected_count: 6 include_examples "it creates records", model: IssuePriority, expected_count: 4 include_examples "it creates records", model: Status, expected_count: 4 include_examples "it creates records", model: TimeEntryActivity, expected_count: 3 diff --git a/modules/documents/app/components/documents/admin/document_categories/deprecation_notice_component.html.erb b/modules/documents/app/components/documents/admin/document_categories/deprecation_notice_component.html.erb new file mode 100644 index 00000000000..deb4c5615f7 --- /dev/null +++ b/modules/documents/app/components/documents/admin/document_categories/deprecation_notice_component.html.erb @@ -0,0 +1,52 @@ +<%# + -- copyright + OpenProject is an open source project management software. + Copyright (C) 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. + + ++# +%> + +<%= render( + Primer::Beta::Blankslate.new(border: true, test_selector: "documents-categories-deprecation-notice") + ) do |component| + component.with_visual_icon(icon: :"op-file-doc") + component.with_heading(tag: :h2).with_content(I18n.t("documents.document_categories_deprecation_notice.heading")) + + component.with_description { I18n.t("documents.document_categories_deprecation_notice.description") } + component.with_primary_action( + scheme: :primary, + label: I18n.t("documents.document_categories_deprecation_notice.primary_action"), + tag: :a, + href: admin_settings_document_types_path + ).with_content(I18n.t("documents.document_categories_deprecation_notice.primary_action")) + + component.with_secondary_action( + scheme: :secondary, + label: I18n.t("documents.document_categories_deprecation_notice.secondary_action"), + tag: :a, + href: OpenProject::Static::Links.url_for(:documents_docs) + ).with_content(I18n.t("documents.document_categories_deprecation_notice.secondary_action")) + end %> diff --git a/modules/documents/spec/factories/document_category_factory.rb b/modules/documents/app/components/documents/admin/document_categories/deprecation_notice_component.rb similarity index 89% rename from modules/documents/spec/factories/document_category_factory.rb rename to modules/documents/app/components/documents/admin/document_categories/deprecation_notice_component.rb index 7126cc22a00..508bdfdd3d7 100644 --- a/modules/documents/spec/factories/document_category_factory.rb +++ b/modules/documents/app/components/documents/admin/document_categories/deprecation_notice_component.rb @@ -28,9 +28,11 @@ # See COPYRIGHT and LICENSE files for more details. #++ -FactoryBot.define do - factory :document_category do - project - sequence(:name) { |n| "I am Category No. #{n}" } +module Documents + module Admin + module DocumentCategories + class DeprecationNoticeComponent < ApplicationComponent + end + end end end diff --git a/modules/documents/app/controllers/admin/settings/document_categories_controller.rb b/modules/documents/app/controllers/admin/settings/document_categories_controller.rb index 9526f256279..4f637552ecf 100644 --- a/modules/documents/app/controllers/admin/settings/document_categories_controller.rb +++ b/modules/documents/app/controllers/admin/settings/document_categories_controller.rb @@ -30,14 +30,14 @@ module Admin module Settings - class DocumentCategoriesController < EnumerationsControllerBase + class DocumentCategoriesController < ApplicationController + layout "admin" + + before_action :require_admin + menu_item :document_categories - private - - def enumeration_class - DocumentCategory - end + def index; end end end end diff --git a/modules/documents/app/controllers/documents_controller.rb b/modules/documents/app/controllers/documents_controller.rb index 73718a4c1b0..d74ab240f28 100644 --- a/modules/documents/app/controllers/documents_controller.rb +++ b/modules/documents/app/controllers/documents_controller.rb @@ -44,7 +44,7 @@ class DocumentsController < ApplicationController def index @documents = list_documents_query - .includes(:category) + .includes(:type) .paginate(page: page_param, per_page: per_page_param) end diff --git a/modules/documents/app/models/document.rb b/modules/documents/app/models/document.rb index c297881b8f1..093e2b0f80a 100644 --- a/modules/documents/app/models/document.rb +++ b/modules/documents/app/models/document.rb @@ -34,7 +34,6 @@ class Document < ApplicationRecord collaborative: "collaborative" } - belongs_to :category, class_name: "DocumentCategory", optional: true belongs_to :project belongs_to :type, class_name: "DocumentType", optional: true, counter_cache: :documents_count diff --git a/modules/documents/app/models/document_category.rb b/modules/documents/app/models/document_category.rb deleted file mode 100644 index 14c26268288..00000000000 --- a/modules/documents/app/models/document_category.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -#-- copyright -# OpenProject is an open source project management software. -# Copyright (C) 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. -#++ - -class DocumentCategory < Enumeration - has_many :documents, foreign_key: "category_id" - - OptionName = :enumeration_doc_categories - - def option_name - OptionName - end - - def objects_count - documents.count - end - - def transfer_relations(to) - documents.update_all("category_id = #{to.id}") - end -end diff --git a/modules/documents/app/seeders/basic_data/documents/enumeration_seeder.rb b/modules/documents/app/seeders/basic_data/documents/enumeration_seeder.rb deleted file mode 100644 index f1de1d0db09..00000000000 --- a/modules/documents/app/seeders/basic_data/documents/enumeration_seeder.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -#-- copyright -# OpenProject is an open source project management software. -# Copyright (C) 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. -#++ - -module BasicData - module Documents - class EnumerationSeeder < ModelSeeder - self.model_class = DocumentCategory - self.seed_data_model_key = "document_categories" - - def model_attributes(category_data) - { - name: category_data["name"] - } - end - end - end -end diff --git a/modules/documents/app/seeders/common.yml b/modules/documents/app/seeders/common.yml index ee8ca60ae1d..bb0ed8c4db6 100644 --- a/modules/documents/app/seeders/common.yml +++ b/modules/documents/app/seeders/common.yml @@ -36,14 +36,6 @@ modules_permissions: add: - :view_documents -document_categories: - - t_name: Documentation - position: 1 - - t_name: Specification - position: 2 - - t_name: Other - position: 3 - document_types: - reference: doc_type_note t_name: Note diff --git a/modules/documents/app/views/admin/settings/document_categories/edit.html.erb b/modules/documents/app/views/admin/settings/document_categories/edit.html.erb deleted file mode 100644 index 922c90cf315..00000000000 --- a/modules/documents/app/views/admin/settings/document_categories/edit.html.erb +++ /dev/null @@ -1,49 +0,0 @@ -<%#-- copyright -OpenProject is an open source project management software. -Copyright (C) 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.v -See COPYRIGHT and LICENSE files for more details. - -++#%> - -<% html_title t(:label_administration), t("documents.label_categories") %> - -<%= - render(Primer::OpenProject::PageHeader.new) do |header| - header.with_title { @enumeration.name } - header.with_breadcrumbs( - [ - { href: admin_index_path, text: t("label_administration") }, - { href: admin_settings_storages_path, text: t("project_module_storages") }, - { href: url_for(action: :index), text: t("documents.label_categories") }, - @enumeration.name - ] - ) - end -%> - -<% content_controller "admin--enumerations" %> - -<%= settings_primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :update, id: @enumeration)) do |f| %> - <%= render(Admin::Enumerations::ItemForm.new(f)) %> -<% end %> diff --git a/modules/documents/app/views/admin/settings/document_categories/index.html.erb b/modules/documents/app/views/admin/settings/document_categories/index.html.erb index e4abe0827dc..eb2ede415f9 100644 --- a/modules/documents/app/views/admin/settings/document_categories/index.html.erb +++ b/modules/documents/app/views/admin/settings/document_categories/index.html.erb @@ -1,45 +1,45 @@ -<%#-- copyright -OpenProject is an open source project management software. -Copyright (C) the OpenProject GmbH +<%# + -- copyright + OpenProject is an open source project management software. + Copyright (C) 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. + 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 + 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 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. + 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. + 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. + See COPYRIGHT and LICENSE files for more details. -++#%> + ++# +%> <% html_title t(:label_administration), t("documents.label_categories") %> -<%= - render(Primer::OpenProject::PageHeader.new) do |header| - header.with_title { t("documents.label_categories") } - header.with_breadcrumbs( - [ - { href: admin_index_path, text: t("label_administration") }, - { href: admin_settings_storages_path, text: t("project_module_storages") }, - t("documents.label_categories") - ] - ) - end -%> +<%= render(Primer::OpenProject::PageHeader.new) do |header| + header.with_title { t("documents.label_categories") } + header.with_breadcrumbs( + [ + { href: admin_index_path, text: t("label_administration") }, + { href: admin_settings_storages_path, text: t("project_module_storages") }, + t("documents.label_categories") + ] + ) + end %> -<%= render(index_component_class.new(enumerations: @enumerations)) %> +<%= render(Documents::Admin::DocumentCategories::DeprecationNoticeComponent.new) %> diff --git a/modules/documents/app/views/admin/settings/document_categories/new.html.erb b/modules/documents/app/views/admin/settings/document_categories/new.html.erb deleted file mode 100644 index e23cc512ff0..00000000000 --- a/modules/documents/app/views/admin/settings/document_categories/new.html.erb +++ /dev/null @@ -1,48 +0,0 @@ -<%#-- copyright -OpenProject is an open source project management software. -Copyright (C) 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.v -See COPYRIGHT and LICENSE files for more details. - -++#%> - -<% html_title t(:label_administration), t("documents.new_category") %> - -<%= - render(Primer::OpenProject::PageHeader.new) do |header| - header.with_title { I18n.t("documents.new_category") } - header.with_breadcrumbs( - [ - { href: admin_index_path, text: t("label_administration") }, - { href: admin_settings_storages_path, text: t("project_module_storages") }, - t("documents.new_category") - ] - ) - end -%> - -<% content_controller "admin--enumerations" %> - -<%= primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :create)) do |f| %> - <%= render(Admin::Enumerations::ItemForm.new(f)) %> -<% end %> diff --git a/modules/documents/app/views/admin/settings/document_categories/reassign.html.erb b/modules/documents/app/views/admin/settings/document_categories/reassign.html.erb deleted file mode 100644 index 01463f8c242..00000000000 --- a/modules/documents/app/views/admin/settings/document_categories/reassign.html.erb +++ /dev/null @@ -1,47 +0,0 @@ -<%#-- copyright -OpenProject is an open source project management software. -Copyright (C) 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.v -See COPYRIGHT and LICENSE files for more details. - -++#%> - -<% html_title t(:label_administration), t("documents.categories") %> - -<%= - render(Primer::OpenProject::PageHeader.new) do |header| - header.with_title { @enumeration.name } - header.with_breadcrumbs( - [ - { href: admin_index_path, text: t("label_administration") }, - { href: admin_settings_storages_path, text: t("project_module_storages") }, - { href: url_for(action: :index), text: t("documents.categories") }, - @enumeration.name - ] - ) - end -%> - -<%= primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :destroy, id: @enumeration), method: :delete) do |f| %> - <%= render(Admin::Enumerations::ReassignForm.new(f, other_enumerations: @other_enumerations)) %> -<% end %> diff --git a/modules/documents/config/locales/en.yml b/modules/documents/config/locales/en.yml index 6222724b526..d0195bfb48b 100644 --- a/modules/documents/config/locales/en.yml +++ b/modules/documents/config/locales/en.yml @@ -70,6 +70,14 @@ en: heading: "There are no documents yet" description: "There are no documents in this view. You can click the button below to add one." + document_categories_deprecation_notice: + heading: File categories are now called 'Document types' + description: |- + Your existing file categories have been converted to document types with the introduction of the new Documents module. + All existing documents have also been migrated to these new types. + primary_action: Configure document types + secondary_action: Learn more about the Documents module + document_type_actions: "Document type actions" index_page: diff --git a/modules/documents/lib/open_project/documents/engine.rb b/modules/documents/lib/open_project/documents/engine.rb index 6481b369f36..3549ef92b1a 100644 --- a/modules/documents/lib/open_project/documents/engine.rb +++ b/modules/documents/lib/open_project/documents/engine.rb @@ -117,10 +117,5 @@ module OpenProject::Documents # Add documents to allowed search params additional_permitted_attributes search: %i(documents) - - config.to_prepare do - # Load Enumeration descendants due to STI - DocumentCategory - end end end diff --git a/modules/documents/spec/factories/document_factory.rb b/modules/documents/spec/factories/document_factory.rb index 157dab9f267..eed60e3de6b 100644 --- a/modules/documents/spec/factories/document_factory.rb +++ b/modules/documents/spec/factories/document_factory.rb @@ -31,7 +31,6 @@ FactoryBot.define do factory :document do project - category factory: :document_category type factory: :document_type sequence(:description) { |n| "I am a document's description No. #{n}" } sequence(:title) { |n| "I am the document No. #{n}" } diff --git a/modules/documents/spec/features/document_categories_spec.rb b/modules/documents/spec/features/document_categories_spec.rb index 68e8a17c937..57dc664a4a2 100644 --- a/modules/documents/spec/features/document_categories_spec.rb +++ b/modules/documents/spec/features/document_categories_spec.rb @@ -31,34 +31,38 @@ require "spec_helper" RSpec.describe "Document categories", :js do + include Rails.application.routes.url_helpers + shared_let(:admin) { create(:admin) } before do login_as(admin) end - it "allows creating new document categories" do + it "renders a deprecation notice" do visit admin_settings_document_categories_path - page.find_test_selector("add-enumeration-button").click + expect(page).to have_heading("File categories are now called 'Document types'") + expect(page).to have_content("Your existing file categories have been converted to document types " \ + "with the introduction of the new Documents module. " \ + "All existing documents have also been migrated to these new types.") - fill_in "Name", with: "Documentation" - click_on("Save") + expect(page).to have_link("Configure document types", href: admin_settings_document_types_path) + expect(page).to have_link("Learn more about the Documents module", + href: "https://www.openproject.org/docs/user-guide/documents/?go_to_locale=en") + end - # we are redirected back to the index page - expect(page).to have_current_path(admin_settings_document_categories_path) - expect(page).to have_content("Documentation") + context "as non-admin" do + shared_let(:non_admin) { create(:user) } - # It allows editing (Regression #62459) - click_link "Documentation" + before do + login_as(non_admin) + end - fill_in "Name", with: "Specification" - click_on("Save") + it "denies access" do + visit admin_settings_document_categories_path - expect(page).to have_current_path(admin_settings_document_categories_path) - expect(page).to have_content("Specification") - - expect(DocumentCategory).to exist(name: "Specification") - expect(DocumentCategory).not_to exist(name: "Documentation") + expect(page).to have_content("You are not authorized to access this page.") + end end end diff --git a/modules/documents/spec/models/document_category_spec.rb b/modules/documents/spec/models/document_category_spec.rb deleted file mode 100644 index 16bbbd09cf8..00000000000 --- a/modules/documents/spec/models/document_category_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -# frozen_string_literal: true - -#-- copyright -# OpenProject is an open source project management software. -# Copyright (C) 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 "../spec_helper" - -require Rails.root.join("spec/models/enumerations/shared_enumeration_examples").to_s - -RSpec.describe DocumentCategory do - let(:project) { create(:project) } - - it "is an enumeration" do - expect(DocumentCategory.ancestors).to include Enumeration - end - - it "orders documents by the category they are created with" do - uncategorized = create(:document_category, name: "Uncategorized", project:) - user_documentation = create(:document_category, name: "User documentation") - - create_list(:document, 2, category: uncategorized, project:) - - expect(DocumentCategory.find_by_name(uncategorized.name).objects_count).to be 2 - expect(DocumentCategory.find_by_name(user_documentation.name).objects_count).to be 0 - end - - it "files the categorizations under the option name :enumeration_doc_categories" do - expect(DocumentCategory.new.option_name).to be :enumeration_doc_categories - end - - it "onlies allow one category to be the default-category" do - old_default = create(:document_category, name: "old default", project:, is_default: true) - - expect do - create(:document_category, name: "new default", project:, is_default: true) - old_default.reload - end.to change { old_default.is_default? }.from(true).to(false) - end - - it_behaves_like "enumeration#active handling", true do - let(:enumeration) { described_class.new(attributes_for(:document_category)) } - end -end diff --git a/modules/documents/spec/models/document_spec.rb b/modules/documents/spec/models/document_spec.rb index 233adc63e7a..8126c6eada4 100644 --- a/modules/documents/spec/models/document_spec.rb +++ b/modules/documents/spec/models/document_spec.rb @@ -32,7 +32,6 @@ require "spec_helper" require_module_spec_helper RSpec.describe Document do - let(:documentation_category) { create(:document_category, name: "User documentation") } let(:project) { create(:project) } let(:user) { create(:user) } let(:admin) { create(:admin) } @@ -52,7 +51,6 @@ RSpec.describe Document do end describe "Associations" do - it { is_expected.to belong_to(:category).class_name("DocumentCategory").optional } it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:type).class_name("DocumentType").optional } end @@ -71,7 +69,7 @@ RSpec.describe Document do end describe "create with a valid document" do - let(:valid_document) { build(:document, title: "Test", project:, category: documentation_category) } + let(:valid_document) { build(:document, title: "Test", project:) } it "adds a document" do expect do diff --git a/modules/documents/spec/requests/admin/settings/document_categories_spec.rb b/modules/documents/spec/requests/admin/settings/document_categories_spec.rb deleted file mode 100644 index 0bf374ac7e6..00000000000 --- a/modules/documents/spec/requests/admin/settings/document_categories_spec.rb +++ /dev/null @@ -1,100 +0,0 @@ -# frozen_string_literal: true - -#-- copyright -# OpenProject is an open source project management software. -# Copyright (C) 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 "spec_helper" - -RSpec.describe "Document categories", - :aggregate_failures, - :skip_csrf, - type: :rails_request do - shared_let(:admin) { create(:admin) } - shared_let(:category) { create(:document_category, name: "Technical") } - shared_let(:other_category) { create(:document_category, name: "Other") } - - before do - login_as(admin) - end - - describe "GET /admin/settings/document_categories" do - it "renders the index template" do - get admin_settings_document_categories_path - expect(response).to have_http_status(:ok) - expect(response.body).to include "Technical" - expect(response.body).to include "Other" - end - end - - describe "DELETE /admin/settings/document_categories/:id" do - let(:params) { {} } - - context "without documents assigned" do - it "redirects to the categories index" do - delete(admin_settings_document_category_path(category), params:) - expect(response).to redirect_to admin_settings_document_categories_path - expect { category.reload }.to raise_error(ActiveRecord::RecordNotFound) - end - end - - context "with documents assigned" do - shared_let(:document) { create(:document, category:) } - - it "renders the reassign template" do - delete(admin_settings_document_category_path(category), params:) - expect(response).to redirect_to reassign_admin_settings_document_category_path(category) - expect { category.reload }.not_to raise_error - expect(document.reload.category).to eq category - end - - context "with documents assigned and reassigning" do - let(:params) do - { - enumeration: { reassign_to_id: other_category.id } - } - end - - it "reassigns the category" do - delete(admin_settings_document_category_path(category), params:) - expect(response).to redirect_to admin_settings_document_categories_path - expect { category.reload }.to raise_error(ActiveRecord::RecordNotFound) - expect(document.reload.category).to eq other_category - end - end - end - end - - describe "PUT /admin/settings/document_categories/:id/move" do - it "moves the category to the bottom" do - put move_admin_settings_document_category_path(category), params: { move_to: "lowest" }, as: :turbo_stream - - expect(response).to have_http_status(:ok) - expect(category.reload.position).to be > other_category.reload.position - end - end -end diff --git a/modules/documents/spec/routing/document_categories_spec.rb b/modules/documents/spec/routing/document_categories_spec.rb deleted file mode 100644 index 993da4d15a3..00000000000 --- a/modules/documents/spec/routing/document_categories_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -# frozen_string_literal: true - -#-- copyright -# OpenProject is an open source project management software. -# Copyright (C) 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 "spec_helper" - -RSpec.describe Admin::Settings::DocumentCategoriesController, "routing" do - describe "document categories" do - it { - expect(subject).to route(:get, "admin/settings/document_categories") - .to(controller: "admin/settings/document_categories", action: "index") - } - - it { - expect(subject).to route(:get, "admin/settings/document_categories/new") - .to(controller: "admin/settings/document_categories", action: "new") - } - - it { - expect(subject).to route(:post, "admin/settings/document_categories") - .to(controller: "admin/settings/document_categories", action: "create") - } - - it { - expect(subject).to route(:get, "admin/settings/document_categories/1/edit") - .to(controller: "admin/settings/document_categories", action: "edit", id: "1") - } - - it { - expect(subject).to route(:put, "admin/settings/document_categories/1") - .to(controller: "admin/settings/document_categories", action: "update", id: "1") - } - - it { - expect(subject).to route(:delete, "admin/settings/document_categories/1") - .to(controller: "admin/settings/document_categories", action: "destroy", id: "1") - } - end -end diff --git a/spec/seeders/root_seeder_standard_edition_spec.rb b/spec/seeders/root_seeder_standard_edition_spec.rb index 80ef37ee22d..d3e7bd0f3eb 100644 --- a/spec/seeders/root_seeder_standard_edition_spec.rb +++ b/spec/seeders/root_seeder_standard_edition_spec.rb @@ -144,7 +144,7 @@ RSpec.describe RootSeeder, end include_examples "it creates records", model: Color, expected_count: 148 - include_examples "it creates records", model: DocumentCategory, expected_count: 3 + include_examples "it creates records", model: DocumentType, expected_count: 6 include_examples "it creates records", model: GlobalRole, expected_count: 2 include_examples "it creates records", model: WorkPackageRole, expected_count: 3 include_examples "it creates records", model: ProjectRole, expected_count: 5