foreman_expire_hosts 6.0.0 → 7.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +78 -0
  3. data/.rubocop.yml +18 -13
  4. data/.rubocop_todo.yml +11 -31
  5. data/Gemfile +2 -0
  6. data/README.md +1 -0
  7. data/app/controllers/concerns/foreman_expire_hosts/api/v2/hosts_controller_extensions.rb +2 -0
  8. data/app/controllers/concerns/foreman_expire_hosts/host_controller_extensions.rb +20 -15
  9. data/app/helpers/concerns/foreman_expire_hosts/audits_helper_extensions.rb +4 -0
  10. data/app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb +5 -22
  11. data/app/helpers/expire_hosts_mailer_helper.rb +3 -0
  12. data/app/helpers/foreman_expire_hosts/hosts_helper.rb +16 -0
  13. data/app/mailers/expire_hosts_mailer.rb +3 -0
  14. data/app/models/concerns/foreman_expire_hosts/host_ext.rb +9 -1
  15. data/app/models/host_status/expiration_status.rb +3 -0
  16. data/app/models/setting/expire_hosts.rb +2 -0
  17. data/app/overrides/add_expired_on_field_to_host_form.rb +4 -2
  18. data/app/overrides/add_expired_on_field_to_host_show.rb +5 -3
  19. data/app/overrides/deleted_expired_host_comment_in_audits.rb +8 -6
  20. data/app/services/foreman_expire_hosts/action/base.rb +9 -2
  21. data/app/services/foreman_expire_hosts/action/delete_expired_hosts.rb +3 -0
  22. data/app/services/foreman_expire_hosts/action/stop_expired_hosts.rb +6 -2
  23. data/app/services/foreman_expire_hosts/expiry_edit_authorizer.rb +2 -0
  24. data/app/services/foreman_expire_hosts/notification/base.rb +12 -3
  25. data/app/services/foreman_expire_hosts/notification/deleted_hosts.rb +2 -0
  26. data/app/services/foreman_expire_hosts/notification/expiry_warning.rb +2 -0
  27. data/app/services/foreman_expire_hosts/notification/failed_deleted_hosts.rb +2 -0
  28. data/app/services/foreman_expire_hosts/notification/failed_stopped_hosts.rb +2 -0
  29. data/app/services/foreman_expire_hosts/notification/stopped_hosts.rb +2 -0
  30. data/app/services/foreman_expire_hosts/safe_destroy.rb +7 -5
  31. data/app/services/foreman_expire_hosts/ui_notifications/hosts/base.rb +4 -1
  32. data/app/services/foreman_expire_hosts/ui_notifications/hosts/expiry_warning.rb +2 -0
  33. data/app/services/foreman_expire_hosts/ui_notifications/hosts/stopped_host.rb +2 -0
  34. data/app/views/api/v2/hosts/expiration.json.rabl +2 -0
  35. data/app/views/hosts/_expired_on_field.html.erb +11 -20
  36. data/app/views/hosts/select_multiple_expiration.html.erb +10 -15
  37. data/config/routes.rb +2 -0
  38. data/db/migrate/20150427101516_add_expiry_on_to_hosts.rb +2 -0
  39. data/db/seeds.d/80_expire_hosts_ui_notification.rb +2 -0
  40. data/extra/foreman_expire_hosts.cron +8 -0
  41. data/foreman_expire_hosts.gemspec +10 -3
  42. data/lib/expire_hosts_notifications.rb +3 -0
  43. data/lib/foreman_expire_hosts.rb +2 -0
  44. data/lib/foreman_expire_hosts/engine.rb +22 -10
  45. data/lib/foreman_expire_hosts/version.rb +3 -1
  46. data/lib/tasks/expired_hosts.rake +3 -1
  47. data/test/factories/foreman_expire_hosts_factories.rb +7 -5
  48. data/test/functional/api/v2/hosts_controller_test.rb +3 -1
  49. data/test/functional/concerns/hosts_controller_extensions_test.rb +3 -1
  50. data/test/helpers/hosts_helper_test.rb +5 -0
  51. data/test/lib/expire_hosts_notifications_test.rb +91 -45
  52. data/test/test_plugin_helper.rb +2 -0
  53. data/test/unit/concerns/host_extensions_test.rb +21 -19
  54. data/test/unit/expire_hosts_mailer_test.rb +6 -0
  55. data/test/unit/expiry_edit_authorizer_test.rb +2 -0
  56. data/test/unit/host_status/expiration_status_test.rb +3 -1
  57. data/test/unit/safe_destroy_test.rb +3 -1
  58. metadata +53 -26
  59. data/app/assets/javascripts/foreman_expire_hosts/application.js +0 -3
  60. data/app/assets/javascripts/foreman_expire_hosts/datepicker_for_host_expired_on_field.js +0 -27
  61. data/app/assets/stylesheets/foreman_expire_hosts/application.scss +0 -4
  62. data/app/overrides/add_js_to_host_index.rb +0 -6
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'deface'
2
- require 'bootstrap-datepicker-rails'
3
4
 
4
5
  module ForemanExpireHosts
5
6
  class Engine < ::Rails::Engine
@@ -24,7 +25,7 @@ module ForemanExpireHosts
24
25
 
25
26
  initializer 'foreman_expire_hosts.register_plugin', :before => :finisher_hook do |_app|
26
27
  Foreman::Plugin.register :foreman_expire_hosts do
27
- requires_foreman '>= 1.18'
28
+ requires_foreman '>= 1.24'
28
29
  register_custom_status HostStatus::ExpirationStatus
29
30
 
30
31
  # strong parameters
@@ -34,22 +35,29 @@ module ForemanExpireHosts
34
35
  permission :edit_host_expiry,
35
36
  {},
36
37
  :resource_type => 'Host'
37
- permission :edit_hosts,
38
- { :hosts => [:select_multiple_expiration, :update_multiple_expiration] },
39
- :resource_type => 'Host'
40
38
  end
41
39
 
40
+ # Extend built in permissions
41
+ Foreman::AccessControl.permission(:edit_hosts).actions.concat [
42
+ 'hosts/select_multiple_expiration',
43
+ 'hosts/update_multiple_expiration'
44
+ ]
45
+
42
46
  extend_rabl_template 'api/v2/hosts/main', 'api/v2/hosts/expiration'
47
+
48
+ describe_host do
49
+ multiple_actions_provider :expire_hosts_host_multiple_actions
50
+ end
43
51
  end
44
52
  end
45
53
 
46
54
  config.to_prepare do
47
55
  begin
48
- Host::Managed.send :include, ForemanExpireHosts::HostExt
49
- HostsHelper.send :include, ForemanExpireHosts::HostsHelperExtensions
50
- HostsController.send :prepend, ForemanExpireHosts::HostControllerExtensions
51
- AuditsHelper.send :include, ForemanExpireHosts::AuditsHelperExtensions
52
- ::Api::V2::HostsController.send :include, ForemanExpireHosts::Api::V2::HostsControllerExtensions
56
+ ::Host::Managed.include ForemanExpireHosts::HostExt
57
+ ::HostsHelper.include ForemanExpireHosts::HostsHelperExtensions
58
+ ::HostsController.prepend ForemanExpireHosts::HostControllerExtensions
59
+ ::AuditsHelper.include ForemanExpireHosts::AuditsHelperExtensions
60
+ ::Api::V2::HostsController.include ForemanExpireHosts::Api::V2::HostsControllerExtensions
53
61
  rescue StandardError => e
54
62
  Rails.logger.warn "ForemanExpireHosts: skipping engine hook (#{e})"
55
63
  end
@@ -61,4 +69,8 @@ module ForemanExpireHosts
61
69
  end
62
70
  end
63
71
  end
72
+
73
+ def self.logger
74
+ Foreman::Logging.logger('foreman_expire_hosts')
75
+ end
64
76
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
- VERSION = '6.0.0'.freeze
4
+ VERSION = '7.0.2'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Tasks
2
4
  namespace :expired_hosts do
3
5
  desc 'Delete all expired hosts, send notification email about expiring hosts'
@@ -24,7 +26,7 @@ namespace :test do
24
26
  end
25
27
 
26
28
  namespace :foreman_expire_hosts do
27
- task :rubocop do
29
+ task :rubocop => :environment do
28
30
  begin
29
31
  require 'rubocop/rake_task'
30
32
  RuboCop::RakeTask.new(:rubocop_foreman_expire_hosts) do |task|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.modify do
2
4
  factory :host do
3
5
  trait :without_validation do
@@ -6,26 +8,26 @@ FactoryBot.modify do
6
8
  end
7
9
 
8
10
  trait :expires_in_a_year do
9
- expired_on Date.today + 365
11
+ expired_on { Date.today + 365 }
10
12
  end
11
13
 
12
14
  trait :expires_in_a_week do
13
- expired_on Date.today + 7
15
+ expired_on { Date.today + 7 }
14
16
  end
15
17
 
16
18
  trait :expires_today do
17
19
  without_validation
18
- expired_on Date.today
20
+ expired_on { Date.today }
19
21
  end
20
22
 
21
23
  trait :expired_grace do
22
24
  without_validation
23
- expired_on Date.today - 1
25
+ expired_on { Date.today - 1 }
24
26
  end
25
27
 
26
28
  trait :expired do
27
29
  without_validation
28
- expired_on Date.today - 356
30
+ expired_on { Date.today - 356 }
29
31
  end
30
32
  end
31
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class Api::V2::HostsControllerTest < ActionController::TestCase
@@ -11,7 +13,7 @@ class Api::V2::HostsControllerTest < ActionController::TestCase
11
13
  get :show, params: { :id => host.to_param }
12
14
  assert_response :success
13
15
  show_response = ActiveSupport::JSON.decode(@response.body)
14
- assert !show_response.empty?
16
+ assert_not_empty show_response
15
17
  assert_equal host.expired_on, show_response['expired_on'].to_date
16
18
  end
17
19
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class HostsControllerTest < ActionController::TestCase
@@ -68,7 +70,7 @@ class HostsControllerTest < ActionController::TestCase
68
70
  test 'should set expiration date' do
69
71
  expiration_date = Date.today + 14
70
72
  params = { :host_ids => @hosts.map(&:id),
71
- :host => { :expired_on => expiration_date } }
73
+ :host => { 'expired_on(1i)' => expiration_date.day.to_s, 'expired_on(2i)' => expiration_date.month.to_s, 'expired_on(3i)' => expiration_date.year.to_s } }
72
74
 
73
75
  post :update_multiple_expiration, params: params, session: set_session_user.merge(:user => users(:admin).id)
74
76
 
@@ -1,7 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class HostsHelperTest < ActionView::TestCase
4
6
  include HostsHelper
7
+ include HostDescriptionHelper
8
+ include PuppetRelatedHelper
9
+ include ForemanExpireHosts::HostsHelper
5
10
  include ApplicationHelper
6
11
 
7
12
  describe '#multiple_actions' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
  require 'notifications_test_helper'
3
5
 
@@ -61,17 +63,22 @@ class ExpireHostsNotificationsTest < ActiveSupport::TestCase
61
63
  context 'with additional recipients' do
62
64
  setup do
63
65
  Setting[:host_expiry_email_recipients] = 'test@example.com, test2.example.com'
64
- FactoryBot.create_list(:host, 2, :expired, :owner => user)
65
66
  end
66
67
 
67
68
  test 'should deliver notification to additional recipients' do
69
+ FactoryBot.create_list(:host, 2, :expired, :owner => user)
68
70
  ExpireHostsNotifications.delete_expired_hosts
69
- assert_equal 3, ActionMailer::Base.deliveries.count
71
+ assert_equal 2, ActionMailer::Base.deliveries.count
70
72
  assert_includes ActionMailer::Base.deliveries.first.subject, 'Deleted expired hosts'
71
73
  assert_includes ActionMailer::Base.deliveries.flat_map(&:to), user.mail
72
74
  assert_includes ActionMailer::Base.deliveries.flat_map(&:to), 'test@example.com'
73
75
  assert_includes ActionMailer::Base.deliveries.flat_map(&:to), 'test2.example.com'
74
76
  end
77
+
78
+ test 'should not deliver a mail notification for empty host list' do
79
+ ExpireHostsNotifications.delete_expired_hosts
80
+ assert_equal 0, ActionMailer::Base.deliveries.count
81
+ end
75
82
  end
76
83
  end
77
84
 
@@ -100,12 +107,35 @@ class ExpireHostsNotificationsTest < ActiveSupport::TestCase
100
107
  end
101
108
  end
102
109
 
110
+ test 'should send no message if host is already be stopped' do
111
+ power_mock.stubs(:ready?).returns(false)
112
+ ExpireHostsNotifications.stop_expired_hosts
113
+ assert_equal 0, ActionMailer::Base.deliveries.count
114
+ end
115
+
103
116
  test 'should send failure message if host cannot be stopped' do
104
117
  power_mock.expects(:stop).returns(false)
105
118
  ExpireHostsNotifications.stop_expired_hosts
106
119
  assert_equal 1, ActionMailer::Base.deliveries.count
107
120
  assert_includes ActionMailer::Base.deliveries.first.subject, 'Failed to stop expired hosts'
108
121
  end
122
+
123
+ context 'with a host expiring today' do
124
+ let(:host) { FactoryBot.create(:host, :expires_today, :on_compute_resource, :owner => user) }
125
+ let(:delete_date) { Date.today + Setting[:days_to_delete_after_host_expiration].to_i }
126
+
127
+ it 'should stop the host and show the correct delete date' do
128
+ power_mock.expects(:stop).returns(true)
129
+ ExpireHostsNotifications.stop_expired_hosts
130
+ assert_equal 1, ActionMailer::Base.deliveries.count
131
+ assert_includes ActionMailer::Base.deliveries.first.subject, 'Stopped expired hosts'
132
+ assert_includes ActionMailer::Base.deliveries.first.body, "These hosts will be destroyed on #{delete_date}."
133
+
134
+ travel_to delete_date do
135
+ assert_includes Host.expired_past_grace_period, host
136
+ end
137
+ end
138
+ end
109
139
  end
110
140
 
111
141
  context '#deliver_expiry_warning_notification' do
@@ -114,59 +144,75 @@ class ExpireHostsNotificationsTest < ActiveSupport::TestCase
114
144
 
115
145
  setup do
116
146
  Setting['notify1_days_before_host_expiry'] = 7
117
- hosts
118
147
  end
119
148
 
120
- test 'should send a ui notification per host' do
121
- assert_difference('blueprint.notifications.count', 2) do
149
+ context 'with expired hosts' do
150
+ setup do
151
+ hosts
152
+ end
153
+
154
+ test 'should send a ui notification per host' do
155
+ assert_difference('blueprint.notifications.count', 2) do
156
+ ExpireHostsNotifications.deliver_expiry_warning_notification
157
+ end
158
+ hosts.each do |host|
159
+ notification = Notification.find_by(
160
+ notification_blueprint_id: blueprint.id,
161
+ subject_id: host.id,
162
+ subject_type: 'Host::Base'
163
+ )
164
+ assert_equal 1, notification.notification_recipients.where(user_id: user.id).count
165
+ end
166
+ end
167
+
168
+ test 'should redisplay read ui notification' do
169
+ ExpireHostsNotifications.deliver_expiry_warning_notification
170
+ notification = Notification.find_by(notification_blueprint_id: blueprint.id, subject_id: hosts.first.id)
171
+ assert_not_nil notification
172
+ assert_equal 1, NotificationRecipient.where(notification_id: notification.id).update_all(seen: true)
122
173
  ExpireHostsNotifications.deliver_expiry_warning_notification
174
+ assert_equal 1, NotificationRecipient.where(notification_id: notification.id, seen: false).count
123
175
  end
124
- hosts.each do |host|
125
- notification = Notification.find_by(
126
- notification_blueprint_id: blueprint.id,
127
- subject_id: host.id,
128
- subject_type: 'Host::Base'
129
- )
130
- assert_equal 1, notification.notification_recipients.where(user_id: user.id).count
176
+
177
+ test 'should send a single notification' do
178
+ ExpireHostsNotifications.deliver_expiry_warning_notification
179
+ assert_equal 1, ActionMailer::Base.deliveries.count
180
+ assert_includes ActionMailer::Base.deliveries.first.subject, 'Expiring hosts in foreman'
131
181
  end
132
- end
133
182
 
134
- test 'should redisplay read ui notification' do
135
- ExpireHostsNotifications.deliver_expiry_warning_notification
136
- notification = Notification.find_by(notification_blueprint_id: blueprint.id, subject_id: hosts.first.id)
137
- assert_not_nil notification
138
- assert_equal 1, NotificationRecipient.where(notification_id: notification.id).update_all(seen: true) # rubocop:disable Rails/SkipsModelValidations
139
- ExpireHostsNotifications.deliver_expiry_warning_notification
140
- assert_equal 1, NotificationRecipient.where(notification_id: notification.id, seen: false).count
141
- end
183
+ test 'should send two notifications for two users' do
184
+ owner2 = FactoryBot.create(:user, :with_mail)
185
+ FactoryBot.create(:host, :expires_in_a_week, :owner => owner2)
186
+ ExpireHostsNotifications.deliver_expiry_warning_notification
187
+ assert_equal 2, ActionMailer::Base.deliveries.count
188
+ assert_includes ActionMailer::Base.deliveries.first.subject, 'Expiring hosts in foreman'
189
+ assert_includes ActionMailer::Base.deliveries.last.subject, 'Expiring hosts in foreman'
190
+ end
142
191
 
143
- test 'should send a single notification' do
144
- ExpireHostsNotifications.deliver_expiry_warning_notification
145
- assert_equal 1, ActionMailer::Base.deliveries.count
146
- assert_includes ActionMailer::Base.deliveries.first.subject, 'Expiring hosts in foreman'
192
+ test 'should send three notifications for three users' do
193
+ user2 = FactoryBot.create(:user, :with_mail)
194
+ user3 = FactoryBot.create(:user, :with_mail, :usergroups => [usergroup])
195
+ FactoryBot.create(:host, :expires_in_a_week, :owner => user2)
196
+ FactoryBot.create(:host, :expires_in_a_week, :owner => usergroup)
197
+ ExpireHostsNotifications.deliver_expiry_warning_notification
198
+ assert_equal 3, ActionMailer::Base.deliveries.count
199
+ assert_includes ActionMailer::Base.deliveries.first.subject, 'Expiring hosts in foreman'
200
+ assert_includes ActionMailer::Base.deliveries.flat_map(&:to), user.mail
201
+ assert_includes ActionMailer::Base.deliveries.flat_map(&:to), user2.mail
202
+ assert_includes ActionMailer::Base.deliveries.flat_map(&:to), user3.mail
203
+ assert_equal 1, ActionMailer::Base.deliveries.flat_map(&:subject).uniq.count
204
+ end
147
205
  end
148
206
 
149
- test 'should send two notifications for two users' do
150
- owner2 = FactoryBot.create(:user, :with_mail)
151
- FactoryBot.create(:host, :expires_in_a_week, :owner => owner2)
152
- ExpireHostsNotifications.deliver_expiry_warning_notification
153
- assert_equal 2, ActionMailer::Base.deliveries.count
154
- assert_includes ActionMailer::Base.deliveries.first.subject, 'Expiring hosts in foreman'
155
- assert_includes ActionMailer::Base.deliveries.last.subject, 'Expiring hosts in foreman'
156
- end
207
+ context 'with additional recipients' do
208
+ setup do
209
+ Setting[:host_expiry_email_recipients] = 'test@example.com, test2.example.com'
210
+ end
157
211
 
158
- test 'should send three notifications for three users' do
159
- user2 = FactoryBot.create(:user, :with_mail)
160
- user3 = FactoryBot.create(:user, :with_mail, :usergroups => [usergroup])
161
- FactoryBot.create(:host, :expires_in_a_week, :owner => user2)
162
- FactoryBot.create(:host, :expires_in_a_week, :owner => usergroup)
163
- ExpireHostsNotifications.deliver_expiry_warning_notification
164
- assert_equal 3, ActionMailer::Base.deliveries.count
165
- assert_includes ActionMailer::Base.deliveries.first.subject, 'Expiring hosts in foreman'
166
- assert_includes ActionMailer::Base.deliveries.flat_map(&:to), user.mail
167
- assert_includes ActionMailer::Base.deliveries.flat_map(&:to), user2.mail
168
- assert_includes ActionMailer::Base.deliveries.flat_map(&:to), user3.mail
169
- assert_equal 1, ActionMailer::Base.deliveries.flat_map(&:subject).uniq.count
212
+ test 'should not send empty reminders' do
213
+ ExpireHostsNotifications.deliver_expiry_warning_notification
214
+ assert_equal 0, ActionMailer::Base.deliveries.count
215
+ end
170
216
  end
171
217
  end
172
218
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This calls the main test_helper in Foreman-core
2
4
  require 'test_helper'
3
5
  require 'database_cleaner'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
@@ -26,7 +28,7 @@ class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
26
28
 
27
29
  test 'should require expired on' do
28
30
  host = FactoryBot.build(:host)
29
- refute host.valid?, "Can not be valid without expiration date: #{host.errors.messages}"
31
+ assert_not host.valid?, "Can not be valid without expiration date: #{host.errors.messages}"
30
32
  assert_includes host.errors.messages.keys, :expired_on
31
33
  end
32
34
  end
@@ -99,23 +101,23 @@ class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
99
101
  end
100
102
 
101
103
  test 'should not expire' do
102
- refute @host.expires?
104
+ assert_not @host.expires?
103
105
  end
104
106
 
105
107
  test 'should not expire today' do
106
- refute @host.expires_today?
108
+ assert_not @host.expires_today?
107
109
  end
108
110
 
109
111
  test 'should not be expired' do
110
- refute @host.expired?
112
+ assert_not @host.expired?
111
113
  end
112
114
 
113
115
  test 'should not be expired past grace period' do
114
- refute @host.expired_past_grace_period?
116
+ assert_not @host.expired_past_grace_period?
115
117
  end
116
118
 
117
119
  test 'should not be pending expiration' do
118
- refute @host.pending_expiration?
120
+ assert_not @host.pending_expiration?
119
121
  end
120
122
 
121
123
  test 'should not be in any expiration scopes' do
@@ -133,7 +135,7 @@ class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
133
135
  end
134
136
 
135
137
  test 'should not expire today' do
136
- refute @host.expires_today?
138
+ assert_not @host.expires_today?
137
139
  end
138
140
 
139
141
  test 'should be expired' do
@@ -145,7 +147,7 @@ class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
145
147
  end
146
148
 
147
149
  test 'should not be pending expiration' do
148
- refute @host.pending_expiration?
150
+ assert_not @host.pending_expiration?
149
151
  end
150
152
 
151
153
  test 'should only exist in correct scopes' do
@@ -168,11 +170,11 @@ class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
168
170
  end
169
171
 
170
172
  test 'should not be expired' do
171
- refute @host.expired?
173
+ assert_not @host.expired?
172
174
  end
173
175
 
174
176
  test 'should not be expired past grace period' do
175
- refute @host.expired_past_grace_period?
177
+ assert_not @host.expired_past_grace_period?
176
178
  end
177
179
 
178
180
  test 'should be pending expiration' do
@@ -180,7 +182,7 @@ class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
180
182
  end
181
183
 
182
184
  test 'should only exist in correct scopes' do
183
- exists_only_in_scopes(@host, ['expiring', 'expiring_today'])
185
+ exists_only_in_scopes(@host, ['expiring', 'expired', 'expiring_today'])
184
186
  end
185
187
  end
186
188
 
@@ -195,19 +197,19 @@ class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
195
197
  end
196
198
 
197
199
  test 'should not expire today' do
198
- refute @host.expires_today?
200
+ assert_not @host.expires_today?
199
201
  end
200
202
 
201
203
  test 'should not be expired' do
202
- refute @host.expired?
204
+ assert_not @host.expired?
203
205
  end
204
206
 
205
207
  test 'should not be expired past grace period' do
206
- refute @host.expired_past_grace_period?
208
+ assert_not @host.expired_past_grace_period?
207
209
  end
208
210
 
209
211
  test 'should not be pending expiration' do
210
- refute @host.pending_expiration?
212
+ assert_not @host.pending_expiration?
211
213
  end
212
214
 
213
215
  test 'should only exist in correct scopes' do
@@ -225,7 +227,7 @@ class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
225
227
  end
226
228
 
227
229
  test 'should not expire today' do
228
- refute @host.expires_today?
230
+ assert_not @host.expires_today?
229
231
  end
230
232
 
231
233
  test 'should be expired' do
@@ -233,11 +235,11 @@ class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
233
235
  end
234
236
 
235
237
  test 'should not be expired past grace period' do
236
- refute @host.expired_past_grace_period?
238
+ assert_not @host.expired_past_grace_period?
237
239
  end
238
240
 
239
241
  test 'should not be pending expiration' do
240
- refute @host.pending_expiration?
242
+ assert_not @host.pending_expiration?
241
243
  end
242
244
 
243
245
  test 'should only exist in correct scopes' do
@@ -250,7 +252,7 @@ class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
250
252
  def exists_only_in_scopes(host, valid_scopes)
251
253
  host.save(validate: false)
252
254
  (EXPIRATION_SCOPES - valid_scopes).each do |scope|
253
- refute Host::Managed.send(scope).exists?(host.id), "Host should not exist in #{scope} scope"
255
+ assert_not Host::Managed.send(scope).exists?(host.id), "Host should not exist in #{scope} scope"
254
256
  end
255
257
  valid_scopes.each do |scope|
256
258
  assert Host::Managed.send(scope).exists?(host.id), "Host should exist in #{scope} scope"