foreman-tasks 9.1.0 → 9.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,14 +22,14 @@ class TasksTest < ActiveSupport::TestCase
22
22
  FactoryBot.create(:dynflow_task, :product_create_task)]
23
23
  cleaner.expects(:tasks_to_csv)
24
24
  cleaner.delete
25
- _(ForemanTasks::Task.where(id: tasks_to_delete)).must_be_empty
26
- _(ForemanTasks::Task.where(id: tasks_to_keep).order(:id).map(&:id)).must_equal tasks_to_keep.map(&:id).sort
25
+ assert_empty ForemanTasks::Task.where(id: tasks_to_delete)
26
+ assert_equal tasks_to_keep.map(&:id).sort, ForemanTasks::Task.where(id: tasks_to_keep).order(:id).map(&:id)
27
27
 
28
- _(ForemanTasks.dynflow.world.persistence
29
- .find_execution_plans(filters: { 'uuid' => tasks_to_delete.map(&:external_id) }).size).must_equal 0
28
+ assert_equal 0, ForemanTasks.dynflow.world.persistence
29
+ .find_execution_plans(filters: { 'uuid' => tasks_to_delete.map(&:external_id) }).size
30
30
 
31
- _(ForemanTasks.dynflow.world.persistence
32
- .find_execution_plans(filters: { 'uuid' => tasks_to_keep.map(&:external_id) }).size).must_equal tasks_to_keep.size
31
+ assert_equal tasks_to_keep.size, ForemanTasks.dynflow.world.persistence
32
+ .find_execution_plans(filters: { 'uuid' => tasks_to_keep.map(&:external_id) }).size
33
33
  end
34
34
 
35
35
  describe "#orphaned_dynflow_tasks" do
@@ -67,11 +67,11 @@ class TasksTest < ActiveSupport::TestCase
67
67
 
68
68
  cleaner.expects(:tasks_to_csv)
69
69
  cleaner.delete
70
- _(ForemanTasks::Task.where(id: tasks_to_delete)).must_be_empty
71
- _(ForemanTasks::Task.where(id: tasks_to_keep)).must_equal tasks_to_keep
70
+ assert_empty ForemanTasks::Task.where(id: tasks_to_delete)
71
+ assert_equal tasks_to_keep, ForemanTasks::Task.where(id: tasks_to_keep)
72
72
 
73
- _(ForemanTasks::Link.find_by(id: link_to_delete.id)).must_be_nil
74
- _(ForemanTasks::Link.find_by(id: link_to_keep.id)).wont_be_nil
73
+ assert_nil ForemanTasks::Link.find_by(id: link_to_delete.id)
74
+ assert_not_nil ForemanTasks::Link.find_by(id: link_to_keep.id)
75
75
  end
76
76
 
77
77
  it 'supports passing empty filter (just delete all)' do
@@ -85,8 +85,8 @@ class TasksTest < ActiveSupport::TestCase
85
85
  end]
86
86
  cleaner.expects(:tasks_to_csv)
87
87
  cleaner.delete
88
- _(ForemanTasks::Task.where(id: tasks_to_delete)).must_be_empty
89
- _(ForemanTasks::Task.where(id: tasks_to_keep)).must_equal tasks_to_keep
88
+ assert_empty ForemanTasks::Task.where(id: tasks_to_delete)
89
+ assert_equal tasks_to_keep, ForemanTasks::Task.where(id: tasks_to_keep)
90
90
  end
91
91
 
92
92
  it 'matches tasks with compound filters properly' do
@@ -100,8 +100,8 @@ class TasksTest < ActiveSupport::TestCase
100
100
  task_to_keep.update!(:result => 'pending', :state => 'planned')
101
101
  cleaner.expects(:tasks_to_csv)
102
102
  cleaner.delete
103
- _(ForemanTasks::Task.where(id: tasks_to_delete)).must_be_empty
104
- _(ForemanTasks::Task.where(id: task_to_keep)).must_equal [task_to_keep]
103
+ assert_empty ForemanTasks::Task.where(id: tasks_to_delete)
104
+ assert_equal [task_to_keep], ForemanTasks::Task.where(id: task_to_keep)
105
105
  end
106
106
 
107
107
  it 'backs tasks up before deleting' do
@@ -117,11 +117,11 @@ class TasksTest < ActiveSupport::TestCase
117
117
  cleaner.delete
118
118
  w.close
119
119
  header, *data = r.readlines.map(&:chomp)
120
- _(header).must_equal ForemanTasks::Task.attribute_names.join(',')
120
+ assert_equal ForemanTasks::Task.attribute_names.join(','), header
121
121
  expected_lines = tasks_to_delete.map { |task| task.attributes.values.to_csv.chomp }
122
- _(data.count).must_equal expected_lines.count
123
- expected_lines.each { |line| _(data).must_include line }
124
- _(ForemanTasks::Task.where(id: tasks_to_delete)).must_be_empty
122
+ assert_equal expected_lines.count, data.count
123
+ expected_lines.each { |line| assert_includes data, line }
124
+ assert_empty ForemanTasks::Task.where(id: tasks_to_delete)
125
125
  end
126
126
 
127
127
  class ActionWithCleanup < Actions::Base
@@ -135,7 +135,7 @@ class TasksTest < ActiveSupport::TestCase
135
135
  ForemanTasks::Cleaner.stubs(:cleanup_settings => {})
136
136
  actions = ForemanTasks::Cleaner.actions_with_default_cleanup
137
137
  example = actions.find { |rule| rule.klass == ActionWithCleanup }
138
- _(example.after).must_equal '15d'
138
+ assert_equal '15d', example.after
139
139
  end
140
140
 
141
141
  it 'searches for the actions that have the cleanup_after defined' do
@@ -143,7 +143,7 @@ class TasksTest < ActiveSupport::TestCase
143
143
  { :actions => [{ :name => ActionWithCleanup.name, :after => '5d' }] })
144
144
  actions = ForemanTasks::Cleaner.actions_with_default_cleanup
145
145
  example = actions.find { |rule| rule.klass == ActionWithCleanup }
146
- _(example.after).must_equal '5d'
146
+ assert_equal '5d', example.after
147
147
  end
148
148
 
149
149
  it 'generates filters from rules properly' do
@@ -157,10 +157,10 @@ class TasksTest < ActiveSupport::TestCase
157
157
  :override_actions => true, :states => 'all' }]
158
158
  ForemanTasks::Cleaner.stubs(:cleanup_settings).returns(:rules => rules)
159
159
  r1, r2 = ForemanTasks::Cleaner.actions_by_rules actions_with_default
160
- _(r1[:filter]).must_equal '(NOT ((label ^ (action1, action2)))) AND (label = something)'
161
- _(r1[:states]).must_equal %w[stopped paused]
162
- _(r2[:filter]).must_equal '(label = something_else)'
163
- _(r2[:states]).must_equal []
160
+ assert_equal '(NOT ((label ^ (action1, action2)))) AND (label = something)', r1[:filter]
161
+ assert_equal %w[stopped paused], r1[:states]
162
+ assert_equal '(label = something_else)', r2[:filter]
163
+ assert_equal [], r2[:states]
164
164
  end
165
165
  end
166
166
  end
@@ -32,14 +32,14 @@ module ForemanTasks
32
32
 
33
33
  it 'can lock a resource for a single task only once' do
34
34
  Lock.lock!(resource, task1)
35
- _(Lock.for_resource(resource).count).must_equal 1
35
+ assert_equal 1, Lock.for_resource(resource).count
36
36
  Lock.lock!(resource, task1)
37
- _(Lock.for_resource(resource).count).must_equal 1
37
+ assert_equal 1, Lock.for_resource(resource).count
38
38
  end
39
39
 
40
40
  it 'cannot lock a resource for multiple tasks' do
41
41
  lock = Lock.lock!(resource, task1)
42
- _(Lock.colliding_locks(resource, task2)).must_equal [lock]
42
+ assert_equal [lock], Lock.colliding_locks(resource, task2)
43
43
  assert_raises Lock::LockConflict do
44
44
  Lock.lock!(resource, task2)
45
45
  end
@@ -52,13 +52,13 @@ module ForemanTasks
52
52
  exception = assert_raises Lock::LockConflict do
53
53
  Lock.lock!(resource, task2)
54
54
  end
55
- _(exception.message).must_match(/#{lock.task_id}/)
55
+ assert_match(/#{lock.task_id}/, exception.message)
56
56
  end
57
57
 
58
58
  it 'creates a link when creating a lock for a resource' do
59
59
  Lock.lock!(resource, task1)
60
60
  link = Link.for_resource(resource).first
61
- _(link.task_id).must_equal task1.id
61
+ assert_equal task1.id, link.task_id
62
62
  end
63
63
  end
64
64
 
@@ -69,15 +69,15 @@ module ForemanTasks
69
69
 
70
70
  it 'can link a resource for a single task only once' do
71
71
  Link.link!(resource, task1)
72
- _(Link.for_resource(resource).count).must_equal 1
72
+ assert_equal 1, Link.for_resource(resource).count
73
73
  Link.link!(resource, task1)
74
- _(Link.for_resource(resource).count).must_equal 1
74
+ assert_equal 1, Link.for_resource(resource).count
75
75
  end
76
76
 
77
77
  it 'can link a resource to multiple tasks' do
78
78
  Link.link!(resource, task1)
79
79
  Link.link!(resource, task2)
80
- _(Link.for_resource(resource).count).must_equal 2
80
+ assert_equal 2, Link.for_resource(resource).count
81
81
  end
82
82
  end
83
83
  end
@@ -18,22 +18,22 @@ describe ForemanTasks::ProxySelector do
18
18
  found << proxy_selector.select_by_jobs_count(proxies)
19
19
  end
20
20
 
21
- _(available.count).must_equal count
22
- _(available.uniq.count).must_equal count - 1
23
- _(proxy_selector.offline.count).must_equal 1
21
+ assert_equal count, available.count
22
+ assert_equal count - 1, available.uniq.count
23
+ assert_equal 1, proxy_selector.offline.count
24
24
  end
25
25
 
26
26
  it 'returns nil for if no proxy is available' do
27
- _(proxy_selector.select_by_jobs_count([])).must_be_nil
27
+ assert_nil proxy_selector.select_by_jobs_count([])
28
28
  end
29
29
  end
30
30
 
31
31
  describe '#determine_proxy' do
32
32
  it 'returns :not_defined when avialable proxies returns empty hash' do
33
33
  proxy_selector.stubs(:available_proxies => [])
34
- _(proxy_selector.determine_proxy).must_equal :not_defined
34
+ assert_equal :not_defined, proxy_selector.determine_proxy
35
35
  proxy_selector.stubs(:available_proxies => { :global => [] })
36
- _(proxy_selector.determine_proxy).must_equal :not_defined
36
+ assert_equal :not_defined, proxy_selector.determine_proxy
37
37
  end
38
38
 
39
39
  it 'returns :not_available when proxies are set but offline' do
@@ -41,7 +41,7 @@ describe ForemanTasks::ProxySelector do
41
41
  ProxyAPI::ForemanDynflow::DynflowProxy.any_instance.expects(:tasks_count).times(count).raises
42
42
  proxy_selector.stubs(:available_proxies =>
43
43
  { :global => FactoryBot.create_list(:smart_proxy, count) })
44
- _(proxy_selector.determine_proxy).must_equal :not_available
44
+ assert_equal :not_available, proxy_selector.determine_proxy
45
45
  end
46
46
 
47
47
  it 'returns first available proxy, prioritizing by strategy' do
@@ -51,9 +51,9 @@ describe ForemanTasks::ProxySelector do
51
51
  ForemanTasks::ProxySelector.any_instance.stubs(:available_proxies =>
52
52
  { :fallback => [fallback_proxy],
53
53
  :global => [global_proxy] })
54
- _(ForemanTasks::ProxySelector.new.determine_proxy).must_equal fallback_proxy
54
+ assert_equal fallback_proxy, ForemanTasks::ProxySelector.new.determine_proxy
55
55
  ProxyAPI::ForemanDynflow::DynflowProxy.any_instance.expects(:tasks_count).raises.then.returns(0)
56
- _(ForemanTasks::ProxySelector.new.determine_proxy).must_equal global_proxy
56
+ assert_equal global_proxy, ForemanTasks::ProxySelector.new.determine_proxy
57
57
  end
58
58
  end
59
59
  end
@@ -4,17 +4,17 @@ class RecurringLogicsTest < ActiveSupport::TestCase
4
4
  describe 'generating times' do
5
5
  it 'assembles cronline' do
6
6
  hash = {}
7
- _(ForemanTasks::RecurringLogic.assemble_cronline(hash)).must_equal '* * * * *'
7
+ assert_equal '* * * * *', ForemanTasks::RecurringLogic.assemble_cronline(hash)
8
8
  hash.update :minutes => '*'
9
- _(ForemanTasks::RecurringLogic.assemble_cronline(hash)).must_equal '* * * * *'
9
+ assert_equal '* * * * *', ForemanTasks::RecurringLogic.assemble_cronline(hash)
10
10
  hash.update :hours => '0,12'
11
- _(ForemanTasks::RecurringLogic.assemble_cronline(hash)).must_equal '* 0,12 * * *'
11
+ assert_equal '* 0,12 * * *', ForemanTasks::RecurringLogic.assemble_cronline(hash)
12
12
  hash.update :days => '*/2'
13
- _(ForemanTasks::RecurringLogic.assemble_cronline(hash)).must_equal '* 0,12 */2 * *'
13
+ assert_equal '* 0,12 */2 * *', ForemanTasks::RecurringLogic.assemble_cronline(hash)
14
14
  hash.update :months => '12'
15
- _(ForemanTasks::RecurringLogic.assemble_cronline(hash)).must_equal '* 0,12 */2 12 *'
15
+ assert_equal '* 0,12 */2 12 *', ForemanTasks::RecurringLogic.assemble_cronline(hash)
16
16
  hash.update :days_of_week => '1,2,3,4,5,6,7'
17
- _(ForemanTasks::RecurringLogic.assemble_cronline(hash)).must_equal '* 0,12 */2 12 1,2,3,4,5,6,7'
17
+ assert_equal '* 0,12 */2 12 1,2,3,4,5,6,7', ForemanTasks::RecurringLogic.assemble_cronline(hash)
18
18
  end
19
19
 
20
20
  it 'generates correct times' do
@@ -25,17 +25,17 @@ class RecurringLogicsTest < ActiveSupport::TestCase
25
25
  minute = 0
26
26
  reference_time = Time.utc(year, month, day, hour, minute)
27
27
  parser = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
28
- _(parser.next_occurrence_time(reference_time)).must_equal Time.utc(year, month, day, hour, minute)
28
+ assert_equal Time.utc(year, month, day, hour, minute), parser.next_occurrence_time(reference_time)
29
29
  parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 * * * *')
30
- _(parser.next_occurrence_time(reference_time)).must_equal Time.utc(year, month, day, hour, minute)
30
+ assert_equal Time.utc(year, month, day, hour, minute), parser.next_occurrence_time(reference_time)
31
31
  parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 18,19 * * *')
32
- _(parser.next_occurrence_time(reference_time)).must_equal Time.utc(year, month, day, 18)
32
+ assert_equal Time.utc(year, month, day, 18), parser.next_occurrence_time(reference_time)
33
33
  parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 18,19 10 * *')
34
- _(parser.next_occurrence_time(reference_time)).must_equal Time.utc(year, month + 1, 10, 18, minute)
34
+ assert_equal Time.utc(year, month + 1, 10, 18, minute), parser.next_occurrence_time(reference_time)
35
35
  parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 18,19 10 11,12 *')
36
- _(parser.next_occurrence_time(reference_time)).must_equal Time.utc(year, 11, 10, 18, 0)
36
+ assert_equal Time.utc(year, 11, 10, 18, 0), parser.next_occurrence_time(reference_time)
37
37
  parser = ForemanTasks::RecurringLogic.new_from_cronline('* * * * 1')
38
- _(parser.next_occurrence_time(reference_time)).must_equal Time.utc(year, month + 1, 5)
38
+ assert_equal Time.utc(year, month + 1, 5), parser.next_occurrence_time(reference_time)
39
39
  end
40
40
 
41
41
  it 'creates correct cronline hash' do
@@ -48,10 +48,10 @@ class RecurringLogicsTest < ActiveSupport::TestCase
48
48
  expected_result_daily = { :minutes => minutes, :hours => hours }
49
49
  expected_result_weekly = { :minutes => minutes, :hours => hours, :days_of_week => '1,4,6' }
50
50
  expected_result_monthly = { :minutes => minutes, :hours => hours, :days => days }
51
- _(ForemanTasks::RecurringLogic.cronline_hash(:hourly, time_hash, days, days_of_week)).must_equal expected_result_hourly
52
- _(ForemanTasks::RecurringLogic.cronline_hash(:daily, time_hash, days, days_of_week)).must_equal expected_result_daily
53
- _(ForemanTasks::RecurringLogic.cronline_hash(:weekly, time_hash, days, days_of_week)).must_equal expected_result_weekly
54
- _(ForemanTasks::RecurringLogic.cronline_hash(:monthly, time_hash, days, days_of_week)).must_equal expected_result_monthly
51
+ assert_equal expected_result_hourly, ForemanTasks::RecurringLogic.cronline_hash(:hourly, time_hash, days, days_of_week)
52
+ assert_equal expected_result_daily, ForemanTasks::RecurringLogic.cronline_hash(:daily, time_hash, days, days_of_week)
53
+ assert_equal expected_result_weekly, ForemanTasks::RecurringLogic.cronline_hash(:weekly, time_hash, days, days_of_week)
54
+ assert_equal expected_result_monthly, ForemanTasks::RecurringLogic.cronline_hash(:monthly, time_hash, days, days_of_week)
55
55
  end
56
56
 
57
57
  it 'validates cronline correctly' do
@@ -68,18 +68,18 @@ class RecurringLogicsTest < ActiveSupport::TestCase
68
68
  it 'can have limited number of repeats' do
69
69
  parser = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
70
70
  parser.state = 'active'
71
- _(parser).must_be :can_continue?
71
+ assert parser.can_continue?
72
72
  parser.max_iteration = 5
73
73
  parser.expects(:iteration).twice.returns(5)
74
- _(parser).wont_be :can_continue?
74
+ assert_not parser.can_continue?
75
75
  parser.max_iteration = nil
76
76
  time = Time.utc(2015, 9, 29, 15, 0)
77
77
  parser.end_time = time
78
- _(parser).wont_be :can_continue?, time
78
+ assert_not parser.can_continue?(time)
79
79
  parser.end_time = time + 120
80
- _(parser).must_be :can_continue?, time
80
+ assert parser.can_continue?(time)
81
81
  parser.max_iteration = 5
82
- _(parser).wont_be :can_continue?, time
82
+ assert_not parser.can_continue?(time)
83
83
  end
84
84
 
85
85
  it 'generates delay options' do
@@ -87,9 +87,8 @@ class RecurringLogicsTest < ActiveSupport::TestCase
87
87
  parser.stubs(:id).returns(1)
88
88
  reference_time = Time.utc(2015, 9, 29, 15)
89
89
  expected_hash = { :start_at => reference_time, :start_before => nil, :recurring_logic_id => parser.id, :frozen => false }
90
- _(parser.generate_delay_options(reference_time)).must_equal expected_hash
91
- _(parser.generate_delay_options(reference_time, 'start_before' => reference_time + 3600))
92
- .must_equal expected_hash.merge(:start_before => reference_time + 3600)
90
+ assert_equal expected_hash, parser.generate_delay_options(reference_time)
91
+ assert_equal expected_hash.merge(:start_before => reference_time + 3600), parser.generate_delay_options(reference_time, 'start_before' => reference_time + 3600)
93
92
  end
94
93
 
95
94
  it 'can start' do
@@ -119,19 +118,19 @@ class RecurringLogicsTest < ActiveSupport::TestCase
119
118
  it 'has a task group associated to all tasks that were created as part of the recurring logic' do
120
119
  recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
121
120
  recurring_logic.save
122
- _(recurring_logic.task_group).must_be_kind_of ForemanTasks::TaskGroups::RecurringLogicTaskGroup
121
+ assert_kind_of ForemanTasks::TaskGroups::RecurringLogicTaskGroup, recurring_logic.task_group
123
122
  task = FactoryBot.build(:dynflow_task, :user_create_task)
124
123
  task.task_groups << Support::DummyTaskGroup.new
125
124
  task.save!
126
125
  recurring_logic.task_group.tasks << task
127
- _(recurring_logic.task_groups).must_include(*task.task_groups)
126
+ assert_includes recurring_logic.task_groups, *task.task_groups
128
127
  end
129
128
 
130
129
  it 'can be created from triggering' do
131
130
  triggering = FactoryBot.build(:triggering, :recurring, :end_time_limited)
132
131
  logic = ForemanTasks::RecurringLogic.new_from_triggering(triggering)
133
132
  # Mysql coerces the times a bit
134
- _(logic.end_time).must_be_close_to(triggering.end_time, 1.second)
133
+ assert_in_delta triggering.end_time, logic.end_time, 1.second
135
134
  end
136
135
 
137
136
  it 'cannot trigger tasks when cancelled' do
@@ -181,24 +180,24 @@ class RecurringLogicsTest < ActiveSupport::TestCase
181
180
  let(:logic) { FactoryBot.build(:recurring_logic) }
182
181
 
183
182
  it 'is valid by default' do
184
- _(logic).must_be :valid?
183
+ assert_predicate logic, :valid?
185
184
  end
186
185
 
187
186
  it 'is invalid when end time in past' do
188
187
  logic.end_time = (Time.zone.now - 120)
189
- _(logic).wont_be :valid?
188
+ assert_not_predicate logic, :valid?
190
189
  end
191
190
 
192
191
  it 'is invalid when iteration limit < 1' do
193
192
  logic.max_iteration = 0
194
- _(logic).wont_be :valid?
193
+ assert_not_predicate logic, :valid?
195
194
  end
196
195
 
197
196
  it 'is valid when in active state' do
198
197
  logic.end_time = (Time.zone.now - 120)
199
- _(logic).wont_be :valid?
198
+ assert_not_predicate logic, :valid?
200
199
  logic.state = 'active'
201
- _(logic).must_be :valid?
200
+ assert_predicate logic, :valid?
202
201
  end
203
202
  end
204
203
  end
@@ -24,8 +24,8 @@ module ForemanTasks
24
24
  RemoteTask.batch_trigger('a_operation', remote_tasks)
25
25
  remote_tasks.each do |remote_task|
26
26
  remote_task.reload
27
- _(remote_task.state).must_equal 'triggered'
28
- _(remote_task.remote_task_id).must_equal((remote_task.id + 5).to_s)
27
+ assert_equal 'triggered', remote_task.state
28
+ assert_equal (remote_task.id + 5).to_s, remote_task.remote_task_id
29
29
  end
30
30
  end
31
31
 
@@ -50,8 +50,8 @@ module ForemanTasks
50
50
  RemoteTask.batch_trigger('a_operation', remote_tasks)
51
51
  remote_tasks.each do |remote_task|
52
52
  remote_task.reload
53
- _(remote_task.state).must_equal 'triggered'
54
- _(remote_task.remote_task_id).must_equal((remote_task.id + 5).to_s)
53
+ assert_equal 'triggered', remote_task.state
54
+ assert_equal (remote_task.id + 5).to_s, remote_task.remote_task_id
55
55
  end
56
56
  end
57
57
  end
@@ -59,18 +59,18 @@ module ForemanTasks
59
59
 
60
60
  it 'has the task group assigned' do
61
61
  task = spawn_task.call ChildAction
62
- _(task.task_groups.map(&:id)).must_equal [1]
62
+ assert_equal [1], task.task_groups.map(&:id)
63
63
  end
64
64
 
65
65
  it 'tasks inherit task groups correctly' do
66
66
  children_count = 3
67
67
  task = spawn_task.call ParentAction, children_count
68
68
  # Parent task has task groups of its children
69
- _(task.task_groups.map(&:id).sort).must_equal [1, 2, 3, 4]
69
+ assert_equal [1, 2, 3, 4], task.task_groups.map(&:id).sort
70
70
  # Children have the parent's and their own, they don't have their siblings' task groups
71
- _(task.sub_tasks.count).must_equal children_count
71
+ assert_equal children_count, task.sub_tasks.count
72
72
  task.sub_tasks.each do |sub_task|
73
- _(sub_task.task_groups.map(&:id).sort).must_equal [1, sub_task.input[:id]].sort
73
+ assert_equal [1, sub_task.input[:id]].sort, sub_task.task_groups.map(&:id).sort
74
74
  end
75
75
  end
76
76
  end
@@ -32,8 +32,8 @@ class TasksTest < ActiveSupport::TestCase
32
32
  end
33
33
 
34
34
  it 'cannot search by arbitrary key' do
35
- _(proc { ForemanTasks::Task.search_for('user.my_key ~ 5') }).must_raise(ScopedSearch::QueryNotSupported)
36
- _(proc { ForemanTasks::Task.search_for('user. = 5') }).must_raise(ScopedSearch::QueryNotSupported)
35
+ assert_raises(ScopedSearch::QueryNotSupported) { ForemanTasks::Task.search_for('user.my_key ~ 5') }
36
+ assert_raises(ScopedSearch::QueryNotSupported) { ForemanTasks::Task.search_for('user. = 5') }
37
37
  end
38
38
 
39
39
  test 'can search the tasks by negated user' do
@@ -59,8 +59,8 @@ class TasksTest < ActiveSupport::TestCase
59
59
  end
60
60
 
61
61
  test 'cannot glob on user\'s id' do
62
- _(proc { ForemanTasks::Task.search_for("user.id ~ something") }).must_raise(ScopedSearch::QueryNotSupported)
63
- _(proc { ForemanTasks::Task.search_for("user.id ~ 5") }).must_raise(ScopedSearch::QueryNotSupported)
62
+ assert_raises(ScopedSearch::QueryNotSupported) { ForemanTasks::Task.search_for("user.id ~ something") }
63
+ assert_raises(ScopedSearch::QueryNotSupported) { ForemanTasks::Task.search_for("user.id ~ 5") }
64
64
  end
65
65
 
66
66
  test 'can search the tasks by user with wildcards' do
@@ -105,28 +105,28 @@ class TasksTest < ActiveSupport::TestCase
105
105
 
106
106
  it 'can search by seconds ' do
107
107
  skip unless on_postgresql?
108
- _(scope.search_for('duration < 2')).must_be :empty?
109
- _(scope.search_for('duration = 2')).must_equal [@task_one, @task_two]
110
- _(scope.search_for('duration < "2 seconds"')).must_be :empty?
111
- _(scope.search_for('duration > "2 seconds"')).must_be :empty?
112
- _(scope.search_for('duration = "2 seconds"')).must_equal [@task_one, @task_two]
113
- _(scope.search_for('duration <= "2 seconds"')).must_equal [@task_one, @task_two]
114
- _(scope.search_for('duration >= "2 seconds"')).must_equal [@task_one, @task_two]
108
+ assert_empty scope.search_for('duration < 2')
109
+ assert_equal [@task_one, @task_two], scope.search_for('duration = 2')
110
+ assert_empty scope.search_for('duration < "2 seconds"')
111
+ assert_empty scope.search_for('duration > "2 seconds"')
112
+ assert_equal [@task_one, @task_two], scope.search_for('duration = "2 seconds"')
113
+ assert_equal [@task_one, @task_two], scope.search_for('duration <= "2 seconds"')
114
+ assert_equal [@task_one, @task_two], scope.search_for('duration >= "2 seconds"')
115
115
  end
116
116
 
117
117
  it 'can search by other time intervals' do
118
118
  skip unless on_postgresql?
119
119
  %w[minutes hours days months years].each do |interval|
120
- _(scope.search_for("duration < \"2 #{interval}\"")).must_equal [@task_one, @task_two]
121
- _(scope.search_for("duration > \"2 #{interval}\"")).must_be :empty?
122
- _(scope.search_for("duration = \"2 #{interval}\"")).must_be :empty?
123
- _(scope.search_for("duration <= \"2 #{interval}\"")).must_equal [@task_one, @task_two]
124
- _(scope.search_for("duration >= \"2 #{interval}\"")).must_be :empty?
120
+ assert_equal [@task_one, @task_two], scope.search_for("duration < \"2 #{interval}\"")
121
+ assert_empty scope.search_for("duration > \"2 #{interval}\"")
122
+ assert_empty scope.search_for("duration = \"2 #{interval}\"")
123
+ assert_equal [@task_one, @task_two], scope.search_for("duration <= \"2 #{interval}\"")
124
+ assert_empty scope.search_for("duration >= \"2 #{interval}\"")
125
125
  end
126
126
  end
127
127
 
128
128
  it 'raises an exception if duration is unknown' do
129
- _(proc { ForemanTasks::Task.search_for('duration = "25 potatoes"') }).must_raise ScopedSearch::QueryNotSupported
129
+ assert_raises(ScopedSearch::QueryNotSupported) { ForemanTasks::Task.search_for('duration = "25 potatoes"') }
130
130
  end
131
131
  end
132
132
 
@@ -144,7 +144,7 @@ class TasksTest < ActiveSupport::TestCase
144
144
  describe 'users' do
145
145
  test 'users can be deleted even if they have tasks assigned' do
146
146
  user = FactoryBot.create(:user)
147
- FactoryBot.create(:some_task, :user => user)
147
+ FactoryBot.create(:some_task, user: user)
148
148
  user.destroy!
149
149
  end
150
150
  end
@@ -152,14 +152,14 @@ class TasksTest < ActiveSupport::TestCase
152
152
  describe 'state_updated_at' do
153
153
  it 'updates the state_updated_at when the state changes' do
154
154
  task = FactoryBot.create(:some_task)
155
- assert task.state_updated_at > Time.now.utc - 1.minute, "Newly created task has to have state_updated_at set"
155
+ assert_operator task.state_updated_at, :>, Time.now.utc - 1.minute, "Newly created task has to have state_updated_at set"
156
156
  task.update(state_updated_at: nil)
157
157
  task.result = 'error'
158
158
  task.save
159
- assert_not task.state_updated_at, "Other than state change should not affect 'state_updated_at'"
159
+ assert_nil task.state_updated_at, "Other than state change should not affect 'state_updated_at'"
160
160
  task.state = 'running'
161
161
  task.save
162
- assert task.state_updated_at, "State change should set 'state_updated_at'"
162
+ assert_not_nil task.state_updated_at, "State change should set 'state_updated_at'"
163
163
  end
164
164
  end
165
165
 
@@ -171,7 +171,7 @@ class TasksTest < ActiveSupport::TestCase
171
171
  permission = FactoryBot.build(:permission)
172
172
  permission.resource_type = 'ForemanTasks::Task'
173
173
  permission.save!
174
- FactoryBot.create(:filter, :role => role, :permissions => [permission])
174
+ FactoryBot.create(:filter, role: role, permissions: [permission])
175
175
 
176
176
  User.current = user
177
177
  task = FactoryBot.create(:dynflow_task)
@@ -184,21 +184,21 @@ class TasksTest < ActiveSupport::TestCase
184
184
  describe 'consistency check' do
185
185
  it 'ensures the tasks marked as running are really running in Dynflow' do
186
186
  task = ForemanTasks.sync_task(Support::DummyDynflowAction)
187
- task.update(:state => 'running') # Updating state updates the timestamp
188
- task.update(:state_updated_at => Time.zone.now - 5.minutes)
187
+ task.update(state: 'running') # Updating state updates the timestamp
188
+ task.update(state_updated_at: Time.zone.now - 5.minutes)
189
189
 
190
190
  ForemanTasks::Task::DynflowTask.consistency_check
191
191
  task.reload
192
- _(task.state).must_equal 'stopped'
192
+ assert_equal 'stopped', task.state
193
193
  end
194
194
  end
195
195
 
196
196
  describe 'active job task' do
197
197
  it 'when scheduled to the future, the label and action is set properly' do
198
- job = Support::DummyActiveJob.set(:wait => 12.hours).perform_later
199
- task = ForemanTasks::Task.find_by!(:external_id => job.provider_job_id)
200
- _(task.action).must_equal "Dummy action"
201
- _(task.label).must_equal "Support::DummyActiveJob"
198
+ job = Support::DummyActiveJob.set(wait: 12.hours).perform_later
199
+ task = ForemanTasks::Task.find_by!(external_id: job.provider_job_id)
200
+ assert_equal "Dummy action", task.action
201
+ assert_equal "Support::DummyActiveJob", task.label
202
202
  end
203
203
  end
204
204
 
@@ -214,9 +214,9 @@ class TasksTest < ActiveSupport::TestCase
214
214
  end
215
215
 
216
216
  it 'handles the error while loading the task and does not propagate errors unless necessary' do
217
- task.cancellable?
218
- task.resumable?
219
- task.main_action
217
+ assert_nothing_raised { task.cancellable? }
218
+ assert_nothing_raised { task.resumable? }
219
+ assert_nothing_raised { task.main_action }
220
220
  assert_equal 'Support::DummyDynflowAction', task.get_humanized(:humanized_name)
221
221
  assert_equal 0, task.progress
222
222
  assert_raises(KeyError) { task.cancel }
@@ -226,19 +226,19 @@ class TasksTest < ActiveSupport::TestCase
226
226
  describe 'subtask count querying' do
227
227
  let(:result_base) do
228
228
  {
229
- :error => 0,
230
- :warning => 0,
231
- :total => 0,
232
- :success => 0,
233
- :cancelled => 0,
234
- :pending => 0,
229
+ error: 0,
230
+ warning: 0,
231
+ total: 0,
232
+ success: 0,
233
+ cancelled: 0,
234
+ pending: 0,
235
235
  }
236
236
  end
237
237
  let(:task) { FactoryBot.create(:dynflow_task) }
238
238
 
239
239
  describe 'without sub tasks' do
240
240
  it 'calculates the progress report correctly' do
241
- _(task.sub_tasks_counts).must_equal result_base
241
+ assert_equal result_base, task.sub_tasks_counts
242
242
  end
243
243
  end
244
244
 
@@ -248,22 +248,22 @@ class TasksTest < ActiveSupport::TestCase
248
248
  before { task.sub_tasks = [success, failed] }
249
249
 
250
250
  it 'calculate the progress report correctly' do
251
- expected_result = result_base.merge(:success => 1, :error => 1, :total => 2)
252
- _(task.sub_tasks_counts).must_equal expected_result
251
+ expected_result = result_base.merge(success: 1, error: 1, total: 2)
252
+ assert_equal expected_result, task.sub_tasks_counts
253
253
  end
254
254
 
255
255
  it 'calculates the progress report correctly when using batch planning' do
256
- result_base = self.result_base.merge(:success => 1, :error => 1, :total => 25)
257
- fake_action = OpenStruct.new(:total_count => 25)
256
+ result_base = self.result_base.merge(success: 1, error: 1, total: 25)
257
+ fake_action = OpenStruct.new(total_count: 25)
258
258
  task.stubs(:main_action).returns(fake_action)
259
259
 
260
260
  task.state = 'stopped'
261
- expected_result = result_base.merge(:cancelled => 23)
262
- _(task.sub_tasks_counts).must_equal expected_result
261
+ expected_result = result_base.merge(cancelled: 23)
262
+ assert_equal expected_result, task.sub_tasks_counts
263
263
 
264
264
  task.state = 'pending'
265
- expected_result = result_base.merge(:pending => 23)
266
- _(task.sub_tasks_counts).must_equal expected_result
265
+ expected_result = result_base.merge(pending: 23)
266
+ assert_equal expected_result, task.sub_tasks_counts
267
267
  end
268
268
  end
269
269
  end
@@ -284,11 +284,11 @@ class TasksTest < ActiveSupport::TestCase
284
284
  let(:task) { FactoryBot.create(:some_task) }
285
285
 
286
286
  it 'can indicate it is delayed' do
287
- assert_not task.delayed?
288
- _(task.execution_type).must_equal 'Immediate'
287
+ assert_not_predicate task, :delayed?
288
+ assert_equal 'Immediate', task.execution_type
289
289
  task.start_at = Time.now.utc + 100
290
- assert task.delayed?
291
- _(task.execution_type).must_equal 'Delayed'
290
+ assert_predicate task, :delayed?
291
+ assert_equal 'Delayed', task.execution_type
292
292
  end
293
293
  end
294
294