diff --git a/app/models/assignment.rb b/app/models/assignment.rb index 3bd9644ad81..793ac7e223f 100755 --- a/app/models/assignment.rb +++ b/app/models/assignment.rb @@ -483,7 +483,7 @@ def self.export_headers(parent_id) @assignment = Assignment.find(parent_id) fields = [] fields << 'Assignment Name: ' + @assignment.name.to_s - fields << 'Assignment Instructor: ' + User.find(@assignment.instructor_id).name.to_s + fields << 'Assignment Instructor: ' + User.find(@assignment.instructor_id).username.to_s fields end diff --git a/app/models/team.rb b/app/models/team.rb index 8e8edc9cf5e..6305b3c83a1 100755 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -261,7 +261,7 @@ def self.export(csv, parent_id, options, teamtype) if options[:team_name] == 'false' team_members = TeamsUser.where(team_id: team.id) team_members.each do |user| - output.push(user.user) + output.push(user.username) end end csv << output diff --git a/app/models/user.rb b/app/models/user.rb index 9203eeeeaf4..e38248a9cb5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -20,7 +20,7 @@ class User < ApplicationRecord belongs_to :parent, class_name: 'User' belongs_to :role validates :username, presence: true - validates :username, uniqueness: true + validates_uniqueness_of :username, :case_sensitive => true validates :username, format: { without: /\s/ } validates :email, presence: { message: "can't be blank" } diff --git a/spec/models/review_response_map_spec.rb b/spec/models/review_response_map_spec.rb index 32dc3e0f6eb..da88716371d 100755 --- a/spec/models/review_response_map_spec.rb +++ b/spec/models/review_response_map_spec.rb @@ -139,17 +139,17 @@ allow(User).to receive(:find_by).and_return(nil) expect { ReviewResponseMap.import(row_hash, session, 1) }.to raise_error(ArgumentError, 'Cannot find reviewee user.') # when reviewee user exists but reviewee user is not a participant in this assignment - allow(User).to receive(:find_by).with(name: 'name').and_return(student) + allow(User).to receive(:find_by).with(username: 'name').and_return(student) allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil) expect { ReviewResponseMap.import(row_hash, session, 1) }.to raise_error(ArgumentError, 'Reviewee user is not a participant in this assignment.') # when reviewee user exists and reviewee user is a participant in this assignment allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant) allow(AssignmentTeam).to receive(:team).with(participant).and_return(team) ## when reviewer user doesn't exist - allow(User).to receive(:find_by).with(name: 'name1').and_return(nil) + allow(User).to receive(:find_by).with(username: 'name1').and_return(nil) expect { ReviewResponseMap.import(row_hash, session, 1) }.to raise_error(ArgumentError, 'Cannot find reviewer user.') ## when reviewer user exist - allow(User).to receive(:find_by).with(name: 'name1').and_return(student1) + allow(User).to receive(:find_by).with(username: 'name1').and_return(student1) ### when reviewer user is not a participant in this assignment. allow(AssignmentParticipant).to receive(:find_by).with(user_id: 2, parent_id: 1).and_return(nil) expect { ReviewResponseMap.import(row_hash, session, 1) }.to raise_error(ArgumentError, 'Reviewer user is not a participant in this assignment.') @@ -166,7 +166,7 @@ allow(TeamsUser).to receive(:create).with(team_id: 1, user_id: 1).and_return(double('teams_users', id: 1, team_id: 1, user_id: 1)) allow(TeamNode).to receive(:create).with(parent_id: assignment_id, node_object_id: 1).and_return(double('team_node', id: 1, parent_id: 1, node_object_id: 1)) allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('team_user_node', id: 1, parent_id: 1, node_object_id: 1)) - allow(User).to receive(:find_by).with(name: 'name1').and_return(student1) + allow(User).to receive(:find_by).with(username: 'name1').and_return(student1) allow(AssignmentParticipant).to receive(:find_by).with(user_id: 2, parent_id: 1).and_return(participant1) allow(ReviewResponseMap).to receive(:find_or_create_by) .with(reviewed_object_id: 1, reviewer_id: 1, reviewee_id: 1, calibrate_to: false).and_return(review_response_map)