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 duration column to the work package table
Dombi Attilacc7c2fd3a5a0
diff --git a/app/models/queries/work_packages/filter/duration_filter.rb b/app/models/queries/work_packages/filter/duration_filter.rbindex 11e96a5c12f..694c3550da1 100644--- a/app/models/queries/work_packages/filter/duration_filter.rb+++ b/app/models/queries/work_packages/filter/duration_filter.rb@@ -34,9 +34,19 @@ class Queries::WorkPackages::Filter::DurationFilter <def whereif operator == Queries::Operators::None.to_sym.to_s- super + " OR #{WorkPackage.table_name}.duration=0"+ <<~SQL.squish+ #{super}+ OR #{WorkPackage.table_name}.duration = 0+ OR #{Type.table_name}.is_milestone = TRUE+ SQLelse- super+ <<~SQL.squish+ #{super} AND #{Type.table_name}.is_milestone = FALSE+ SQLendend++ def joins+ :type+ endenddiff --git a/app/models/work_package.rb b/app/models/work_package.rbindex 376c5a51719..8ad49eb96c3 100644--- a/app/models/work_package.rb+++ b/app/models/work_package.rb@@ -271,7 +271,7 @@ class WorkPackage < ApplicationRecord# Returns true if the work_package is overduedef overdue?- !due_date.nil? && (due_date < Date.today) && !closed?+ !due_date.nil? && (due_date < Time.zone.today) && !closed?enddef milestone?@@ -287,9 +287,13 @@ class WorkPackage < ApplicationRecordendend- def estimated_hours=(h)- converted_hours = (h.is_a?(String) ? h.to_hours : h)- write_attribute :estimated_hours, !!converted_hours ? converted_hours : h+ def estimated_hours=(hours)+ converted_hours = (hours.is_a?(String) ? hours.to_hours : hours)+ write_attribute :estimated_hours, !!converted_hours ? converted_hours : hours+ end++ def duration_in_hours+ duration ? duration * 24 : nilend# aliasing subject to name@@ -460,7 +464,7 @@ class WorkPackage < ApplicationRecordreturn if time_entry_blank?(attributes)attributes.reverse_merge!(user:,- spent_on: Date.today)+ spent_on: Time.zone.today)time_entries.build(attributes)end@@ -474,7 +478,7 @@ class WorkPackage < ApplicationRecordkey = 'activity_id'id = attributes[key]- default_id = if id && id.present?+ default_id = if id&.present?Enumeration.exists? id: id, is_default: true, type: 'TimeEntryActivity'elsetruediff --git a/config/constants/settings/definitions.rb b/config/constants/settings/definitions.rbindex 769d6076f60..74ff6cdd6a5 100644--- a/config/constants/settings/definitions.rb+++ b/config/constants/settings/definitions.rb@@ -979,6 +979,10 @@ Settings::Definition.define doadd :work_package_startdate_is_adddate,default: false+ add :work_packages_duration_field_active,+ default: Rails.env.development?,+ format: :boolean+add :youtube_channel,default: 'https://www.youtube.com/c/OpenProjectCommunity',writable: falsediff --git a/docs/api/apiv3/components/schemas/work_package_model.yml b/docs/api/apiv3/components/schemas/work_package_model.ymlindex 8444f00a33f..3393766098c 100644--- a/docs/api/apiv3/components/schemas/work_package_model.yml+++ b/docs/api/apiv3/components/schemas/work_package_model.yml@@ -55,6 +55,13 @@ properties:by the work packages's descendants. If manual scheduleManually is active, thetwo dates can deviate.readOnly: true+ duration:+ type: string+ format: duration+ description: |-+ **(NOT IMPLEMENTED)** The amount of time in hours the work package needs to be completed.+ Not available for milestone type of work packages.+ readOnly: trueestimatedTime:type: stringformat: durationdiff --git a/docs/api/apiv3/paths/work_packages.yml b/docs/api/apiv3/paths/work_packages.ymlindex 0c5e310f3ef..3f74a3d8167 100644--- a/docs/api/apiv3/paths/work_packages.yml+++ b/docs/api/apiv3/paths/work_packages.yml@@ -46,6 +46,7 @@ get:- due_date- duplicated- duplicates+ - duration- estimated_hours- file_link_origin_id- followsdiff --git a/lib/api/v3/work_packages/schema/work_package_schema_representer.rb b/lib/api/v3/work_packages/schema/work_package_schema_representer.rbindex 1cda6e9c543..ff36ecf4216 100644--- a/lib/api/v3/work_packages/schema/work_package_schema_representer.rb+++ b/lib/api/v3/work_packages/schema/work_package_schema_representer.rb@@ -117,6 +117,18 @@ module APItype: 'Formattable',required: false+ schema :duration,+ type: 'Duration',+ required: false,+ writable: false,+ show_if: ->(*) { !represented.milestone? && OpenProject::FeatureDecisions.work_packages_duration_field_active? }++ # TODO: Remove this, once the duration feature is complete+ # This enables hiding the duration field on the form_configuration+ ::Type.add_constraint :duration, ->(*) {+ OpenProject::FeatureDecisions.work_packages_duration_field_active?+ }+schema :schedule_manually,type: 'Boolean',required: false,diff --git a/lib/api/v3/work_packages/work_package_payload_representer.rb b/lib/api/v3/work_packages/work_package_payload_representer.rbindex df9edd8149b..8293edf578f 100644--- a/lib/api/v3/work_packages/work_package_payload_representer.rb+++ b/lib/api/v3/work_packages/work_package_payload_representer.rb@@ -36,7 +36,13 @@ module APIcached_representer disabled: truedef writeable_attributes- super + %w[date]+ attributes = super+ # TODO: Remove this, once the duration feature is complete+ # We have to remove the duration field as it is not being accepted yet.+ if OpenProject::FeatureDecisions.work_packages_duration_field_active?+ attributes -= %w[duration]+ end+ attributes + %w[date]enddef load_complete_model(model)diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rbindex e9f460fec40..e70c9c2ad51 100644--- a/lib/api/v3/work_packages/work_package_representer.rb+++ b/lib/api/v3/work_packages/work_package_representer.rb@@ -391,6 +391,17 @@ module APIend,render_nil: true+ property :duration,+ exec_context: :decorator,+ skip_render: ->(represented:, **) {+ represented.milestone? || !OpenProject::FeatureDecisions.work_packages_duration_field_active?+ },+ getter: ->(*) do+ datetime_formatter.format_duration_from_hours(represented.duration_in_hours,+ allow_nil: true)+ end,+ render_nil: true+property :spent_time,exec_context: :decorator,getter: ->(*) dodiff --git a/lib/open_project/feature_decisions.rb b/lib/open_project/feature_decisions.rbindex a3b49b1f482..1cf3082126b 100644--- a/lib/open_project/feature_decisions.rb+++ b/lib/open_project/feature_decisions.rb@@ -31,5 +31,9 @@ module OpenProjectdef self.storages_module_active?Setting.feature_storages_module_activeend++ def self.work_packages_duration_field_active?+ Setting.work_packages_duration_field_active+ endendenddiff --git a/spec/factories/type_factory.rb b/spec/factories/type_factory.rbindex 17dde98734f..5530e7e27d2 100644--- a/spec/factories/type_factory.rb+++ b/spec/factories/type_factory.rb@@ -31,8 +31,8 @@ FactoryBot.define dosequence(:position)name { |a| "Type No. #{a.position}" }description { nil }- created_at { Time.now }- updated_at { Time.now }+ created_at { Time.zone.now }+ updated_at { Time.zone.now }factory :type_with_workflow, class: 'Type' docallback(:after_build) do |t|@@ -53,21 +53,25 @@ FactoryBot.define do["query_#{query.id}".to_sym]]]endend++ factory :type_milestone, class: 'Type' do+ is_milestone { true }+ endendfactory :type_standard, class: '::Type' doname { 'None' }is_standard { true }is_default { true }- created_at { Time.now }- updated_at { Time.now }+ created_at { Time.zone.now }+ updated_at { Time.zone.now }endfactory :type_bug, class: '::Type' doname { 'Bug' }position { 1 }- created_at { Time.now }- updated_at { Time.now }+ created_at { Time.zone.now }+ updated_at { Time.zone.now }# reuse existing type with the given name# this prevents a validation error (name has to be unique)diff --git a/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb b/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rbindex 8101bcd48b4..1e6382424ce 100644--- a/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb+++ b/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb@@ -97,7 +97,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter doallow(schema).to receive(:writable?).and_call_originalend- context 'generation' do+ context 'for generation' dosubject(:generated) { representer.to_json }shared_examples_for 'has a collection of allowed values' do@@ -152,7 +152,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter dolet(:link) { 'baseSchema' }end- context 'embedded in a form' do+ context 'when embedded in a form' dolet(:self_link) { nil }let(:base_schema_link) { '/a/schema/link' }@@ -243,7 +243,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter dolet(:writable) { true }end- context 'lockVersion disabled' do+ context 'when lockVersion disabled' dolet(:representer) dodescribed_class.create(schema,self_link: nil,@@ -293,6 +293,50 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter doendend+ describe 'duration' do+ before do+ # TODO: remove feature flag once the implementation is complete+ allow(OpenProject::FeatureDecisions)+ .to receive(:work_packages_duration_field_active?)+ .and_return(true)+ allow(schema)+ .to receive(:milestone?)+ .and_return(false)+ end++ it_behaves_like 'has basic schema properties' do+ let(:path) { 'duration' }+ let(:type) { 'Duration' }+ let(:name) { I18n.t('activerecord.attributes.work_package.duration') }+ let(:required) { false }+ let(:writable) { false }+ end++ context 'when the work package is a milestone' do+ before do+ allow(schema)+ .to receive(:milestone?)+ .and_return(true)+ end++ it 'has no duration attribute' do+ expect(subject).not_to have_json_path('duration')+ end+ end++ context 'when the feature flag is off' do+ before do+ allow(OpenProject::FeatureDecisions)+ .to receive(:work_packages_duration_field_active?)+ .and_return(false)+ end++ it 'has no duration attribute' do+ expect(subject).not_to have_json_path('duration')+ end+ end+ end+describe 'scheduleManually' doit_behaves_like 'has basic schema properties' dolet(:path) { 'scheduleManually' }@@ -324,7 +368,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter dolet(:writable) { true }end- context 'not writable' do+ context 'when not writable' dobefore doallow(schema).to receive(:writable?)@@ -374,7 +418,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter dolet(:writable) { true }end- context 'not writable' do+ context 'when not writable' dobefore doallow(schema).to receive(:writable?)@@ -424,7 +468,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter dolet(:writable) { true }end- context 'not writable' do+ context 'when not writable' dobefore doallow(schema).to receive(:writable?).with(:due_date).and_return falseend@@ -519,7 +563,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter dolet(:writable) { true }end- context 'not writable' do+ context 'when not writable' dobefore doallow(schema).to receive(:writable?)@@ -592,7 +636,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter dolet(:writable) { true }end- context 'not writable' do+ context 'when not writable' dobefore doallow(schema).to receive(:writable?).with(:percentage_done).and_return falseend@@ -606,7 +650,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter doendend- context 'is disabled' do+ context 'as disabled' dobefore doallow(Setting).to receive(:work_package_done_ratio).and_return('disabled')end@@ -839,7 +883,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter dolet(:factory) { :priority }end- context 'not writable' do+ context 'when not writable' dobefore doallow(schema).to receive(:writable?).with(:priority).and_return falseend@@ -929,7 +973,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter doenddescribe 'budget' do- context 'user allowed to view_budgets' do+ context 'when user allowed to view_budgets' dolet(:permissions) { %i[edit_work_packages view_budgets] }it_behaves_like 'has basic schema properties' do@@ -948,7 +992,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter doendend- context 'user not allowed to view_budgets' do+ context 'when user not allowed to view_budgets' doit 'has no schema for budget' doexpect(subject).not_to have_json_path('budget')end@@ -959,9 +1003,11 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter dolet(:available_custom_fields) { [build_stubbed(:int_wp_custom_field)] }it 'uses a CustomFieldInjector' do- expect(::API::V3::Utilities::CustomFieldInjector).to receive(:create_schema_representer)+ allow(::API::V3::Utilities::CustomFieldInjector).to receive(:create_schema_representer).and_return(described_class)representer.to_json++ expect(::API::V3::Utilities::CustomFieldInjector).to have_received(:create_schema_representer)endendend@@ -972,10 +1018,12 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter dolet(:attribute_groups) { [] }it 'is disabled' do- expect(OpenProject::Cache)- .not_to receive(:fetch)+ allow(OpenProject::Cache).to receive(:fetch)representer.to_json++ expect(OpenProject::Cache)+ .not_to have_received(:fetch)endend@@ -1002,12 +1050,16 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter doendit 'is based on the representer\'s cache_key' do- expect(OpenProject::Cache)+ allow(OpenProject::Cache).to receive(:fetch).with(representer.json_cache_key).and_call_originalrepresenter.to_json++ expect(OpenProject::Cache)+ .to have_received(:fetch)+ .with(representer.json_cache_key)endit 'does not cache the attribute_groups' do@@ -1038,7 +1090,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter dochangeend- let(:setup) {}+ let(:setup) { nil }let(:original_cache_key) { joined_cache_key }shared_examples_for 'changes' do@@ -1051,7 +1103,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter doendend- context 'for a different type' do+ context 'for a different project' doit_behaves_like 'changes' dolet(:change) { work_package.project = build_stubbed(:project) }enddiff --git a/spec/lib/api/v3/work_packages/work_package_payload_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_payload_representer_spec.rbindex 20e5cb6105b..afacb57ddd0 100644--- a/spec/lib/api/v3/work_packages/work_package_payload_representer_spec.rb+++ b/spec/lib/api/v3/work_packages/work_package_payload_representer_spec.rb@@ -33,8 +33,8 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter dolet(:work_package) dobuild_stubbed(:work_package,- start_date: Date.today.to_datetime,- due_date: Date.today.to_datetime,+ start_date: Time.zone.today.to_datetime,+ due_date: Time.zone.today.to_datetime,created_at: DateTime.now,updated_at: DateTime.now,budget:,@@ -55,7 +55,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter dolet(:budget) { build_stubbed(:budget) }let(:representer) do- ::API::V3::WorkPackages::WorkPackagePayloadRepresenter+ described_class.create(work_package, current_user: user)end@@ -67,7 +67,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter do.and_return(1)end- context 'generation' do+ context 'for generation' dosubject(:generated) { representer.to_json }describe 'work_package' do@@ -76,7 +76,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter doit_behaves_like 'API V3 formattable', 'description' dolet(:format) { 'markdown' }let(:raw) { work_package.description }- let(:html) { '<p class="op-uc-p">' + work_package.description + '</p>' }+ let(:html) { "<p class=\"op-uc-p\">#{work_package.description}</p>" }enddescribe 'lock version' do@@ -115,11 +115,11 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter do.at_path('estimatedTime')end- context 'not set' do+ context 'when not set' doit { is_expected.to have_json_type(NilClass).at_path('estimatedTime') }end- context 'set' do+ context 'when set' dolet(:work_package) { build(:work_package, estimated_hours: 0) }it { is_expected.to have_json_type(String).at_path('estimatedTime') }@@ -133,7 +133,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter do.and_return(true)end- context 'percentage done enabled' do+ context 'when percentage done enabled' doit { is_expected.to have_json_path('percentageDone') }it { is_expected.to have_json_type(Integer).at_path('percentageDone') }@@ -143,7 +143,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter doend%w(disabled status).each do |setting|- context "work package done ratio setting on #{setting}" do+ context "when work package done ratio setting on #{setting}" dobefore doallow(Setting).to receive(:work_package_done_ratio).and_return(setting)end@@ -171,7 +171,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter dolet(:json_path) { 'startDate' }end- context 'no start date' do+ context 'with no start date' dolet(:work_package) { build(:work_package, start_date: nil) }it 'renders as null' do@@ -179,7 +179,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter doendend- context 'if the work_package is a milestone' do+ context 'when the work_package is a milestone' dobefore doallow(work_package).to receive(:milestone?)@@ -208,7 +208,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter dolet(:json_path) { 'dueDate' }end- context 'no finish date' do+ context 'when no finish date' dolet(:work_package) { build(:work_package, due_date: nil) }it 'renders as null' do@@ -216,7 +216,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter doendend- context 'if the work_package is a milestone' do+ context 'when the work_package is a milestone' dobefore doallow(work_package).to receive(:milestone?)@@ -245,7 +245,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter dolet(:json_path) { 'date' }end- context 'no finish date' do+ context 'when no finish date' dolet(:work_package) dobuild_stubbed(:work_package,type: build_stubbed(:type),@@ -257,7 +257,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter doendend- context 'if the work_package is no milestone' do+ context 'when the work_package is no milestone' dobefore doallow(work_package).to receive(:milestone?)@@ -269,6 +269,32 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter doendendend++ describe 'duration' do+ before do+ allow(OpenProject::FeatureDecisions)+ .to receive(:work_packages_duration_field_active?)+ .and_return(true)+ end++ it 'has no duration attribute' do+ # TODO: Remove this, once the duration feature is complete+ expect(subject).not_to have_json_path('duration')+ end++ context 'when duration feature flag disabled' do+ before do+ allow(OpenProject::FeatureDecisions)+ .to receive(:work_packages_duration_field_active?)+ .and_return(false)+ end++ it 'has no duration attribute' do+ # TODO: Remove this, once the duration feature is complete+ expect(subject).not_to have_json_path('duration')+ end+ end+ endenddescribe '_links' do@@ -450,9 +476,10 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter dolet(:available_custom_fields) { [build_stubbed(:int_wp_custom_field)] }it 'uses a CustomFieldInjector' do- expect(::API::V3::Utilities::CustomFieldInjector).to receive(:create_value_representer)+ allow(::API::V3::Utilities::CustomFieldInjector).to receive(:create_value_representer).and_call_originalrepresenter.to_json+ expect(::API::V3::Utilities::CustomFieldInjector).to have_received(:create_value_representer)endend@@ -460,10 +487,13 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter doit 'does not cache' dorepresenter.to_json- expect(Rails.cache)- .not_to receive(:fetch)+ allow(Rails.cache)+ .to receive(:fetch)representer.to_json++ expect(Rails.cache)+ .not_to have_received(:fetch)endendend@@ -476,21 +506,19 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter docopy[:_links] = linkscopy.to_jsonend- let(:work_package) do- OpenStruct.new available_custom_fields:- end+ let(:work_package) { WorkPackage.new }subject { representer.from_json(json) }shared_examples_for 'settable ISO 8601 date only' dolet(:attributes) do{- property => dateString+ property => date_string}endcontext 'with an ISO formatted date' do- let(:dateString) { '2015-01-31' }+ let(:date_string) { '2015-01-31' }it 'sets the date' doexpect(subject.send(method)).to eql(Date.new(2015, 1, 31))@@ -498,7 +526,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter doendcontext 'with null' do- let(:dateString) { nil }+ let(:date_string) { nil }it 'sets the date to nil' doexpect(subject.send(method)).to be_nil@@ -506,7 +534,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter doendcontext 'with a non ISO formatted date' do- let(:dateString) { '31.01.2015' }+ let(:date_string) { '31.01.2015' }it 'raises an error' doexpect { subject }.to raise_error(API::Errors::PropertyFormatError)@@ -514,7 +542,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter doendcontext 'with an ISO formatted date and time' do- let(:dateString) { '2015-01-31T13:37:00Z' }+ let(:date_string) { '2015-01-31T13:37:00Z' }it 'raises an error' doexpect { subject }.to raise_error(API::Errors::PropertyFormatError)@@ -565,7 +593,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter do.and_return(true)# Setting values to ensure they are later set to nil in one of the test cases- work_package.start_date = work_package.due_date = Date.today+ work_package.start_date = work_package.due_date = Time.zone.todayendit_behaves_like 'settable ISO 8601 date only' do@@ -573,7 +601,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter dolet(:method) { :due_date }context 'with an ISO formatted date' do- let(:dateString) { '2015-01-31' }+ let(:date_string) { '2015-01-31' }it 'sets the start and the due_date' doexpect(subject.start_date).to eql(Date.new(2015, 1, 31))@@ -585,7 +613,7 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter doshared_examples_for 'linked resource' dolet(:path) { api_v3_paths.send(attribute_name, id) }- let(:association_name) { attribute_name + '_id' }+ let(:association_name) { "#{attribute_name}_id" }let(:id) { work_package.send(association_name).to_i + 1 }let(:links) do{ attribute_name => href }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 b00562d6c59..df0ebb1a0d6 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@@ -52,11 +52,13 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter dolet(:derived_start_date) { Time.zone.today - 4.days }let(:derived_due_date) { Time.zone.today - 5.days }let(:budget) { build_stubbed(:budget, project:) }+ let(:duration) { nil }let(:work_package) dobuild_stubbed(:work_package,schedule_manually:,start_date:,due_date:,+ duration:,done_ratio: 50,parent:,type:,@@ -295,6 +297,49 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter doendend+ describe 'duration' do+ let(:duration) { 6 }++ before do+ # TODO: remove feature flag once the implementation is complete+ allow(OpenProject::FeatureDecisions)+ .to receive(:work_packages_duration_field_active?)+ .and_return(true)+ end++ it { is_expected.to be_json_eql('P6D'.to_json).at_path('duration') }++ context 'no duration' do+ let(:duration) { nil }++ it 'renders as null' do+ is_expected.to be_json_eql(nil.to_json).at_path('duration')+ end+ end++ context 'when the work_package is a milestone' do+ let(:type_milestone) { true }++ it 'has no duration' do+ is_expected.to_not have_json_path('duration')+ end+ end++ context 'when the feature flag is off' do+ before do+ # TODO: remove feature flag once the implementation is complete+ allow(OpenProject::FeatureDecisions)+ .to receive(:work_packages_duration_field_active?)+ .and_return(false)+ end+ let(:duration) { 6 }++ it 'has no duration' do+ is_expected.to_not have_json_path('duration')+ end+ end+ end+describe 'createdAt' doit_behaves_like 'has UTC ISO 8601 date and time' dolet(:date) { work_package.created_at }diff --git a/spec/models/queries/work_packages/filter/duration_filter_spec.rb b/spec/models/queries/work_packages/filter/duration_filter_spec.rbindex c996117d44d..575da1b1bb6 100644--- a/spec/models/queries/work_packages/filter/duration_filter_spec.rb+++ b/spec/models/queries/work_packages/filter/duration_filter_spec.rb@@ -51,16 +51,24 @@ describe Queries::WorkPackages::Filter::DurationFilter, type: :model dolet!(:work_package_zero_duration) { create(:work_package, duration: 0) }let!(:work_package_no_duration) { create(:work_package, duration: nil) }let!(:work_package_with_duration) { create(:work_package, duration: 1) }+ let!(:work_package_with_milestone) { create(:work_package, duration: 1, type: create(:type_milestone)) }+ let(:values) { [1] }++ subject { WorkPackage.joins(instance.joins).where(instance.where) }context 'with the operator being "none"' dobefore doinstance.operator = Queries::Operators::None.to_sym.to_send- it 'finds zero and none values' do- expect(WorkPackage.where(instance.where)).to match_array [work_package_zero_duration, work_package_no_duration]+ it 'finds zero and none values also including milestones' do+ expect(subject).to match_array [work_package_zero_duration, work_package_no_duration, work_package_with_milestone]endend++ it 'does not returns milestone work packages' do+ expect(subject).to match_array [work_package_with_duration]+ endendendenddiff --git a/spec/models/type_spec.rb b/spec/models/type_spec.rbindex de27e715095..45fb9fca9da 100644--- a/spec/models/type_spec.rb+++ b/spec/models/type_spec.rb@@ -47,7 +47,7 @@ describe ::Type, type: :model doenddescribe '.statuses' do- let(:subject) { type.statuses }+ subject { type.statuses }context 'when new' dolet(:type) { build(:type) }@@ -85,7 +85,8 @@ describe ::Type, type: :model docontext 'with default status' dolet!(:default_status) { create(:default_status) }- let(:subject) { type.statuses(include_default: true) }++ subject { type.statuses(include_default: true) }it 'returns the workflow and the default status' doexpect(subject.pluck(:id)).to contain_exactly(default_status.id, statuses[0].id, statuses[1].id)@@ -108,4 +109,30 @@ describe ::Type, type: :model do.with(type2, nil, type, nil)endend++ describe '#work_package_attributes' do+ subject { type.work_package_attributes }++ before do+ allow(OpenProject::FeatureDecisions)+ .to receive(:work_packages_duration_field_active?)+ .and_return(true)+ end++ it 'returns the duration field' do+ expect(subject).to have_key("duration")+ end++ context 'when the feature flag is off' do+ before do+ allow(OpenProject::FeatureDecisions)+ .to receive(:work_packages_duration_field_active?)+ .and_return(false)+ end++ it 'does not return the duration field' do+ expect(subject).not_to have_key("duration")+ end+ end+ endend