Skip to content

Commit d42f66f

Browse files
committed
Move callbacks before save for #changed? and #changes?
1 parent eb74c6c commit d42f66f

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

app/models/ext_management_system.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ def edit_with_params(params, endpoints, authentications)
193193
endpoints_changed ||= ems.endpoints.any?(&:changed?)
194194
authentications_changed ||= ems.authentications.any?(&:changed?)
195195

196+
after_update_endpoints if endpoints_changed
197+
after_update_authentication if authentications_changed
198+
196199
ems.provider.save! if ems.provider.present? && ems.provider.changed?
197200
ems.save!
198201
end
199-
200-
after_update_endpoints if endpoints_changed
201-
after_update_authentication if authentications_changed
202202
end
203203
end
204204

@@ -920,14 +920,14 @@ def stop_event_monitor_queue
920920
end
921921

922922
def stop_event_monitor_queue_on_change
923-
if event_monitor_class && !self.new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress")
923+
if event_monitor_class && !new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress")
924924
_log.info("EMS: [#{name}], Hostname or IP address has changed, stopping Event Monitor. It will be restarted by the WorkerMonitor.")
925925
stop_event_monitor_queue
926926
end
927927
end
928928

929929
def stop_event_monitor_queue_on_credential_change
930-
if event_monitor_class && !self.new_record? && self.credentials_changed?
930+
if event_monitor_class && !new_record? && default_authentication&.changed?
931931
_log.info("EMS: [#{name}], Credentials have changed, stopping Event Monitor. It will be restarted by the WorkerMonitor.")
932932
stop_event_monitor_queue
933933
end
@@ -984,14 +984,14 @@ def stop_refresh_worker_queue
984984
end
985985

986986
def stop_refresh_worker_queue_on_change
987-
if refresh_worker_class && !self.new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress")
987+
if refresh_worker_class && !new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress")
988988
_log.info("EMS: [#{name}], Hostname or IP address has changed, stopping Refresh Worker. It will be restarted by the WorkerMonitor.")
989989
stop_refresh_worker_queue
990990
end
991991
end
992992

993993
def stop_refresh_worker_queue_on_credential_change
994-
if refresh_worker_class && !self.new_record? && self.credentials_changed?
994+
if refresh_worker_class && !new_record? && default_authentication&.changed?
995995
_log.info("EMS: [#{name}], Credentials have changed, stopping Refresh Worker. It will be restarted by the WorkerMonitor.")
996996
stop_refresh_worker_queue
997997
end

spec/models/ext_management_system_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,12 @@ def deliver_queue_message(queue_message = MiqQueue.order(:id).first)
931931

932932
ems.edit_with_params(params, endpoints, authentications)
933933
end
934+
935+
it "stops the event monitor" do
936+
expect(ems).to receive(:stop_event_monitor_queue)
937+
938+
ems.edit_with_params(params, endpoints, authentications)
939+
end
934940
end
935941

936942
context "adding an authentication" do
@@ -985,6 +991,12 @@ def deliver_queue_message(queue_message = MiqQueue.order(:id).first)
985991

986992
ems.edit_with_params(params, endpoints, authentications)
987993
end
994+
995+
it "stops the event monitor" do
996+
expect(ems).to receive(:stop_event_monitor_queue)
997+
998+
ems.edit_with_params(params, endpoints, authentications)
999+
end
9881000
end
9891001
end
9901002

0 commit comments

Comments
 (0)