Merge pull request #2277 from opf/hotfix/17228_handle_fractional_hours

17228 handle fractional hours
pull/2267/merge
ulferts 10 years ago
commit 3c86e3f1c5
  1. 19
      lib/api/v3/work_packages/work_package_representer.rb
  2. 17
      spec/lib/api/v3/work_packages/work_package_representer_spec.rb

@ -224,11 +224,17 @@ module API
property :start_date, getter: -> (*) { model.start_date.to_datetime.utc.iso8601 unless model.start_date.nil? }, render_nil: true, writeable: false
property :due_date, getter: -> (*) { model.due_date.to_datetime.utc.iso8601 unless model.due_date.nil? }, render_nil: true, writeable: false
property :estimated_time,
getter: -> (*) { Duration.new(hours: model.estimated_hours).iso8601 },
exec_context: :decorator,
getter: -> (*) {
Duration.new(hours_and_minutes(represented.model.estimated_hours)).iso8601
},
render_nil: true,
writeable: false
property :spent_time,
getter: -> (*) { Duration.new(hours: model.spent_hours).iso8601 },
exec_context: :decorator,
getter: -> (*) {
Duration.new(hours_and_minutes(represented.model.spent_hours)).iso8601
},
writeable: false
property :percentage_done,
render_nil: true,
@ -287,6 +293,15 @@ module API
def percentage_done
represented.percentage_done unless Setting.work_package_done_ratio == 'disabled'
end
private
def hours_and_minutes(hours)
hours = hours.to_f
minutes = (hours - hours.to_i) * 60
{ hours: hours.to_i, minutes: minutes }
end
end
end
end

@ -40,8 +40,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
created_at: DateTime.now,
updated_at: DateTime.now,
category: category,
done_ratio: 50,
estimated_hours: 6.0
done_ratio: 50
)
}
let(:category) { FactoryGirl.build(:category) }
@ -91,7 +90,15 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
describe 'estimatedTime' do
it { is_expected.to be_json_eql('PT6H'.to_json).at_path('estimatedTime') }
let(:work_package) {
FactoryGirl.build(:work_package,
id: 42,
created_at: DateTime.now,
updated_at: DateTime.now,
estimated_hours: 6.5)
}
it { is_expected.to be_json_eql('PT6H30M'.to_json).at_path('estimatedTime') }
end
describe 'spentTime' do
@ -132,12 +139,12 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
FactoryGirl.create(:time_entry,
project: wp.project,
work_package: wp,
hours: 42.0)
hours: 42.5)
}
before { time_entry }
it { is_expected.to be_json_eql('P1DT18H'.to_json).at_path('spentTime') }
it { is_expected.to be_json_eql('P1DT18H30M'.to_json).at_path('spentTime') }
end
end
end

Loading…
Cancel
Save