]> source.dussan.org Git - redmine.git/commitdiff
Replace Member.find_or_new with ActiveRecord's find_or_initialize_by (#36730).
authorGo MAEDA <maeda@farend.jp>
Mon, 14 Mar 2022 14:25:24 +0000 (14:25 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 14 Mar 2022 14:25:24 +0000 (14:25 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@21456 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/member.rb
app/models/project.rb
test/integration/api_test/issues_test.rb

index 784c980989d8ec2455112013073818bfb71b46f5..5a0692a5d570c96dd719c45479703133c65ceb9d 100644 (file)
@@ -208,7 +208,7 @@ class Member < ActiveRecord::Base
       project_ids = Array.wrap(attributes[:project_ids] || attributes[:project_id])
       role_ids = Array.wrap(attributes[:role_ids])
       project_ids.each do |project_id|
-        member = Member.find_or_new(project_id, principal)
+        member = Member.find_or_initialize_by(:project_id => project_id, :user_id => principal.id)
         member.role_ids |= role_ids
         member.save
         members << member
@@ -217,16 +217,6 @@ class Member < ActiveRecord::Base
     members
   end
 
-  # Finds or initializes a Member for the given project and principal
-  def self.find_or_new(project, principal)
-    project_id = project.is_a?(Project) ? project.id : project
-    principal_id = principal.is_a?(Principal) ? principal.id : principal
-
-    member = Member.find_by_project_id_and_user_id(project_id, principal_id)
-    member ||= Member.new(:project_id => project_id, :user_id => principal_id)
-    member
-  end
-
   protected
 
   def validate_role
index 4e15b19c8a65839fc906788247dae4f18791def0..90ef0e2e95060e910872a8a4a6457e1964320708 100644 (file)
@@ -1001,7 +1001,7 @@ class Project < ActiveRecord::Base
   def add_inherited_member_roles
     if inherit_members? && parent
       parent.memberships.each do |parent_member|
-        member = Member.find_or_new(self.id, parent_member.user_id)
+        member = Member.find_or_initialize_by(:project_id => self.id, :user_id => parent_member.user_id)
         parent_member.member_roles.each do |parent_member_role|
           member.member_roles <<
             MemberRole.new(:role => parent_member_role.role,
index 64ac2d4c88cf03fc4e9d33c68a3cdcd0c4a1963c..29b3390d21c6234c8df3516a0c5b395a32ae572e 100644 (file)
@@ -437,7 +437,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
     issue = Issue.find(1)
     assert_equal 1, issue.tracker_id  # Bug
     issue.update(:status_id => 2)     # Assigned
-    member = Member.find_or_new(issue.project, User.find_by_login('dlopper'))
+    member = Member.find_by(:project => issue.project, :user => User.find_by(:login => 'dlopper'))
     assert_equal [2], member.role_ids # Developer
 
     get '/issues/1.xml?include=allowed_statuses', :headers => credentials('dlopper', 'foo')