Skip to content

Commit

Permalink
Add logging for govpay_status changes in Order model
Browse files Browse the repository at this point in the history
- Introduced `before_save` callback to log changes in `govpay_status`.
- Added `log_govpay_status_change` method to log old and new status with caller information.
- Implemented `find_relevant_caller` method to filter out irrelevant caller locations.
  • Loading branch information
jjromeo committed Sep 27, 2024
1 parent 49eb018 commit ed36a08
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion app/models/waste_carriers_engine/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Order
field :manualOrder, as: :manual_order, type: String
field :order_item_reference, type: String


before_save :log_govpay_status_change

def self.new_order_for(user_email)
order = Order.new

Expand Down Expand Up @@ -79,11 +82,35 @@ def generate_description
return unless order_items.any?

description = order_items.map(&:description)
.join(", plus ")
.join(", plus ")

description[0] = description[0].capitalize

description
end

def log_govpay_status_change
if govpay_status_changed?
caller_info = find_relevant_caller

Rails.logger.info <<~LOG_MESSAGE
*******************************************
!!!!! GOVPAY STATUS CHANGED !!!!!
Previous status: #{govpay_status_was || 'NIL'}
Current status: #{govpay_status}
Changed in file: #{caller_info}
*******************************************
LOG_MESSAGE
end
end

def find_relevant_caller
caller_locations.find do |loc|
!loc.path.include?('mongoid') &&
!loc.path.include?('activesupport') &&
!loc.path.include?('active_model') &&
!loc.path.end_with?('order.rb')
end.to_s
end
end
end

0 comments on commit ed36a08

Please sign in to comment.