Skip to content

Commit

Permalink
removing signup as instructor feature and related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sswetha08 committed Oct 23, 2022
1 parent fb51d49 commit 7b3f68a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 175 deletions.
45 changes: 0 additions & 45 deletions app/controllers/sign_up_sheet_controller.rb
Expand Up @@ -232,30 +232,6 @@ def sign_up
redirect_to action: 'list', id: params[:id]
end

# routes to new page to specficy student
def signup_as_instructor; end

def signup_as_instructor_action
user = User.find_by(name: params[:username])
if user.nil? # validate invalid user
flash[:error] = 'That student does not exist!'
else
if AssignmentParticipant.exists? user_id: user.id, parent_id: params[:assignment_id]
if SignUpSheet.signup_team(params[:assignment_id], user.id, params[:topic_id])
flash[:success] = 'You have successfully signed up the student for the topic!'
ExpertizaLogger.info LoggerMessage.new(controller_name, '', 'Instructor signed up student for topic: ' + params[:topic_id].to_s)
else
flash[:error] = 'The student has already signed up for a topic!'
ExpertizaLogger.info LoggerMessage.new(controller_name, '', 'Instructor is signing up a student who already has a topic')
end
else
flash[:error] = 'The student is not registered for the assignment!'
ExpertizaLogger.info LoggerMessage.new(controller_name, '', 'The student is not registered for the assignment: ' << user.id)
end
end
redirect_to controller: 'assignments', action: 'edit', id: params[:assignment_id]
end

# this function is used to delete a previous signup
def delete_signup
participant = AssignmentParticipant.find(params[:id])
Expand All @@ -279,27 +255,6 @@ def delete_signup
redirect_to action: 'list', id: params[:id]
end

def delete_signup_as_instructor
# find participant using assignment using team and topic ids
team = Team.find(params[:id])
assignment = Assignment.find(team.parent_id)
user = TeamsUser.find_by(team_id: team.id).user
participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: assignment.id)
drop_topic_deadline = assignment.due_dates.find_by(deadline_type_id: 6)
if !participant.team.submitted_files.empty? || !participant.team.hyperlinks.empty?
flash[:error] = 'The student has already submitted their work, so you are not allowed to remove them.'
ExpertizaLogger.error LoggerMessage.new(controller_name, session[:user].id, 'Drop failed for already submitted work: ' + params[:topic_id].to_s)
elsif !drop_topic_deadline.nil? && (Time.now > drop_topic_deadline.due_at)
flash[:error] = 'You cannot drop a student after the drop topic deadline!'
ExpertizaLogger.error LoggerMessage.new(controller_name, session[:user].id, 'Drop failed for ended work: ' + params[:topic_id].to_s)
else
delete_signup_for_topic(assignment.id, params[:topic_id], participant.user_id)
flash[:success] = 'You have successfully dropped the student from the topic!'
ExpertizaLogger.error LoggerMessage.new(controller_name, session[:user].id, 'Student has been dropped from the topic: ' + params[:topic_id].to_s)
end
redirect_to controller: 'assignments', action: 'edit', id: assignment.id
end

def set_priority
participant = AssignmentParticipant.find_by(id: params[:participant_id])
assignment_id = SignUpTopic.find(params[:topic].first).assignment.id
Expand Down
130 changes: 0 additions & 130 deletions spec/controllers/sign_up_sheet_controller_spec.rb
Expand Up @@ -513,81 +513,6 @@
end
end

describe '#signup_as_instructor_action' do
context 'when user cannot be found' do
it 'shows an flash error message and redirects to assignment#edit page' do
allow(User).to receive(:find_by).with(name: 'no name').and_return(nil)
allow(User).to receive(:find).with(8).and_return(student)
allow(Team).to receive(:find).with(1).and_return(team)
request_params = { username: 'no name', assignment_id: 1 }
get :signup_as_instructor_action, params: request_params
expect(flash[:error]).to eq('That student does not exist!')
expect(response).to redirect_to('/assignments/1/edit')
end
end

context 'when user can be found' do
before(:each) do
allow(User).to receive(:find_by).with(name: 'no name').and_return(student)
end

context 'when an assignment_participant can be found' do
before(:each) do
allow(AssignmentParticipant).to receive(:exists?).with(user_id: 8, parent_id: '1').and_return(true)
end

context 'when creating team related objects successfully' do
it 'shows a flash success message and redirects to assignment#edit page' do
allow(SignedUpTeam).to receive(:find_team_users).with('1', 8).and_return([team])
allow(Team).to receive(:find).and_return(team)
allow(team).to receive(:t_id).and_return(1)
allow(TeamsUser).to receive(:team_id).with('1', 8).and_return(1)
allow(SignedUpTeam).to receive(:topic_id).with('1', 8).and_return(1)
allow_any_instance_of(SignedUpTeam).to receive(:save).and_return(team)
request_params = {
username: 'no name',
assignment_id: 1,
topic_id: 1
}
get :signup_as_instructor_action, params: request_params
expect(flash[:success]).to eq('You have successfully signed up the student for the topic!')
expect(response).to redirect_to('/assignments/1/edit')
end
end

context 'when creating team related objects unsuccessfully' do
it 'shows a flash error message and redirects to assignment#edit page' do
allow(SignedUpTeam).to receive(:find_team_users).with('1', 8).and_return([])
allow(User).to receive(:find).with(8).and_return(student)
allow(Assignment).to receive(:find).with(1).and_return(assignment)
allow(TeamsUser).to receive(:create).with(user_id: 8, team_id: 1).and_return(double('TeamsUser', id: 1))
allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))
request_params = {
username: 'no name',
assignment_id: 1
}
get :signup_as_instructor_action, params: request_params
expect(flash[:error]).to eq('The student has already signed up for a topic!')
expect(response).to redirect_to('/assignments/1/edit')
end
end
end

context 'when an assignment_participant cannot be found' do
it 'shows a flash error message and redirects to assignment#edit page' do
allow(AssignmentParticipant).to receive(:exists?).with(user_id: 8, parent_id: '1').and_return(false)
request_params = {
username: 'no name',
assignment_id: 1
}
get :signup_as_instructor_action, params: request_params
expect(flash[:error]).to eq('The student is not registered for the assignment!')
expect(response).to redirect_to('/assignments/1/edit')
end
end
end
end

describe '#delete_signup' do
before(:each) do
allow(participant).to receive(:team).and_return(team)
Expand Down Expand Up @@ -634,61 +559,6 @@
end
end

describe '#delete_signup_as_instructor' do
before(:each) do
allow(Team).to receive(:find).with('1').and_return(team)
allow(TeamsUser).to receive(:find_by).with(team_id: 1).and_return(double('TeamsUser', user: student))
allow(AssignmentParticipant).to receive(:find_by).with(user_id: 8, parent_id: 1).and_return(participant)
allow(participant).to receive(:team).and_return(team)
end

context 'when either submitted files or hyperlinks of current team are not empty' do
it 'shows a flash error message and redirects to assignment#edit page' do
allow(assignment).to receive(:instructor).and_return(instructor)
request_params = { id: 1 }
user_session = { user: instructor }
get :delete_signup_as_instructor, params: request_params, session: user_session
expect(flash[:error]).to eq('The student has already submitted their work, so you are not allowed to remove them.')
expect(response).to redirect_to('/assignments/1/edit')
end
end

context 'when both submitted files and hyperlinks of current team are empty and drop topic deadline is not nil and its due date has already passed' do
it 'shows a flash error message and redirects to assignment#edit page' do
due_date.due_at = DateTime.now.in_time_zone - 1.day
allow(assignment).to receive(:due_dates).and_return(due_date)
allow(due_date).to receive(:find_by).with(deadline_type_id: 6).and_return(due_date)
allow(team).to receive(:submitted_files).and_return([])
allow(team).to receive(:hyperlinks).and_return([])
request_params = {
id: 1,
due_date: {
'1_submission_1_due_date' => nil,
'1_review_1_due_date' => nil
}
}
user_session = { user: instructor }
get :delete_signup_as_instructor, params: request_params, session: user_session
expect(flash[:error]).to eq('You cannot drop a student after the drop topic deadline!')
expect(response).to redirect_to('/assignments/1/edit')
end
end

context 'when both submitted files and hyperlinks of current team are empty and drop topic deadline is nil' do
it 'shows a flash success message and redirects to assignment#edit page' do
allow(team).to receive(:submitted_files).and_return([])
allow(team).to receive(:hyperlinks).and_return([])
allow(SignedUpTeam).to receive(:find_team_users).with(1, 6).and_return([team])
allow(team).to receive(:t_id).and_return(1)
request_params = { id: 1, topic_id: 1 }
user_session = { user: instructor }
get :delete_signup_as_instructor, params: request_params, session: user_session
expect(flash[:success]).to eq('You have successfully dropped the student from the topic!')
expect(response).to redirect_to('/assignments/1/edit')
end
end
end

describe '#set_priority' do
it 'sets priority of bidding topic and redirects to sign_up_sheet#list page' do
allow(participant).to receive(:team).and_return(team)
Expand Down

0 comments on commit 7b3f68a

Please sign in to comment.