diff --git a/app/services/projects/import_export/members_mapper.rb b/app/services/projects/import_export/members_mapper.rb index 56abc131b16a81a7fc05009c6c5d2886188827b5..634683da5ce12ed2852073b1fdf7015237321a52 100644 --- a/app/services/projects/import_export/members_mapper.rb +++ b/app/services/projects/import_export/members_mapper.rb @@ -30,13 +30,14 @@ module Projects def assign_member(existing_user, member) member['user'] = existing_user project_member = ProjectMember.new(member_hash(member)) - @project_member_map[member['id']] = project_member if project_member.save + @project_member_map[existing_user.id] = project_member if project_member.save end def member_hash(member) member.except('id').merge(source_id: @project_id) end + #TODO: If default, then we need to leave a comment 'Comment by <original username>' on comments def default_project_member @default_project_member ||= begin diff --git a/spec/services/projects/import_export/members_mapper_spec.rb b/spec/services/projects/import_export/members_mapper_spec.rb index 431626d5e78f32cf8c436cfc64dcb2d7e6a98404..dc6ccb5012187b839ef565d8fbb392fbd6ce6bfa 100644 --- a/spec/services/projects/import_export/members_mapper_spec.rb +++ b/spec/services/projects/import_export/members_mapper_spec.rb @@ -6,21 +6,27 @@ describe Projects::ImportExport::MembersMapper, services: true do let(:user) { create(:user) } let(:project) { create(:project, :public, name: 'searchable_project') } let(:user2) { create(:user) } - let(:exported_members) { [ - { - "id" => 2, - "access_level" => 40, - "source_id" => 14, - "source_type" => "Project", - "user_id" => 19, - "notification_level" => 3, - "created_at" => "2016-03-11T10:21:44.822Z", - "updated_at" => "2016-03-11T10:21:44.822Z", - "created_by_id" => nil, - "invite_email" => nil, - "invite_token" => nil, - "invite_accepted_at" => nil, - "user" => { "email" => user2.email, "username" => user2.username } }] } + let(:exported_members) do + [{ + "id" => 2, + "access_level" => 40, + "source_id" => 14, + "source_type" => "Project", + "user_id" => 19, + "notification_level" => 3, + "created_at" => "2016-03-11T10:21:44.822Z", + "updated_at" => "2016-03-11T10:21:44.822Z", + "created_by_id" => nil, + "invite_email" => nil, + "invite_token" => nil, + "invite_accepted_at" => nil, + "user" => + { + "email" => user2.email, + "username" => user2.username + } + }] + end let(:members_mapper) do Projects::ImportExport::MembersMapper.new( @@ -28,15 +34,15 @@ describe Projects::ImportExport::MembersMapper, services: true do end it 'maps a project member' do - expect(project_member_map_id(user2.id)).to eq(user2.id) + expect(project_member_user_id(user2.id)).to eq(user2.id) end it 'defaults to importer project member if it does not exist' do - expect(project_member_map_id(-1)).to eq(user.id) + expect(project_member_user_id(-1)).to eq(user.id) end end - def project_member_map_id(id) - members_mapper.map[id]['id'] + def project_member_user_id(id) + members_mapper.map[id].user.id end end