Created
December 10, 2013 14:10
-
-
Save mschuerig/7891143 to your computer and use it in GitHub Desktop.
Mongoid: Raise an exception and log errors if the identity map contains changed but unsaved objects after a request was processed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless Rails.env.production? | |
after_filter do | |
objects = Mongoid::IdentityMap.values.flat_map(&:values) | |
changed_objects = objects.select { |o| o.changes.except('updated_at', 'locked_at', 'locked_until').present? } | |
unsaved_objects = changed_objects.select { |o| o.errors.empty? } | |
unless unsaved_objects.empty? | |
unsaved_objects.each do |obj| | |
Rails.logger.error "Unsaved object: #{obj.inspect}\n Changes: #{obj.changes.inspect}" | |
end | |
raise "Some changed objects have not been saved. See log for details." | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment