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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Move document category names into the seeder files
Christophe Bliard05f47d268f8f
diff --git a/app/seeders/common.yml b/app/seeders/common.ymlnew file mode 100644index 00000000000..0b8b9588260--- /dev/null+++ b/app/seeders/common.yml@@ -0,0 +1,35 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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.+#++++document_categories:+- t_name: Management+ position: 1+- t_name: Security+ position: 2+- t_name: Accessibility+ position: 3diff --git a/app/seeders/composite_seeder.rb b/app/seeders/composite_seeder.rbindex aa14c7449f3..11f6b4e8626 100644--- a/app/seeders/composite_seeder.rb+++ b/app/seeders/composite_seeder.rb@@ -63,7 +63,7 @@ class CompositeSeeder < Seeder# e.g. 'BasicData::Documents' in order to avoid name conflicts.def discovered_seeder_classesSeeder- .subclasses+ .descendants.reject { |cl| cl.to_s.deconstantize == namespace }.select { |cl| include_discovered_class? cl }enddiff --git a/app/seeders/source/seed_data_loader.rb b/app/seeders/source/seed_data_loader.rbindex d89926a179c..12815135f9b 100644--- a/app/seeders/source/seed_data_loader.rb+++ b/app/seeders/source/seed_data_loader.rb@@ -47,12 +47,20 @@ class Source::SeedDataLoaderenddef seed_data- @seed_data ||= Source::SeedData.new(translate(seed_file.raw_content))+ @seed_data ||= Source::SeedData.new(translate(raw_seed_files_content))endprivate+ def raw_seed_files_content+ common_seed_file.raw_content.deep_merge(seed_file.raw_content)+ end+def seed_fileSource::SeedFile.find(seed_file_name)end++ def common_seed_file+ Source::SeedFile.find('common')+ endenddiff --git a/app/seeders/source/seed_file.rb b/app/seeders/source/seed_file.rbindex f62e51d3db9..4b996493281 100644--- a/app/seeders/source/seed_file.rb+++ b/app/seeders/source/seed_file.rb@@ -32,6 +32,7 @@ class Source::SeedFileclass << selfdef all@all ||= [+ new('app/seeders/common.yml'),new('app/seeders/standard.yml'),new('modules/bim/app/seeders/bim.yml')].freezediff --git a/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb b/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rbindex 39a00ec3c5e..20fbc387975 100644--- a/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb+++ b/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb@@ -78,6 +78,7 @@ describe RootSeeder,)end+ include_examples 'it creates records', model: DocumentCategory, expected_count: 3include_examples 'it creates records', model: IssuePriority, expected_count: 4include_examples 'it creates records', model: Status, expected_count: 4include_examples 'it creates records', model: TimeEntryActivity, expected_count: 3diff --git a/modules/documents/app/seeders/basic_data/documents/enumeration_seeder.rb b/modules/documents/app/seeders/basic_data/documents/enumeration_seeder.rbindex 7acbd21f4f7..80b30b0a95d 100644--- a/modules/documents/app/seeders/basic_data/documents/enumeration_seeder.rb+++ b/modules/documents/app/seeders/basic_data/documents/enumeration_seeder.rb@@ -28,21 +28,14 @@module BasicDatamodule Documents- class EnumerationSeeder < Seeder- def seed_data!- category_names.each do |name|- DocumentCategory.create name:- end- end-- def category_names- category_i18n_keys.map { |key| I18n.t key }- end+ class EnumerationSeeder < ModelSeeder+ self.model_class = DocumentCategory+ self.seed_data_model_key = 'document_categories'- def category_i18n_keys- ['documentation', 'specification', 'other'].map do |name|- ['enumeration', 'document_category', name].join('.')- end+ def model_attributes(category_data)+ {+ name: category_data['name']+ }endendenddiff --git a/modules/documents/config/locales/en.yml b/modules/documents/config/locales/en.ymlindex 4a573d04928..73649ce5300 100644--- a/modules/documents/config/locales/en.yml+++ b/modules/documents/config/locales/en.yml@@ -39,11 +39,6 @@ en:default_doc_category_user: "User documentation"enumeration_doc_categories: "Document categories"- enumeration:- document_category:- documentation: Documentation- specification: Specification- other: Otherdocuments:label_attachment_author: "Attachment author"diff --git a/spec/seeders/root_seeder_standard_edition_spec.rb b/spec/seeders/root_seeder_standard_edition_spec.rbindex d76fb43658f..42dc46d1587 100644--- a/spec/seeders/root_seeder_standard_edition_spec.rb+++ b/spec/seeders/root_seeder_standard_edition_spec.rb@@ -78,6 +78,7 @@ describe RootSeeder,)end+ include_examples 'it creates records', model: DocumentCategory, expected_count: 3include_examples 'it creates records', model: IssuePriority, expected_count: 4include_examples 'it creates records', model: Status, expected_count: 14include_examples 'it creates records', model: TimeEntryActivity, expected_count: 6