anteo / redmine_custom_workflows

Allows to create custom workflows for Redmine
http://www.redmine.org/plugins/custom-workflows
GNU General Public License v2.0
182 stars 72 forks source link

IssueRelation.to_s is broken after #257 #258

Closed dmakurin closed 2 years ago

dmakurin commented 2 years ago

Yes it fixed error in ruby 3.0 but current redmine version does not use nor support ruby 3.0. You should at least provide backward compatibility.

dmakurin commented 2 years ago

Turns out redmine actually supports ruby 3.0 (https://www.redmine.org/issues/34992). But compatibility for 2.7 would be great since it is still a maintainable version.

picman commented 2 years ago

Just tested width Ruby 2.7 and it seems to be working.

# ruby -v
ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux-gnu]

Could you add some details to your problem, please? production.log, Ruby version, Redmine version,...

dmakurin commented 2 years ago

Well its actually working but there is no link to issue:

screenshot ![image](https://user-images.githubusercontent.com/49897128/168083506-d5e46fae-a430-4cac-aab0-46407778d738.png)

Problem is that block https://github.com/redmine/redmine/blob/2a60a7bd7940dcde74202163f36becf53df7f9b3/app/helpers/issues_helper.rb#L232 got nothing when you use &Proc.new{}

Tested on https://github.com/redmine/redmine/tree/5.0-stable

ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [x86_64-linux]

Rails 6.1.6

Something like this would fix it:

diff --git a/lib/redmine_custom_workflows/patches/issue_relation_patch.rb b/lib/redmine_custom_workflows/patches/issue_relation_patch.rb
index 1e67623..d3daf70 100644
--- a/lib/redmine_custom_workflows/patches/issue_relation_patch.rb
+++ b/lib/redmine_custom_workflows/patches/issue_relation_patch.rb
@@ -36,7 +36,15 @@ module RedmineCustomWorkflows
           alias_method :old_to_s, :to_s

           def to_s(issue=nil)
-            block_given? ? old_to_s(issue, &Proc.new {}) : old_to_s(issue)
+            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
           rescue NoMethodError => e
             if issue_from.present? || issue_to.present?
               raise e
picman commented 2 years ago

Very well. I've applied your patch. Could you test, the devel branch now, please?

P.S. A pull request next time, please.

dmakurin commented 2 years ago

Yeah, it works. Thank you.

picman commented 2 years ago

I've just fixed it a bit more professionally. It should work in Ruby 2.7 and 3.0 too.