foreman_remote_execution 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +11 -9
  3. data/.rubocop_todo.yml +146 -116
  4. data/app/controllers/api/v2/job_invocations_controller.rb +6 -1
  5. data/app/controllers/api/v2/job_templates_controller.rb +0 -1
  6. data/app/controllers/job_invocations_controller.rb +6 -1
  7. data/app/lib/actions/remote_execution/run_host_job.rb +1 -1
  8. data/app/models/concerns/foreman_remote_execution/errors_flattener.rb +3 -0
  9. data/app/models/concerns/foreman_remote_execution/host_extensions.rb +1 -1
  10. data/app/models/concerns/foreman_remote_execution/subnet_extensions.rb +1 -1
  11. data/app/models/foreign_input_set.rb +1 -1
  12. data/app/models/job_invocation.rb +1 -1
  13. data/app/models/job_invocation_composer.rb +2 -2
  14. data/app/models/job_invocation_task_group.rb +1 -1
  15. data/app/models/job_template.rb +3 -3
  16. data/app/models/job_template_effective_user.rb +1 -1
  17. data/app/models/remote_execution_feature.rb +1 -1
  18. data/app/models/target_remote_execution_proxy.rb +1 -1
  19. data/app/models/targeting.rb +2 -2
  20. data/app/models/targeting_host.rb +1 -1
  21. data/app/models/template_input.rb +1 -1
  22. data/app/models/template_invocation.rb +1 -1
  23. data/app/models/template_invocation_input_value.rb +1 -1
  24. data/db/migrate/20150612121541_add_job_template_to_template.rb +1 -1
  25. data/db/migrate/20150616080015_create_template_input.rb +1 -1
  26. data/db/migrate/20150708133241_add_targeting.rb +1 -1
  27. data/db/migrate/20150708133242_add_invocation.rb +1 -1
  28. data/db/migrate/20150708133305_add_template_invocation.rb +1 -1
  29. data/db/migrate/20150812110800_add_resolved_at_to_targeting.rb +1 -1
  30. data/db/migrate/20150812145900_add_last_task_id_to_job_invocation.rb +1 -1
  31. data/db/migrate/20150826191632_create_target_remote_execution_proxies.rb +1 -1
  32. data/db/migrate/20150827144500_change_targeting_search_query_type.rb +1 -1
  33. data/db/migrate/20150827152730_add_options_to_template_input.rb +1 -1
  34. data/db/migrate/20150903192731_add_execution_to_interface.rb +2 -2
  35. data/db/migrate/20150923125825_add_job_invocation_task_group.rb +1 -1
  36. data/db/migrate/20151013135415_add_pub_key_to_smart_proxy.rb +1 -1
  37. data/db/migrate/20151022105508_rename_last_task_id_column.rb +1 -1
  38. data/db/migrate/20151116105412_add_triggering_to_job_invocation.rb +1 -1
  39. data/db/migrate/20151120171100_add_effective_user_to_template_invocation.rb +1 -1
  40. data/db/migrate/20151124162300_create_job_template_effective_users.rb +1 -1
  41. data/db/migrate/20151203100824_add_description_to_job_invocation.rb +1 -1
  42. data/db/migrate/20151215114631_add_host_id_to_template_invocation.rb +2 -2
  43. data/db/migrate/20151217092555_migrate_to_task_groups.rb +2 -2
  44. data/db/migrate/20160108134600_create_template_input_sets.rb +1 -1
  45. data/db/migrate/20160108141144_make_job_name_default_to_something.rb +1 -1
  46. data/db/migrate/20160111113032_upcase_ssh_feature.rb +2 -2
  47. data/db/migrate/20160113161916_add_run_host_job_task_id_to_template_invocation.rb +1 -1
  48. data/db/migrate/20160113162007_expand_all_template_invocations.rb +3 -3
  49. data/db/migrate/20160114120200_rename_job_categories.rb +1 -1
  50. data/db/migrate/20160114125628_rename_job_name_to_job_category.rb +1 -1
  51. data/db/migrate/20160118124600_create_remote_execution_features.rb +1 -1
  52. data/db/migrate/20160125155108_make_job_template_name_unique.rb +1 -1
  53. data/db/migrate/20160127134031_add_advanced_to_template_input.rb +1 -1
  54. data/db/migrate/20160127162711_reword_puppet_template_description.rb +1 -1
  55. data/db/migrate/20160203104056_add_concurrency_options_to_job_invocation.rb +1 -1
  56. data/db/migrate/20160926225841_update_template_input_value.rb +1 -1
  57. data/db/migrate/20170110145641_add_host_action_button_to_remote_execution_feature.rb +1 -1
  58. data/db/migrate/20170613101039_add_timeout_to_job_templates_and_job_invocations.rb +1 -1
  59. data/db/migrate/20180110104432_rename_template_invocation_permission.rb +25 -0
  60. data/db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb +14 -0
  61. data/db/seeds.d/90-bookmarks.rb +1 -1
  62. data/foreman_remote_execution.gemspec +2 -1
  63. data/lib/foreman_remote_execution/engine.rb +3 -3
  64. data/lib/foreman_remote_execution/version.rb +1 -1
  65. data/test/benchmark/run_hosts_job_benchmark.rb +10 -10
  66. data/test/benchmark/targeting_benchmark.rb +6 -6
  67. data/test/factories/foreman_remote_execution_factories.rb +14 -14
  68. data/test/functional/api/v2/foreign_input_sets_controller_test.rb +10 -15
  69. data/test/functional/api/v2/job_invocations_controller_test.rb +19 -8
  70. data/test/functional/api/v2/job_templates_controller_test.rb +12 -16
  71. data/test/functional/api/v2/remote_execution_features_controller_test.rb +3 -4
  72. data/test/functional/api/v2/template_inputs_controller_test.rb +8 -13
  73. data/test/test_plugin_helper.rb +4 -4
  74. data/test/unit/actions/run_hosts_job_test.rb +3 -3
  75. data/test/unit/concerns/exportable_test.rb +1 -1
  76. data/test/unit/concerns/foreman_tasks_cleaner_extensions_test.rb +2 -2
  77. data/test/unit/concerns/host_extensions_test.rb +20 -20
  78. data/test/unit/concerns/nic_extensions_test.rb +1 -1
  79. data/test/unit/input_template_renderer_test.rb +86 -86
  80. data/test/unit/job_invocation_composer_test.rb +17 -16
  81. data/test/unit/job_invocation_test.rb +10 -10
  82. data/test/unit/job_template_effective_user_test.rb +2 -2
  83. data/test/unit/job_template_importer_test.rb +3 -3
  84. data/test/unit/job_template_test.rb +15 -15
  85. data/test/unit/remote_execution_feature_test.rb +3 -3
  86. data/test/unit/remote_execution_provider_test.rb +15 -15
  87. data/test/unit/targeting_test.rb +3 -3
  88. data/test/unit/template_input_test.rb +1 -1
  89. data/test/unit/template_invocation_input_value_test.rb +17 -17
  90. metadata +19 -77
  91. data/doc/.gitignore +0 -7
  92. data/doc/Gemfile +0 -7
  93. data/doc/Rakefile +0 -41
  94. data/doc/_config.yml +0 -33
  95. data/doc/plugins/alert_block.rb +0 -27
  96. data/doc/plugins/div_tag.rb +0 -24
  97. data/doc/plugins/graphviz.rb +0 -121
  98. data/doc/plugins/plantuml.rb +0 -84
  99. data/doc/plugins/play.rb +0 -13
  100. data/doc/plugins/tags.rb +0 -137
  101. data/doc/plugins/toc.rb +0 -19
  102. data/doc/source/.nojekyll +0 -0
  103. data/doc/source/404.md +0 -6
  104. data/doc/source/_includes/footer.html +0 -21
  105. data/doc/source/_includes/header.html +0 -59
  106. data/doc/source/_includes/tocify.html +0 -6
  107. data/doc/source/_layouts/default.html +0 -9
  108. data/doc/source/_layouts/page.html +0 -25
  109. data/doc/source/atom.xml +0 -32
  110. data/doc/source/design/index.md +0 -1322
  111. data/doc/source/design/wireframes.pdf +0 -0
  112. data/doc/source/index.md +0 -18
  113. data/doc/source/static/css/bootstrap-responsive.min.css +0 -9
  114. data/doc/source/static/css/bootstrap.min.css +0 -866
  115. data/doc/source/static/css/jquery.tocify.css +0 -128
  116. data/doc/source/static/css/style.css +0 -285
  117. data/doc/source/static/css/syntax.css +0 -60
  118. data/doc/source/static/images/foreman.png +0 -0
  119. data/doc/source/static/images/glyphicons-halflings-white.png +0 -0
  120. data/doc/source/static/images/glyphicons-halflings.png +0 -0
  121. data/doc/source/static/js/bootstrap.min.js +0 -7
  122. data/doc/source/static/js/jquery-ui-1.9.2.custom.min.js +0 -6
  123. data/doc/source/static/js/jquery.js +0 -2
  124. data/doc/source/static/js/jquery.tocify.min.js +0 -3
  125. data/doc/source/static/js/scroll.js +0 -24
@@ -0,0 +1,14 @@
1
+ class FixTaxableTaxonomiesJobTemplate < ActiveRecord::Migration[4.2]
2
+ def up
3
+ # we need to count on the fact that the user might already has assigned the templates
4
+ # to taxonomies after the previous update
5
+ already_present = TaxableTaxonomy.where(:taxable_type => 'JobTemplate').pluck(:taxable_id)
6
+ missing = JobTemplate.unscoped.pluck(:id) - already_present
7
+ TaxableTaxonomy.unscoped.where(:taxable_type => 'Template', :taxable_id => missing).update_all(:taxable_type => 'JobTemplate')
8
+ TaxableTaxonomy.unscoped.where(:taxable_type => 'Template', :taxable_id => already_present).delete_all
9
+ end
10
+
11
+ def down
12
+ TaxableTaxonomy.unscoped.where(:taxable_type => 'JobTemplate').update_all(:taxable_type => 'Template')
13
+ end
14
+ end
@@ -9,7 +9,7 @@ Bookmark.without_auditing do
9
9
  ].each do |input|
10
10
  next if Bookmark.where(:controller => 'job_invocations').find_by(name: input[:name])
11
11
  # TODO audit should be fixed once core #13109 gets merged
12
- next if audit_modified? Bookmark, input[:name]
12
+ next if SeedHelper.audit_modified? Bookmark, input[:name]
13
13
  attributes = { :public => true }.merge(input)
14
14
  b = Bookmark.where(:name => input[:name], :controller => input[:controller]).first || Bookmark.new
15
15
  b.attributes = attributes
@@ -21,13 +21,14 @@ Gem::Specification.new do |s|
21
21
  end
22
22
 
23
23
  s.test_files = `git ls-files test`.split("\n")
24
- s.extra_rdoc_files = `git ls-files doc`.split("\n") + Dir['README*', 'LICENSE']
24
+ s.extra_rdoc_files = Dir['README*', 'LICENSE']
25
25
 
26
26
  s.add_dependency 'deface'
27
27
  s.add_dependency 'dynflow', '~> 0.8.26'
28
28
  s.add_dependency 'foreman_remote_execution_core'
29
29
  s.add_dependency 'foreman-tasks', '>= 0.9.5'
30
30
 
31
+ s.add_development_dependency 'factory_bot_rails', '~> 4.8.0'
31
32
  s.add_development_dependency 'rubocop'
32
33
  s.add_development_dependency 'rdoc'
33
34
  end
@@ -31,7 +31,7 @@ module ForemanRemoteExecution
31
31
 
32
32
  initializer 'foreman_remote_execution.register_plugin', before: :finisher_hook do |_app|
33
33
  Foreman::Plugin.register :foreman_remote_execution do
34
- requires_foreman '>= 1.15'
34
+ requires_foreman '>= 1.17'
35
35
 
36
36
  apipie_documented_controllers ["#{ForemanRemoteExecution::Engine.root}/app/controllers/api/v2/*.rb"]
37
37
 
@@ -56,7 +56,7 @@ module ForemanRemoteExecution
56
56
  'api/v2/job_invocations' => [:create] }, :resource_type => 'JobInvocation'
57
57
  permission :view_job_invocations, { :job_invocations => [:index, :show, :auto_complete_search], :template_invocations => [:show],
58
58
  'api/v2/job_invocations' => [:index, :show, :output] }, :resource_type => 'JobInvocation'
59
- permission :execute_template_invocation, {}, :resource_type => 'TemplateInvocation'
59
+ permission :create_template_invocations, {}, :resource_type => 'TemplateInvocation'
60
60
  # this permissions grants user to get auto completion hints when setting up filters
61
61
  permission :filter_autocompletion_for_template_invocation, { :template_invocations => [ :auto_complete_search, :index ] },
62
62
  :resource_type => 'TemplateInvocation'
@@ -66,7 +66,7 @@ module ForemanRemoteExecution
66
66
  :view_job_templates,
67
67
  :view_job_invocations,
68
68
  :create_job_invocations,
69
- :execute_template_invocation,
69
+ :create_template_invocations,
70
70
  :view_hosts,
71
71
  :view_smart_proxies
72
72
  ].freeze
@@ -1,3 +1,3 @@
1
1
  module ForemanRemoteExecution
2
- VERSION = '1.4.1'.freeze
2
+ VERSION = '1.4.2'.freeze
3
3
  end
@@ -1,10 +1,10 @@
1
1
  require 'benchmark/benchmark_helper'
2
2
  require 'dynflow/testing'
3
3
 
4
- # Add plugin to FactoryGirl's paths
5
- FactoryGirl.definition_file_paths << File.expand_path('../../factories', __FILE__)
6
- FactoryGirl.definition_file_paths << "#{ForemanTasks::Engine.root}/test/factories"
7
- FactoryGirl.reload
4
+ # Add plugin to FactoryBot's paths
5
+ FactoryBot.definition_file_paths << File.expand_path('../../factories', __FILE__)
6
+ FactoryBot.definition_file_paths << "#{ForemanTasks::Engine.root}/test/factories"
7
+ FactoryBot.reload
8
8
 
9
9
  module Actions
10
10
  module RemoteExecution
@@ -23,7 +23,7 @@ module Support
23
23
  end
24
24
 
25
25
  def generate_hosts(total)
26
- FactoryGirl.create_list(:host, total, :comment => "benchmark-#{Foreman.uuid}")
26
+ FactoryBot.create_list(:host, total, :comment => "benchmark-#{Foreman.uuid}")
27
27
  end
28
28
 
29
29
  Rails.logger.level = Logger::ERROR
@@ -43,17 +43,17 @@ class ActionTester
43
43
  end
44
44
 
45
45
  puts 'generating admin user'
46
- admin = FactoryGirl.build(:user, :admin)
46
+ admin = FactoryBot.build(:user, :admin)
47
47
  admin.save(:validate => false)
48
48
  User.current = admin
49
- targeting = FactoryGirl.create(:targeting, :search_query => "comment = benchmark-#{Foreman.uuid}", :user => User.current)
50
- template_invocation = FactoryGirl.build(:template_invocation, :job_invocation => nil)
51
- job_invocation = FactoryGirl.build(:job_invocation, :targeting => targeting, :pattern_template_invocations => [template_invocation]).tap do |invocation|
49
+ targeting = FactoryBot.create(:targeting, :search_query => "comment = benchmark-#{Foreman.uuid}", :user => User.current)
50
+ template_invocation = FactoryBot.build(:template_invocation, :job_invocation => nil)
51
+ job_invocation = FactoryBot.build(:job_invocation, :targeting => targeting, :pattern_template_invocations => [template_invocation]).tap do |invocation|
52
52
  invocation.targeting = targeting
53
53
  invocation.save
54
54
  end
55
55
 
56
- task = FactoryGirl.create(:dynflow_task, :external_id => '1')
56
+ task = FactoryBot.create(:dynflow_task, :external_id => '1')
57
57
  tester = ActionTester.new(task)
58
58
 
59
59
  puts 'generating hosts'
@@ -1,12 +1,12 @@
1
1
  require 'benchmark/benchmark_helper'
2
2
  require 'dynflow/testing'
3
3
 
4
- # Add plugin to FactoryGirl's paths
5
- FactoryGirl.definition_file_paths << File.expand_path('../../factories', __FILE__)
6
- FactoryGirl.reload
4
+ # Add plugin to FactoryBot's paths
5
+ FactoryBot.definition_file_paths << File.expand_path('../../factories', __FILE__)
6
+ FactoryBot.reload
7
7
 
8
8
  def generate_hosts(total)
9
- FactoryGirl.create_list(:host, total, :comment => "benchmark-#{Foreman.uuid}")
9
+ FactoryBot.create_list(:host, total, :comment => "benchmark-#{Foreman.uuid}")
10
10
  end
11
11
 
12
12
  Rails.logger.level = Logger::ERROR
@@ -14,7 +14,7 @@ Rails.logger.level = Logger::ERROR
14
14
  puts 'generating hosts'
15
15
  generate_hosts(1000)
16
16
  puts 'generating admin user'
17
- admin = FactoryGirl.build(:user, :admin)
17
+ admin = FactoryBot.build(:user, :admin)
18
18
  admin.save(:validate => false)
19
19
  User.current = admin
20
20
 
@@ -24,7 +24,7 @@ foreman_benchmark do
24
24
  x.config(:time => 10, :warmup => 0)
25
25
 
26
26
  x.report('rex-targeting-resolve-hosts') do
27
- targeting = FactoryGirl.create(:targeting, :search_query => "comment = benchmark-#{Foreman.uuid}", :user => User.current)
27
+ targeting = FactoryBot.create(:targeting, :search_query => "comment = benchmark-#{Foreman.uuid}", :user => User.current)
28
28
  targeting.resolve_hosts!
29
29
  end
30
30
  end
@@ -1,4 +1,4 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
 
3
3
  factory :job_template do |f|
4
4
  f.sequence(:name) { |n| "Job template #{n}" }
@@ -11,7 +11,7 @@ FactoryGirl.define do
11
11
 
12
12
  trait :with_input do
13
13
  after(:build) do |template, evaluator|
14
- template.template_inputs << FactoryGirl.build(:template_input)
14
+ template.template_inputs << FactoryBot.build(:template_input)
15
15
  end
16
16
  end
17
17
 
@@ -43,15 +43,15 @@ FactoryGirl.define do
43
43
  f.description_format '%{job_category}'
44
44
  trait :with_template do
45
45
  after(:build) do |invocation, evaluator|
46
- invocation.pattern_template_invocations << FactoryGirl.build(:template_invocation)
46
+ invocation.pattern_template_invocations << FactoryBot.build(:template_invocation)
47
47
  end
48
48
 
49
49
  end
50
50
 
51
51
  trait :with_task do
52
52
  after(:build) do |invocation, _evaluator|
53
- invocation.template_invocations << FactoryGirl.build(:template_invocation, :with_task, :with_host)
54
- invocation.task = FactoryGirl.build(:some_task)
53
+ invocation.template_invocations << FactoryBot.build(:template_invocation, :with_task, :with_host)
54
+ invocation.task = FactoryBot.build(:some_task)
55
55
  end
56
56
  end
57
57
  end
@@ -66,19 +66,19 @@ FactoryGirl.define do
66
66
 
67
67
  trait :with_task do
68
68
  after(:build) do |template, _evaluator|
69
- template.run_host_job_task = FactoryGirl.build(:some_task)
69
+ template.run_host_job_task = FactoryBot.build(:some_task)
70
70
  end
71
71
  end
72
72
 
73
73
  trait :with_failed_task do
74
74
  after(:build) do |template, _evaluator|
75
- template.run_host_job_task = FactoryGirl.build(:some_task, :result => 'error')
75
+ template.run_host_job_task = FactoryBot.build(:some_task, :result => 'error')
76
76
  end
77
77
  end
78
78
 
79
79
  trait :with_host do
80
80
  after(:build) do |template, _evaluator|
81
- template.host = FactoryGirl.build(:host)
81
+ template.host = FactoryBot.build(:host)
82
82
  end
83
83
  end
84
84
  end
@@ -93,7 +93,7 @@ FactoryGirl.define do
93
93
  end
94
94
  end
95
95
 
96
- FactoryGirl.modify do
96
+ FactoryBot.modify do
97
97
  factory :feature do
98
98
  trait :ssh do
99
99
  name 'SSH'
@@ -102,14 +102,14 @@ FactoryGirl.modify do
102
102
 
103
103
  factory :smart_proxy do
104
104
  trait :ssh do
105
- features { [FactoryGirl.build(:feature, :ssh)] }
105
+ features { [FactoryBot.create(:feature, :ssh)] }
106
106
  pubkey 'ssh-rsa AAAAB3N...'
107
107
  end
108
108
  end
109
109
 
110
110
  factory :subnet do
111
111
  trait :execution do
112
- remote_execution_proxies { [FactoryGirl.build(:smart_proxy, :ssh)] }
112
+ remote_execution_proxies { [FactoryBot.build(:smart_proxy, :ssh)] }
113
113
  end
114
114
  end
115
115
 
@@ -119,19 +119,19 @@ FactoryGirl.modify do
119
119
  domain
120
120
  subnet do
121
121
  overrides = {
122
- :remote_execution_proxies => [FactoryGirl.create(:smart_proxy, :ssh)]
122
+ :remote_execution_proxies => [FactoryBot.create(:smart_proxy, :ssh)]
123
123
  }
124
124
 
125
125
  overrides[:locations] = [location] unless location.nil?
126
126
  overrides[:organizations] = [organization] unless organization.nil?
127
127
 
128
- FactoryGirl.create(
128
+ FactoryBot.create(
129
129
  :subnet_ipv4,
130
130
  overrides
131
131
  )
132
132
  end
133
133
  interfaces do
134
- [FactoryGirl.build(:nic_primary_and_provision, :ip => subnet.network.sub(/0\Z/, '1'), :execution => true)]
134
+ [FactoryBot.build(:nic_primary_and_provision, :ip => subnet.network.sub(/0\Z/, '1'), :execution => true)]
135
135
  end
136
136
  end
137
137
  end
@@ -4,21 +4,21 @@ module Api
4
4
  module V2
5
5
  class ForeignInputSetsControllerTest < ActionController::TestCase
6
6
  setup do
7
- @template = FactoryGirl.create(:job_template)
8
- @foreign_template = FactoryGirl.create(:job_template, :with_input)
9
- @new_foreign_template = FactoryGirl.create(:job_template, :with_input)
7
+ @template = FactoryBot.create(:job_template)
8
+ @foreign_template = FactoryBot.create(:job_template, :with_input)
9
+ @new_foreign_template = FactoryBot.create(:job_template, :with_input)
10
10
  @input_set = @template.foreign_input_sets.create(:target_template_id => @foreign_template.id)
11
11
  end
12
12
 
13
13
  test 'should get index' do
14
- get :index, :template_id => @template.id
14
+ get :index, params: { :template_id => @template.id }
15
15
  input_sets = ActiveSupport::JSON.decode(@response.body)
16
16
  assert !input_sets.empty?, 'Should respond with input sets'
17
17
  assert_response :success
18
18
  end
19
19
 
20
20
  test 'should get input set detail' do
21
- get :show, :template_id => @template.to_param, :id => @input_set.to_param
21
+ get :show, params: { :template_id => @template.to_param, :id => @input_set.to_param }
22
22
  assert_response :success
23
23
  input_set = ActiveSupport::JSON.decode(@response.body)
24
24
  assert !input_set.empty?
@@ -27,34 +27,29 @@ module Api
27
27
 
28
28
  test 'should create valid' do
29
29
  valid_attrs = { :target_template_id => @new_foreign_template.id }
30
- post :create, :foreign_input_set => valid_attrs, :template_id => @template.to_param
30
+ post :create, params: { :foreign_input_set => valid_attrs, :template_id => @template.to_param }
31
31
  input_set = ActiveSupport::JSON.decode(@response.body)
32
32
  assert_equal input_set['target_template_name'], @new_foreign_template.name
33
33
  assert_response :success
34
34
  end
35
35
 
36
36
  test 'should not create invalid' do
37
- post :create, :template_id => @template.to_param
37
+ post :create, params: { :template_id => @template.to_param }
38
38
  assert_response :unprocessable_entity
39
39
  end
40
40
 
41
41
  test 'should update valid' do
42
- put :update, :template_id => @template.to_param,
43
- :id => @input_set.to_param,
44
- :foreign_input_set => { :include_all => false }
42
+ put :update, params: { :template_id => @template.to_param, :id => @input_set.to_param, :foreign_input_set => { :include_all => false } }
45
43
  assert_response :ok
46
44
  end
47
45
 
48
46
  test 'should not update invalid' do
49
- put :update, :template_id => @template.to_param,
50
- :id => @input_set.to_param,
51
- :foreign_input_set => { :target_template_id => '' }
47
+ put :update, params: { :template_id => @template.to_param, :id => @input_set.to_param, :foreign_input_set => { :target_template_id => '' } }
52
48
  assert_response :unprocessable_entity
53
49
  end
54
50
 
55
51
  test 'should destroy' do
56
- delete :destroy, :template_id => @template.to_param,
57
- :id => @input_set.to_param
52
+ delete :destroy, params: { :template_id => @template.to_param, :id => @input_set.to_param }
58
53
  assert_response :ok
59
54
  refute ForeignInputSet.exists?(@input_set.id)
60
55
  end
@@ -4,8 +4,8 @@ module Api
4
4
  module V2
5
5
  class JobInvocationsControllerTest < ActionController::TestCase
6
6
  setup do
7
- @invocation = FactoryGirl.create(:job_invocation, :with_template)
8
- @template = FactoryGirl.create(:job_template, :with_input)
7
+ @invocation = FactoryBot.create(:job_invocation, :with_template, :with_task)
8
+ @template = FactoryBot.create(:job_template, :with_input)
9
9
  end
10
10
 
11
11
  test 'should get index' do
@@ -16,7 +16,7 @@ module Api
16
16
  end
17
17
 
18
18
  test 'should get invocation detail' do
19
- get :show, :id => @invocation.id
19
+ get :show, params: { :id => @invocation.id }
20
20
  assert_response :success
21
21
  template = ActiveSupport::JSON.decode(@response.body)
22
22
  refute_empty template
@@ -26,7 +26,7 @@ module Api
26
26
  test 'should create valid with job_template_id' do
27
27
  attrs = { :job_category => @template.job_category, :name => 'RandomName', :job_template_id => @template.id,
28
28
  :targeting_type => 'static_query', :search_query => 'foobar'}
29
- post :create, :job_invocation => attrs
29
+ post :create, params: { :job_invocation => attrs }
30
30
 
31
31
  invocation = ActiveSupport::JSON.decode(@response.body)
32
32
  assert_equal attrs[:job_category], invocation['job_category']
@@ -36,7 +36,7 @@ module Api
36
36
  test 'should create with description format overridden' do
37
37
  attrs = { :job_category => @template.job_category, :name => 'RandomName', :job_template_id => @template.id,
38
38
  :targeting_type => 'static_query', :search_query => 'foobar', :description_format => 'format' }
39
- post :create, :job_invocation => attrs
39
+ post :create, params: { :job_invocation => attrs }
40
40
 
41
41
  invocation = ActiveSupport::JSON.decode(@response.body)
42
42
  assert_equal attrs[:description_format], invocation['description']
@@ -47,7 +47,7 @@ module Api
47
47
  :job_template_id => @template.id,:targeting_type => 'static_query',
48
48
  :search_query => 'foobar', :recurrence => {:cron_line => '5 * * * *'}}
49
49
 
50
- post :create, :job_invocation => attrs
50
+ post :create, params: { :job_invocation => attrs }
51
51
  invocation = ActiveSupport::JSON.decode(@response.body)
52
52
  assert_equal invocation['mode'], 'recurring'
53
53
  assert_response :success
@@ -56,13 +56,24 @@ module Api
56
56
  test 'should create with schedule' do
57
57
  attrs = { :job_category => @template.job_category, :name => 'RandomName',
58
58
  :job_template_id => @template.id,:targeting_type => 'static_query',
59
- :search_query => 'foobar', :scheduling => {:start_at => DateTime.now.to_s}}
59
+ :search_query => 'foobar', :scheduling => {:start_at => Time.now.to_s}}
60
60
 
61
- post :create, :job_invocation => attrs
61
+ post :create, params: { :job_invocation => attrs }
62
62
  invocation = ActiveSupport::JSON.decode(@response.body)
63
63
  assert_equal invocation['mode'], 'future'
64
64
  assert_response :success
65
65
  end
66
+
67
+ test 'should provide output for delayed task' do
68
+ host = @invocation.template_invocations_hosts.first
69
+ ForemanTasks::Task.any_instance.expects(:delayed?).returns(true)
70
+ get :output, params: { :job_invocation_id => @invocation.id, :host_id => host.id }
71
+ result = ActiveSupport::JSON.decode(@response.body)
72
+ assert_equal result['delayed'], true
73
+ assert_equal result['refresh'], true
74
+ assert_equal result['output'], []
75
+ assert_response :success
76
+ end
66
77
  end
67
78
  end
68
79
  end
@@ -4,7 +4,7 @@ module Api
4
4
  module V2
5
5
  class JobTemplatesControllerTest < ActionController::TestCase
6
6
  setup do
7
- @template = FactoryGirl.create :job_template
7
+ @template = FactoryBot.create :job_template
8
8
  end
9
9
 
10
10
  test 'should get index' do
@@ -15,17 +15,17 @@ module Api
15
15
  end
16
16
 
17
17
  test 'should get templates of give organization' do
18
- @organization = FactoryGirl.create(:organization)
18
+ @organization = FactoryBot.create(:organization)
19
19
  @template.organizations << @organization
20
20
  @template.save!
21
- get :index, :organization_id => @organization.id
21
+ get :index, params: { :organization_id => @organization.id }
22
22
  templates = ActiveSupport::JSON.decode(@response.body)
23
23
  assert !templates.empty?, 'Should respond with template'
24
24
  assert_response :success
25
25
  end
26
26
 
27
27
  test 'should get template detail' do
28
- get :show, :id => @template.to_param
28
+ get :show, params: { :id => @template.to_param }
29
29
  assert_response :success
30
30
  template = ActiveSupport::JSON.decode(@response.body)
31
31
  assert !template.empty?
@@ -35,7 +35,7 @@ module Api
35
35
  test 'should create valid' do
36
36
  JobTemplate.any_instance.stubs(:valid?).returns(true)
37
37
  valid_attrs = { :template => 'This is a test template', :name => 'RandomName', :provider_type => 'ssh' }
38
- post :create, :job_template => valid_attrs
38
+ post :create, params: { :job_template => valid_attrs }
39
39
  template = ActiveSupport::JSON.decode(@response.body)
40
40
  assert template['name'] == 'RandomName'
41
41
  assert_response :success
@@ -48,26 +48,23 @@ module Api
48
48
 
49
49
  test 'should update valid' do
50
50
  JobTemplate.any_instance.stubs(:valid?).returns(true)
51
- put :update, :id => @template.to_param,
52
- :job_template => { :template => 'blah' }
51
+ put :update, params: { :id => @template.to_param, :job_template => { :template => 'blah' } }
53
52
  assert_response :ok
54
53
  end
55
54
 
56
55
  test 'should not update invalid' do
57
- put :update, :id => @template.to_param,
58
- :job_template => { :name => '' }
56
+ put :update, params: { :id => @template.to_param, :job_template => { :name => '' } }
59
57
  assert_response :unprocessable_entity
60
58
  end
61
59
 
62
60
  test 'should destroy' do
63
- delete :destroy, :id => @template.to_param
61
+ delete :destroy, params: { :id => @template.to_param }
64
62
  assert_response :ok
65
63
  refute JobTemplate.exists?(@template.id)
66
64
  end
67
65
 
68
66
  test 'should clone template' do
69
- post :clone, :id => @template.to_param,
70
- :job_template => {:name => 'MyClone'}
67
+ post :clone, params: { :id => @template.to_param, :job_template => {:name => 'MyClone'} }
71
68
  assert_response :success
72
69
  template = ActiveSupport::JSON.decode(@response.body)
73
70
  assert_equal(template['name'], 'MyClone')
@@ -75,13 +72,12 @@ module Api
75
72
  end
76
73
 
77
74
  test 'clone name should not be blank' do
78
- post :clone, :id => @template.to_param,
79
- :job_template => {:name => ''}
75
+ post :clone, params: { :id => @template.to_param, :job_template => {:name => ''} }
80
76
  assert_response :unprocessable_entity
81
77
  end
82
78
 
83
79
  test 'should export template' do
84
- get :export, :id => @template.to_param
80
+ get :export, params: { :id => @template.to_param }
85
81
  assert_equal @response.body, @template.to_erb
86
82
  assert_response :success
87
83
  end
@@ -89,7 +85,7 @@ module Api
89
85
  test 'should import template' do
90
86
  new_name = @template.name = "#{@template.name}_renamed"
91
87
  erb_data = @template.to_erb
92
- post :import, :template => erb_data
88
+ post :import, params: { :template => erb_data }
93
89
  assert_response :success
94
90
  assert JobTemplate.unscoped.find_by(name: new_name)
95
91
  end