Merge pull request #118 from finnlabs/hotfix/17228_handle_fractional_hours

17228 handle fractional hours
pull/6827/head
Alex Coles 10 years ago
commit 22166f2b5b
  1. 2
      lib/open_project/costs/engine.rb
  2. 34
      spec/lib/api/v3/work_packages/work_package_representer_spec.rb

@ -147,7 +147,7 @@ module OpenProject::Costs
end
send(:define_method, :spent_hours) do
self.attributes_helper.time_entries_sum
Duration.new(hours_and_minutes(self.attributes_helper.time_entries_sum)).iso8601
end
send(:define_method, :current_user_allowed_to_view_spent_hours) do

@ -75,6 +75,40 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
it { should have_json_path('_embedded/summarizedCostEntries') }
end
describe 'spentHours' do
describe :content do
context 'no time entry' do
it { is_expected.to be_json_eql('PT0S'.to_json).at_path('spentHours') }
end
context 'time entry with single hour' do
let(:time_entry) {
FactoryGirl.create(:time_entry,
project: work_package.project,
work_package: work_package,
hours: 1.0)
}
before { time_entry }
it { is_expected.to be_json_eql('PT1H'.to_json).at_path('spentHours') }
end
context 'time entry with multiple hours' do
let(:time_entry) {
FactoryGirl.create(:time_entry,
project: work_package.project,
work_package: work_package,
hours: 42.5)
}
before { time_entry }
it { is_expected.to be_json_eql('P1DT18H30M'.to_json).at_path('spentHours') }
end
end
end
end
end

Loading…
Cancel
Save