diff --git a/app/models/maintenance_tasks/progress.rb b/app/models/maintenance_tasks/progress.rb index e4237860..1487cc49 100644 --- a/app/models/maintenance_tasks/progress.rb +++ b/app/models/maintenance_tasks/progress.rb @@ -27,7 +27,10 @@ def initialize(run) # @return [Integer] if progress can be determined or the Run is stopped. # @return [nil] if progress can't be determined and the Run isn't stopped. def value - @run.tick_count if estimatable? || @run.stopped? + return 0 if @run.completed? && @run.tick_total.to_i.zero? + return @run.tick_count if estimatable? || @run.stopped? + + nil end # The maximum amount of work expected to be done. This is extracted from the @@ -48,7 +51,7 @@ def max # # @return [String] the text for the Run progress. def text - count = @run.tick_count + count = @run.tick_count || 0 total = @run.tick_total if !total? diff --git a/test/helpers/maintenance_tasks/tasks_helper_test.rb b/test/helpers/maintenance_tasks/tasks_helper_test.rb index 9244cd0d..befc308b 100644 --- a/test/helpers/maintenance_tasks/tasks_helper_test.rb +++ b/test/helpers/maintenance_tasks/tasks_helper_test.rb @@ -49,6 +49,20 @@ class TasksHelperTest < ActionView::TestCase assert_equal expected, progress(@run) end + test "#progress returns a
with a with no value when Run is succeeded and tick_total is 0" do + @run.status = :succeeded + @run.started_at = Time.now + + Progress.expects(:new).with(@run).returns( + mock(value: 0, max: nil, text: "Processed 0 items."), + ) + + expected = '
' \ + "

Processed 0 items.

" + assert_equal expected, progress(@run) + end + test "#status_tag renders a span with the appropriate tag based on status" do expected = 'Pausing' assert_equal expected, status_tag("pausing") diff --git a/test/models/maintenance_tasks/progress_test.rb b/test/models/maintenance_tasks/progress_test.rb index 994a1750..d1f59ac2 100644 --- a/test/models/maintenance_tasks/progress_test.rb +++ b/test/models/maintenance_tasks/progress_test.rb @@ -18,6 +18,13 @@ class ProgressTest < ActiveSupport::TestCase assert_nil @progress.value end + test "#value is 0 if the Run is completed and does not have a tick total" do + @run.status = :succeeded + @run.tick_total = nil + + assert_equal 0, @progress.value + end + test "#value is the Run tick count if the Run does not have a tick total and it is stopped" do @run.status = :paused @run.tick_total = nil