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 migration to remove obsolete color variables and rename "alternative-color" to "primary-button-color"
Henriette Dargec2ba8ff5df70
diff --git a/db/migrate/20240307102541_reduce_configurable_design_variables.rb b/db/migrate/20240307102541_reduce_configurable_design_variables.rbnew file mode 100644index 00000000000..6654775aec3--- /dev/null+++ b/db/migrate/20240307102541_reduce_configurable_design_variables.rb@@ -0,0 +1,28 @@+class ReduceConfigurableDesignVariables < ActiveRecord::Migration[7.1]+ class MigrationDesignColor < ApplicationRecord+ self.table_name = 'design_colors'+ end++ def up+ # Delete "primary-color" and "primary-color-dark"+ MigrationDesignColor+ .where(variable: %w(primary-color primary-color-dark))+ .delete_all++ # Rename "alternative-color" to "primary-button-color"+ MigrationDesignColor+ .where(variable: 'alternative-color')+ .update(variable: 'primary-button-color')+ end++ def down+ MigrationDesignColor+ .create(variable: 'primary-color', hexcode: OpenProject::CustomStyles::ColorThemes::DEPRECATED_PRIMARY_COLOR)+ MigrationDesignColor+ .create(variable: 'primary-color-dark', hexcode: OpenProject::CustomStyles::ColorThemes::DEPRECATED_PRIMARY_DARK_COLOR)++ MigrationDesignColor+ .where(variable: 'primary-button-color')+ .update(variable: 'alternative-color')+ end+enddiff --git a/lib/open_project/custom_styles/color_themes.rb b/lib/open_project/custom_styles/color_themes.rbindex c624884f664..710979a836a 100644--- a/lib/open_project/custom_styles/color_themes.rb+++ b/lib/open_project/custom_styles/color_themes.rb@@ -33,6 +33,8 @@ module OpenProject::CustomStylesOpenProject::CustomStyles::ColorThemes::DEFAULT_THEME_NAME = 'OpenProject'.freezeDEPRECATED_ALTERNATIVE_COLOR = '#35C53F'.freeze+ DEPRECATED_PRIMARY_COLOR = '#1A67A3'.freeze+ DEPRECATED_PRIMARY_DARK_COLOR = '#175A8E'.freezePRIMER_PRIMARY_BUTTON_COLOR = '#1F883D'.freezeTHEMES = [diff --git a/spec/migrations/reduce_configurable_design_variables_spec.rb b/spec/migrations/reduce_configurable_design_variables_spec.rbnew file mode 100644index 00000000000..dc84d207a38--- /dev/null+++ b/spec/migrations/reduce_configurable_design_variables_spec.rb@@ -0,0 +1,71 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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'+require Rails.root.join("db/migrate/20240307102541_reduce_configurable_design_variables.rb")++RSpec.describe ReduceConfigurableDesignVariables, type: :model do+ context 'when migrating up' do+ before do+ create(:design_color, variable: 'alternative-color')+ create(:design_color, variable: 'primary-color')+ create(:design_color, variable: 'primary-color-dark')+ end++ # Silencing migration logs, since we are not interested in that during testing+ subject { ActiveRecord::Migration.suppress_messages { described_class.new.up } }++ it "removes the obsolete variables and renames 'alternative-color'" do+ expect { subject }+ .to change(DesignColor, :count).from(3).to(1)++ expect(DesignColor.first)+ .to have_attributes(variable: 'primary-button-color')+ end+ end++ context 'when migrating down' do+ before do+ create(:design_color, variable: 'primary-button-color')+ end++ # Silencing migration logs, since we are not interested in that during testing+ subject { ActiveRecord::Migration.suppress_messages { described_class.new.down } }++ it "re-creates the removed variables and reverts the renaming" do+ expect { subject }+ .to change(DesignColor, :count).from(1).to(3)++ expect(DesignColor.find_by(variable: 'primary-button-color')).to be_nil+ expect(DesignColor.find_by(variable: 'primary-color')).not_to be_nil+ expect(DesignColor.find_by(variable: 'primary-color-dark')).not_to be_nil+ expect(DesignColor.find_by(variable: 'alternative-color')).not_to be_nil++ end+ end+end