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
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
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,
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')