# Copies members from +project+
def copy_members(project)
- project.memberships.each do |member|
+ # Copy users first, then groups to handle members with inherited and given roles
+ members_to_copy = []
+ members_to_copy += project.memberships.select {|m| m.principal.is_a?(User)}
+ members_to_copy += project.memberships.select {|m| !m.principal.is_a?(User)}
+
+ members_to_copy.each do |member|
new_member = Member.new
new_member.attributes = member.attributes.dup.except("id", "project_id", "created_on")
# only copy non inherited roles
assert_equal @project, membership.project
end
end
+
+ should "copy memberships with groups and additional roles" do
+ group = Group.create!(:lastname => "Copy group")
+ user = User.find(7)
+ group.users << user
+ # group role
+ Member.create!(:project_id => @source_project.id, :principal => group, :role_ids => [2])
+ member = Member.find_by_user_id_and_project_id(user.id, @source_project.id)
+ # additional role
+ member.role_ids = [1]
+
+ assert @project.copy(@source_project)
+ member = Member.find_by_user_id_and_project_id(user.id, @project.id)
+ assert_not_nil member
+ assert_equal [1, 2], member.role_ids.sort
+ end
should "copy project specific queries" do
assert @project.valid?