04_add_remaining_time_to_version.patch

Marius BALTEANU, 2016-11-12 19:53

Download (3.62 KB)

View differences:

app/models/version.rb
89 89
    @estimated_hours ||= fixed_issues.sum(:estimated_hours).to_f
90 90
  end
91 91

  
92
  # Returns the total remaining time for this version
93
  # (sum of leaves remaining_hours)
94
  def remaining_hours
95
    @remaining_hours ||= fixed_issues.sum(:remaining_hours).to_f
96
  end
97

  
92 98
  # Returns the total reported time for this version
93 99
  def spent_hours
94 100
    @spent_hours ||= TimeEntry.joins(:issue).where("#{Issue.table_name}.fixed_version_id = ?", id).sum(:hours).to_f
app/views/versions/show.html.erb
19 19
    <th><%= l(:field_estimated_hours) %></th>
20 20
    <td class="total-hours"><%= html_hours(l_hours(@version.estimated_hours)) %></td>
21 21
</tr>
22
<tr>
23
    <th><%= l(:field_remaining_hours) %></th>
24
    <td class="total-hours"><%= html_hours(l_hours(@version.remaining_hours)) %></td>
25
</tr>
22 26
<% if User.current.allowed_to_view_all_time_entries?(@project) %>
23 27
<tr>
24 28
    <th><%= l(:label_spent_time) %></th>
test/unit/version_test.rb
177 177
    assert_equal false, version.behind_schedule?
178 178
  end
179 179

  
180
  test "#estimated_hours should return 0 with no assigned issues" do
180
  test "#estimated_hours and remaining_hours should return 0 with no assigned issues" do
181 181
    version = Version.generate!
182 182
    assert_equal 0, version.estimated_hours
183
    assert_equal 0, version.remaining_hours
183 184
  end
184 185

  
185
  test "#estimated_hours should return 0 with no estimated hours" do
186
  test "#estimated_hours and remaining_hours should return 0 with no estimated hours" do
186 187
    version = Version.create!(:project_id => 1, :name => 'test')
187 188
    add_issue(version)
188 189
    assert_equal 0, version.estimated_hours
190
    assert_equal 0, version.remaining_hours
189 191
  end
190 192

  
191
  test "#estimated_hours should return return the sum of estimated hours" do
193
  test "#estimated_hours and remaining_hours should return return the sum of estimated hours" do
192 194
    version = Version.create!(:project_id => 1, :name => 'test')
193
    add_issue(version, :estimated_hours => 2.5)
194
    add_issue(version, :estimated_hours => 5)
195
    add_issue(version, :estimated_hours => 2.5, :remaining_hours => 1)
196
    add_issue(version, :estimated_hours => 5, :remaining_hours => 3)
195 197
    assert_equal 7.5, version.estimated_hours
198
    assert_equal 4, version.remaining_hours
196 199
  end
197 200

  
198
  test "#estimated_hours should return the sum of leaves estimated hours" do
201
  test "#estimated_hours and remaining_hours should return the sum of leaves estimated hours and remaining hours" do
199 202
    version = Version.create!(:project_id => 1, :name => 'test')
200 203
    parent = add_issue(version)
201
    add_issue(version, :estimated_hours => 2.5, :parent_issue_id => parent.id)
202
    add_issue(version, :estimated_hours => 5, :parent_issue_id => parent.id)
204
    add_issue(version, :estimated_hours => 2.5, :remaining_hours => 1, :parent_issue_id => parent.id)
205
    add_issue(version, :estimated_hours => 5, :remaining_hours => 3, :parent_issue_id => parent.id)
203 206
    assert_equal 7.5, version.estimated_hours
207
    assert_equal 4, version.remaining_hours
204 208
  end
205 209

  
206 210
  test "should update all issue's fixed_version associations in case the hierarchy changed XXX" do