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
introduce with_flag spec helper
ulferts369ea5578b86
diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rbindex 97c3d30b918..0ec5dbb8212 100644--- a/lib/api/v3/work_packages/work_package_representer.rb+++ b/lib/api/v3/work_packages/work_package_representer.rb@@ -393,8 +393,8 @@ module APIproperty :duration,exec_context: :decorator,- skip_render: ->(represented:, **) {- represented.milestone? || !OpenProject::FeatureDecisions.work_packages_duration_field_active?+ if: ->(represented:, **) {+ !represented.milestone? && OpenProject::FeatureDecisions.work_packages_duration_field_active?},getter: ->(*) dodatetime_formatter.format_duration_from_hours(represented.duration_in_hours,diff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rbindex 3d907ee5064..5252b265f6c 100644--- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb+++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb@@ -299,16 +299,8 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter doendend- describe 'duration' do+ describe 'duration', with_flag: { work_packages_duration_field_active: true } dolet(:duration) { 6 }- let(:feature_active) { true }-- before do- # TODO: remove feature flag once the implementation is complete- allow(OpenProject::FeatureDecisions)- .to receive(:work_packages_duration_field_active?)- .and_return(feature_active)- endit { is_expected.to be_json_eql('P6D'.to_json).at_path('duration') }@@ -328,26 +320,15 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter doendend- context 'when the feature flag is off' do- let(:feature_active) { false }- let(:duration) { 6 }-+ context 'when the feature flag is off', with_flag: { work_packages_duration_field_active: false } doit 'has no duration' dois_expected.to_not have_json_path('duration')endendend- describe 'ignoreNonWorkingDays' do+ describe 'ignoreNonWorkingDays', with_flag: { work_packages_duration_field_active: true } dolet(:ignore_non_working_days) { true }- let(:feature_active) { true }-- before do- # TODO: remove feature flag once the implementation is complete- allow(OpenProject::FeatureDecisions)- .to receive(:work_packages_duration_field_active?)- .and_return(feature_active)- endcontext 'with the value being `true`' doit { is_expected.to be_json_eql(true.to_json).at_path('ignoreNonWorkingDays') }@@ -359,9 +340,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter doit { is_expected.to be_json_eql(false.to_json).at_path('ignoreNonWorkingDays') }end- context 'when the feature flag is off' do- let(:feature_active) { false }-+ context 'when the feature flag is off', with_flag: { work_packages_duration_field_active: false } doit 'has no ignoreNonWorkingDays' dois_expected.to_not have_json_path('ignoreNonWorkingDays')enddiff --git a/spec/models/type_spec.rb b/spec/models/type_spec.rbindex add1dc7b554..ae45715e472 100644--- a/spec/models/type_spec.rb+++ b/spec/models/type_spec.rb@@ -113,36 +113,24 @@ describe ::Type, type: :model dodescribe '#work_package_attributes' dosubject { type.work_package_attributes }- let(:duration_field_active) { true }-- before do- allow(OpenProject::FeatureDecisions)- .to receive(:work_packages_duration_field_active?)- .and_return(true)- end-- context 'for the duration field' do+ context 'for the duration field', with_flag: { work_packages_duration_field_active: true } doit 'does not return true field' doexpect(subject).not_to have_key("duration")end- context 'when the feature flag is off' do- let(:duration_field_active) { true }-+ context 'when the feature flag is off', with_flag: { work_packages_duration_field_active: false } doit 'does not return the field' doexpect(subject).not_to have_key("duration")endendend- context 'for the ignore_non_working_days field' do+ context 'for the ignore_non_working_days field', with_flag: { work_packages_duration_field_active: true } doit 'does not return duration' doexpect(subject).not_to have_key("ignore_non_working_days")end- context 'when the feature flag is off' do- let(:duration_field_active) { true }-+ context 'when the feature flag is off', with_flag: { work_packages_duration_field_active: false } doit 'does not return the duration field' doexpect(subject).not_to have_key("ignore_non_working_days")enddiff --git a/spec/support/shared/with_flag.rb b/spec/support/shared/with_flag.rbnew file mode 100644index 00000000000..24ad8534e81--- /dev/null+++ b/spec/support/shared/with_flag.rb@@ -0,0 +1,51 @@+# OpenProject is an open source project management software.+# Copyright (C) 2010-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 WithFlagMixin+ module_function++ def with_flags(flags)+ flags.each do |k, value|+ name = k.end_with?('?') ? k : "#{k}?"++ raise "#{k} is not a valid flag" unless OpenProject::FeatureDecisions.respond_to?(name)++ allow(OpenProject::FeatureDecisions).to receive(name).and_return value+ end+ end+end++RSpec.configure do |config|+ config.include WithFlagMixin++ config.before do |example|+ flags = example.metadata[:with_flag]++ if flags.present?+ with_flags(flags)+ end+ end+end