Skip to content

Commit

Permalink
Ensure remaining_hours isn't writable on "status-based" mode
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-contreras committed Feb 28, 2024
1 parent 0de6171 commit 5806625
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ def initialize(schema, self_link:, **context)
schema :remaining_time,
name_source: :remaining_hours,
type: 'Duration',
required: false
required: false,
writable: ->(*) { !WorkPackage.use_status_for_done_ratio? }

schema :derived_remaining_time,
name_source: :derived_remaining_hours,
type: 'Duration',
required: false
required: false,
writable: false

schema :spent_time,
type: 'Duration',
Expand Down
2 changes: 2 additions & 0 deletions lib/api/v3/work_packages/work_package_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ def self_v3_path(*)
datetime_formatter.format_duration_from_hours(represented.remaining_hours,
allow_nil: true)
end,
writable: ->(*) { !WorkPackage.use_status_for_done_ratio? },
render_nil: true

property :derived_remaining_time,
Expand All @@ -417,6 +418,7 @@ def self_v3_path(*)
datetime_formatter.format_duration_from_hours(represented.derived_remaining_hours,
allow_nil: true)
end,
writable: ->(*) { !WorkPackage.use_status_for_done_ratio? },
render_nil: true

property :duration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,17 @@
let(:required) { false }
let(:writable) { true }
end

context 'when on the "status-based" % complete mode',
with_settings: { work_package_done_ratio: 'status' } do
it_behaves_like 'has basic schema properties' do
let(:path) { 'remainingTime' }
let(:type) { 'Duration' }
let(:name) { I18n.t('activerecord.attributes.work_package.remaining_hours') }
let(:required) { false }
let(:writable) { false }
end
end
end

describe 'derivedRemainingTime' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@
end
end

describe 'remaining hours' do
it { is_expected.to have_json_path('remainingTime') }

it do
expect(subject).to be_json_eql(work_package.estimated_hours.to_json)
.at_path('estimatedTime')
end

context 'when not set' do
it { is_expected.to have_json_type(NilClass).at_path('estimatedTime') }
end

context 'when set' do
let(:work_package) { build(:work_package, estimated_hours: 7, remaining_hours: 5) }

it { is_expected.to have_json_type(String).at_path('estimatedTime') }
end
end

describe 'startDate' do
before do
allow(work_package)
Expand Down

0 comments on commit 5806625

Please sign in to comment.