Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #18515 - add scheduling helpers + tests #243

Merged
merged 2 commits into from Mar 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/models/foreman_tasks/task.rb
Expand Up @@ -69,7 +69,7 @@ def username
end

def execution_type
start_at.to_i == started_at.to_i ? N_('Immediate') : N_('Delayed')
delayed? ? N_('Delayed') : N_('Immediate')
end

def humanized
Expand All @@ -96,6 +96,14 @@ def paused?
state == 'paused'
end

def recurring?
!recurring_logic_task_group_ids.empty?
end

def delayed?
start_at.to_i != started_at.to_i
end

def self_and_parents
[self].tap do |ret|
ret.concat(parent_task.self_and_parents) if parent_task
Expand Down
22 changes: 22 additions & 0 deletions test/unit/task_test.rb
Expand Up @@ -95,6 +95,28 @@ class TasksTest < ActiveSupport::TestCase
task.sub_tasks_counts.must_equal expected_result
end
end
end

describe 'recurring task' do
let(:logic) { FactoryGirl.build(:recurring_logic) }
let(:task) { FactoryGirl.create(:some_task) }

it 'can indicate it is recurring' do
refute task.recurring?
task.add_missing_task_groups(logic.task_group)
assert task.recurring?
end
end

describe 'delayed task' do
let(:task) { FactoryGirl.create(:some_task) }

it 'can indicate it is delayed' do
refute task.delayed?
task.execution_type.must_equal 'Immediate'
task.start_at = Time.now.utc + 100
assert task.delayed?
task.execution_type.must_equal 'Delayed'
end
end
end