Skip to content

Commit

Permalink
chore: fixed more incorrect refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
brwali committed Oct 27, 2024
1 parent df5ac31 commit eb9bb42
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/models/assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
8 changes: 4 additions & 4 deletions spec/models/review_response_map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand All @@ -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)
Expand Down

0 comments on commit eb9bb42

Please sign in to comment.