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
Unify settings reset spec helpers
Christophe Bliard0caadaf1dbc5
diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex 9db59465e77..6b5bcd7f436 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -190,7 +190,10 @@ module Settingsprivate- # Currently only required for testing+ # Currently only required for testing.+ #+ # Tag your test with :settings_reset to start test with fresh settings+ # definitions and restore them after test.def reset@all = nil@loaded = falsediff --git a/spec/constants/settings/definition_spec.rb b/spec/constants/settings/definition_spec.rbindex 08b84826a83..28a7a7b0574 100644--- a/spec/constants/settings/definition_spec.rb+++ b/spec/constants/settings/definition_spec.rb@@ -57,9 +57,7 @@ describe Settings::Definition do.to eq 20end- context 'when overriding from ENV' do- include_context 'with clean setting definitions'-+ context 'when overriding from ENV', :settings_reset dodef value_for(name)all.detect { |d| d.name == name }.valueend@@ -373,9 +371,7 @@ describe Settings::Definition doendend- context 'when overriding from file' do- include_context 'with clean setting definitions'-+ context 'when overriding from file', :settings_reset dolet(:file_contents) do<<~YAML---@@ -503,9 +499,7 @@ describe Settings::Definition doendend- context 'when adding an additional setting' do- include_context 'with clean setting definitions'-+ context 'when adding an additional setting', :settings_reset doit 'includes the setting' doall@@ -549,8 +543,7 @@ describe Settings::Definition doendend- context 'when adding a setting late' do- include_context 'with clean setting definitions'+ context 'when adding a setting late', :settings_reset dolet(:key) { 'bogus' }before do@@ -976,9 +969,7 @@ describe Settings::Definition doendend- describe '#on_change' do- include_context 'with clean setting definitions'-+ describe '#on_change', :settings_reset docontext 'for a definition with a callback' dolet(:callback) { -> { 'foobar ' } }diff --git a/spec/lib/open_project/feature_decisions_spec.rb b/spec/lib/open_project/feature_decisions_spec.rbindex acb835df827..bd193042299 100644--- a/spec/lib/open_project/feature_decisions_spec.rb+++ b/spec/lib/open_project/feature_decisions_spec.rb@@ -27,7 +27,7 @@# ++require 'spec_helper'-describe OpenProject::FeatureDecisions do+describe OpenProject::FeatureDecisions, :settings_reset dolet(:flag_name) { :example_flag }include_context 'with clean feature decisions'@@ -46,8 +46,6 @@ describe OpenProject::FeatureDecisions doendend- include_context 'with clean setting definitions'-describe '`flag_name`_active?' docontext 'without an ENV variable' doinclude_context 'when adding without env variable'diff --git a/spec/requests/api/v3/configuration_resource_spec.rb b/spec/requests/api/v3/configuration_resource_spec.rbindex 0291c08fcb5..faacac657d1 100644--- a/spec/requests/api/v3/configuration_resource_spec.rb+++ b/spec/requests/api/v3/configuration_resource_spec.rb@@ -70,9 +70,7 @@ describe 'API v3 Configuration resource', type: :request do.not_to have_json_path('_embedded/user_preferences')end- context 'with feature flags' do- include_context 'with clean setting definitions'-+ context 'with feature flags', :settings_reset dobefore dostub_const('ENV','OPENPROJECT_FEATURE_AN_EXAMPLE_ACTIVE' => 'true',diff --git a/spec/support/settings/clean_definitions.rb b/spec/support/settings/clean_definitions.rbdeleted file mode 100644index 9aff3a58868..00000000000--- a/spec/support/settings/clean_definitions.rb+++ /dev/null@@ -1,40 +0,0 @@-# --copyright-# OpenProject is an open source project management software.-# Copyright (C) 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.-# ++--RSpec.shared_context 'with clean setting definitions' do- let!(:definitions_before) { Settings::Definition.all.dup }-- before do- Settings::Definition.send(:reset)- end-- after do- Settings::Definition.send(:reset)- Settings::Definition.instance_variable_set(:@all, definitions_before)- end-enddiff --git a/spec/support/shared/with_settings.rb b/spec/support/shared/with_settings.rbindex b1c14e7633a..726007f0f5e 100644--- a/spec/support/shared/with_settings.rb+++ b/spec/support/shared/with_settings.rb@@ -39,11 +39,13 @@ def aggregate_mocked_settings(example, settings)endRSpec.shared_context 'with settings reset' do- around do |example|- definitions_before = Settings::Definition.all.dup+ let!(:definitions_before) { Settings::Definition.all.dup }++ before doSettings::Definition.send(:reset)- example.run- ensure+ end++ after doSettings::Definition.send(:reset)Settings::Definition.instance_variable_set(:@all, definitions_before)end