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
Add the WeekDaySeeder
Dombi Attilae7bbad61ec29
diff --git a/app/seeders/basic_data/week_day_seeder.rb b/app/seeders/basic_data/week_day_seeder.rbnew file mode 100644index 00000000000..81d98bd2858--- /dev/null+++ b/app/seeders/basic_data/week_day_seeder.rb@@ -0,0 +1,58 @@+#-- 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.+#+++module BasicData+ class WeekDaySeeder < Seeder+ def seed_data!+ WeekDay.transaction do+ days.each do |attributes|+ WeekDay.create!(attributes)+ end+ end+ end++ def applicable?+ WeekDay.none?+ end++ def not_applicable_message+ 'Skipping week days as there are already some configured'+ end++ def days+ [+ { day: 1, working: true },+ { day: 2, working: true },+ { day: 3, working: true },+ { day: 4, working: true },+ { day: 5, working: true },+ { day: 6, working: false },+ { day: 7, working: false }+ ]+ end+ end+enddiff --git a/app/seeders/standard_seeder/basic_data_seeder.rb b/app/seeders/standard_seeder/basic_data_seeder.rbindex 4ca670082c1..06a404f24b6 100644--- a/app/seeders/standard_seeder/basic_data_seeder.rb+++ b/app/seeders/standard_seeder/basic_data_seeder.rb@@ -31,6 +31,7 @@ module StandardSeeder[::BasicData::BuiltinRolesSeeder,::BasicData::RoleSeeder,+ ::BasicData::WeekDaySeeder,::StandardSeeder::BasicData::ActivitySeeder,::BasicData::ColorSeeder,::BasicData::ColorSchemeSeeder,diff --git a/spec/seeders/week_day_seeder_spec.rb b/spec/seeders/week_day_seeder_spec.rbnew file mode 100644index 00000000000..fc26f1c11e4--- /dev/null+++ b/spec/seeders/week_day_seeder_spec.rb@@ -0,0 +1,52 @@+#-- 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 'spec_helper'++describe ::BasicData::WeekDaySeeder do+ subject { described_class.new }++ before do+ subject.seed!+ end++ def reseed!+ subject.seed!+ end++ it 'creates the initial days' do+ WeekDay.destroy_all+ expect { reseed! }.to change { WeekDay.pluck(:day, :working) }+ .from([])+ .to([[1, true], [2, true], [3, true], [4, true], [5, true], [6, false], [7, false]])+ end++ it 'does not override existing days' do+ expect { reseed! }.not_to change { WeekDay.pluck(:day, :working) }+ end+end