summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/member.rb12
-rw-r--r--app/models/project.rb2
-rw-r--r--test/integration/api_test/issues_test.rb2
3 files changed, 3 insertions, 13 deletions
diff --git a/app/models/member.rb b/app/models/member.rb
index 784c98098..5a0692a5d 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -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
diff --git a/app/models/project.rb b/app/models/project.rb
index 4e15b19c8..90ef0e2e9 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -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,
diff --git a/test/integration/api_test/issues_test.rb b/test/integration/api_test/issues_test.rb
index 64ac2d4c8..29b3390d2 100644
--- a/test/integration/api_test/issues_test.rb
+++ b/test/integration/api_test/issues_test.rb
@@ -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')