]> source.dussan.org Git - redmine.git/commitdiff
Use regular instance methods instead of association extensions.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 3 Jun 2017 08:04:13 +0000 (08:04 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 3 Jun 2017 08:04:13 +0000 (08:04 +0000)
Rails 5.1 seems to mess things up in this particular case (role.workflow_rules.copy calls the extension declare in Tracker model).

git-svn-id: http://svn.redmine.org/redmine/trunk@16597 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/roles_controller.rb
app/controllers/trackers_controller.rb
app/models/role.rb
app/models/tracker.rb
app/models/workflow_rule.rb
test/unit/role_test.rb
test/unit/tracker_test.rb

index d134e1f67c2ce494a763e7f0dcd7fe3009a3b47b..6071e767bf8586560fbd1a77c46393c787ca5070 100644 (file)
@@ -60,7 +60,7 @@ class RolesController < ApplicationController
     if request.post? && @role.save
       # workflow copy
       if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
-        @role.workflow_rules.copy(copy_from)
+        @role.copy_workflow_rules(copy_from)
       end
       flash[:notice] = l(:notice_successful_create)
       redirect_to roles_path
index 5bae880d14552916aca6d715ddb8f2f7a22851a4..c624133a7a43b6f1fcdaa1d8cf2f59689a4224c6 100644 (file)
@@ -44,7 +44,7 @@ class TrackersController < ApplicationController
     if @tracker.save
       # workflow copy
       if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from]))
-        @tracker.workflow_rules.copy(copy_from)
+        @tracker.copy_workflow_rules(copy_from)
       end
       flash[:notice] = l(:notice_successful_create)
       redirect_to trackers_path
index 8f72b6c52007a89d21b97503b206f623004745cb..b5be7417993b81cb2e0508c8a243f2bdf0bc1ea4 100644 (file)
@@ -61,7 +61,8 @@ class Role < ActiveRecord::Base
   before_destroy :check_deletable
   has_many :workflow_rules, :dependent => :delete_all do
     def copy(source_role)
-      WorkflowRule.copy(nil, source_role, nil, proxy_association.owner)
+      ActiveSupport::Deprecation.warn "role.workflow_rules.copy is deprecated and will be removed in Redmine 4.0, use role.copy_worflow_rules instead"
+      proxy_association.owner.copy_workflow_rules(source_role)
     end
   end
   has_and_belongs_to_many :custom_fields, :join_table => "#{table_name_prefix}custom_fields_roles#{table_name_suffix}", :foreign_key => "role_id"
@@ -261,6 +262,10 @@ class Role < ActiveRecord::Base
     self
   end
 
+  def copy_workflow_rules(source_role)
+    WorkflowRule.copy(nil, source_role, nil, self)
+  end
+
   # Find all the roles that can be given to a project member
   def self.find_all_givable
     Role.givable.to_a
index 9c19111b17bee38a5f1dee86b0ed06b6d411b1c0..4004e80d2ec7a4d3ea7541951e083cdbddcf0c26 100644 (file)
@@ -29,10 +29,10 @@ class Tracker < ActiveRecord::Base
   has_many :issues
   has_many :workflow_rules, :dependent => :delete_all do
     def copy(source_tracker)
-      WorkflowRule.copy(source_tracker, nil, proxy_association.owner, nil)
+      ActiveSupport::Deprecation.warn "tracker.workflow_rules.copy is deprecated and will be removed in Redmine 4.0, use tracker.copy_worflow_rules instead"
+      proxy_association.owner.copy_workflow_rules(source_tracker)
     end
   end
-
   has_and_belongs_to_many :projects
   has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
   acts_as_positioned
@@ -121,6 +121,10 @@ class Tracker < ActiveRecord::Base
     core_fields
   end
 
+  def copy_workflow_rules(source_tracker)
+    WorkflowRule.copy(source_tracker, nil, self, nil)
+  end
+
   # Returns the fields that are disabled for all the given trackers
   def self.disabled_core_fields(trackers)
     if trackers.present?
index da7a91f436ff861cf02c051b34c447f9d2093e04..d6df726f7446aa8c8dfef6c2825dce74bfa2b4d5 100644 (file)
@@ -29,7 +29,7 @@ class WorkflowRule < ActiveRecord::Base
   # Copies workflows from source to targets
   def self.copy(source_tracker, source_role, target_trackers, target_roles)
     unless source_tracker.is_a?(Tracker) || source_role.is_a?(Role)
-      raise ArgumentError.new("source_tracker or source_role must be specified")
+      raise ArgumentError.new("source_tracker or source_role must be specified, given: #{source_tracker.class.name} and #{source_role.class.name}")
     end
 
     target_trackers = [target_trackers].flatten.compact
index 092df322ef4c1485d29f8cc1ae5179db77364d67..9ddac8c778b99ab333ac8c77c8019010fc439d04 100644 (file)
@@ -59,7 +59,7 @@ class RoleTest < ActiveSupport::TestCase
 
     target = Role.new(:name => 'Target')
     assert target.save
-    target.workflow_rules.copy(source)
+    target.copy_workflow_rules(source)
     target.reload
     assert_equal rule_count, target.workflow_rules.size
   end
index ad842a753c92c3ed4b11a83b6092d2b0701fadb4..99ea47b4ff15a2846254a5f88a29235ebc9d6740 100644 (file)
@@ -47,7 +47,7 @@ class TrackerTest < ActiveSupport::TestCase
 
     target = Tracker.new(:name => 'Target', :default_status_id => 1)
     assert target.save
-    target.workflow_rules.copy(source)
+    target.copy_workflow_rules(source)
     target.reload
     assert_equal rules_count, target.workflow_rules.size
   end