IssueRelation.to_s is broken #258

This commit is contained in:
Karel Pičman 2022-05-18 12:46:16 +02:00
parent 841c30d25c
commit 3b19b30648

View File

@ -30,30 +30,30 @@ module RedmineCustomWorkflows
after_save :after_save_custom_workflows
before_destroy :before_destroy_custom_workflows
after_destroy :after_destroy_custom_workflows
end
# override IssueRelation.to_s to rescue NoMethodError during CustomWorkflow.validate_syntax due to
# logging of temporarily instatiated IssueRelation with no related issues set
alias_method :old_to_s, :to_s
base.prepend InstanceMethods
end
module InstanceMethods
################################################################################################################
# Overriden methods
# Override IssueRelation.to_s to rescue NoMethodError during CustomWorkflow.validate_syntax due to
# logging of temporarily instatiated IssueRelation with no related issues set.
def to_s(issue=nil)
if block_given?
if Gem.ruby_version < Gem::Version.new('3.0')
old_to_s issue, &Proc.new
else
old_to_s issue, &Proc.new {}
end
else
old_to_s issue
end
super
rescue NoMethodError => e
if issue_from.present? || issue_to.present?
raise e
end
self.class.to_s
end
end
end
################################################################################################################
# New methods
def before_save_custom_workflows
@issue_relation = self
@saved_attributes = attributes.dup
@ -78,6 +78,8 @@ module RedmineCustomWorkflows
end
end
end
end
end