Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/models/maintenance_tasks/progress.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down
14 changes: 14 additions & 0 deletions test/helpers/maintenance_tasks/tasks_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ class TasksHelperTest < ActionView::TestCase
assert_equal expected, progress(@run)
end

test "#progress returns a <div> with a <progress> 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 = '<div class="block"><progress value="0" ' \
'class="progress mt-4 is-success"></progress>' \
"<p><i>Processed 0 items.</i></p></div>"
assert_equal expected, progress(@run)
end

test "#status_tag renders a span with the appropriate tag based on status" do
expected = '<span class="tag has-text-weight-medium pr-2 mr-4 is-warning is-light">Pausing</span>'
assert_equal expected, status_tag("pausing")
Expand Down
7 changes: 7 additions & 0 deletions test/models/maintenance_tasks/progress_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down