Skip to content

Commit

Permalink
Added changes to spec files
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Mar 24, 2024
1 parent e5aa71e commit a03c577
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 53 deletions.
4 changes: 2 additions & 2 deletions spec/controllers/student_teams_controller_spec.rb
Expand Up @@ -46,7 +46,7 @@
it 'saves the team when all the team name is set correctly' do
allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)
allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)
allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)
allow(AssignmentParticipant).to receive(:find).with('1').and_return(participant)
allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)
allow(User).to receive(:find).with(1).and_return(team_user1)
allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)
Expand All @@ -69,7 +69,7 @@
context 'name already in use' do
it 'flash notice when the team name is already in use' do
allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)
allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)
allow(AssignmentParticipant).to receive(:find).with('1').and_return(participant)
allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)
allow(student1).to receive(:user_id).with(any_args).and_return(1)
allow(team7).to receive(:empty?).and_return(false)
Expand Down
16 changes: 8 additions & 8 deletions spec/controllers/teams_users_controller_spec.rb
Expand Up @@ -14,7 +14,7 @@
let(:student) { build(:student) }
let(:duty) { build(:duty, id: 1, name: 'Role', max_members_for_duty: 2, assignment_id: 1) }
let(:teams_user1) { TeamsUser.new id: 1, duty_id: 1 }

let(:participant1) { build_stubbed(:participant, id: 1, user_id: 1, parent_id: 1)}
before(:each) do
allow(Assignment).to receive(:find).with('1').and_return(assignment)
stub_current_user(student, student.role.name, student.role)
Expand Down Expand Up @@ -148,7 +148,7 @@
allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)
allow(Assignment).to receive(:find).with(1).and_return(assignment1)
allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)
allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)
allow_any_instance_of(Team).to receive(:add_participant_to_team).with(any_args).and_return(true)
allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)
user_session = { user: admin }
request_params = {
Expand Down Expand Up @@ -186,7 +186,7 @@
allow(CourseTeam).to receive(:find).with('5').and_return(team5)
allow(Course).to receive(:find).with(1).and_return(course1)
allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)
allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)
allow_any_instance_of(CourseTeam).to receive(:add_participant_to_team).with(any_args).and_return(false)
user_session = { user: admin }
request_params = {
user: { name: 'student2065' }, id: 5
Expand All @@ -209,7 +209,7 @@
allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))
allow(Course).to receive(:find).with(1).and_return(course1)
allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)
allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)
allow_any_instance_of(CourseTeam).to receive(:add_participant_to_team).with(any_args).and_return(true)
user_session = { user: admin }
request_params = {
user: { name: 'student2065' }, id: 5
Expand All @@ -229,7 +229,7 @@
allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)
allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)
allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)
allow(assignment1).to receive(:user_on_team?).with(student1).and_return(true)
allow(assignment1).to receive(:participant_on_team).with(participant).and_return(true)
user_session = { user: admin }
request_params = {
user: { name: 'student2065' }, id: 1
Expand Down Expand Up @@ -272,8 +272,8 @@
allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))
allow(Course).to receive(:find).with(1).and_return(course1)
allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)
allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)
allow(course1).to receive(:user_on_team?).with(student1).and_return(true)
allow_any_instance_of(CourseTeam).to receive(:add_participant_to_team).with(any_args).and_return(true)
allow(course1).to receive(:participant_on_team?).with(participant).and_return(true)
user_session = { user: admin }
request_params = {
user: { name: 'student2065' }, id: 5
Expand All @@ -293,7 +293,7 @@
allow(CourseTeam).to receive(:find).with('5').and_return(team5)
allow(Course).to receive(:find).with(1).and_return(course1)
allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)
allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_raise("Member on existing team error")
allow_any_instance_of(CourseTeam).to receive(:add_participant_to_team).with(any_args).and_raise("Member on existing team error")
user_session = { user: admin }
request_params = {
user: { name: 'student2065' }, id: 5
Expand Down
12 changes: 12 additions & 0 deletions spec/helpers/grades_helper_spec.rb
Expand Up @@ -22,6 +22,10 @@
let(:vmQ1) { VmQuestionResponse.new(questionnaire1, assignment, 1) }
let(:vmQ2) { VmQuestionResponse.new(questionnaire2, assignment, 2) }
let(:helper) { Class.new { extend GradesHelper } }
let(:assignment_with_participant) do
build(:assignment ,id: 1, name: 'test_assignment', instructor_id: 2, participants:[build(:participant, id: 1, user_id: 21, assignment: assignment)], course_id: 1)
end
let(:participants_list) { [build(:participant, id: 1, user_id: 21, assignment: assignment)]}

describe 'accordion_title' do
it 'should render is_first:true if last_topic is nil' do
Expand Down Expand Up @@ -233,6 +237,8 @@
describe 'view_heatgrid' do
context 'when all questionnaires do not match the target type' do
it 'render the view with empty list of VmQuestionResponse' do
allow_any_instance_of(Assignment).to receive(:participants).and_return(assignemnt_with_participants.participants)
allow(assignemnt_with_participants.participants).to receive(:find_by).and_return(participant)
# mock the participant for the AssignmentParticipant.find
allow(AssignmentParticipant).to receive(:find).with(1).and_return(assignment_participant)
allow(assignment_participant).to receive(:team).and_return(team)
Expand All @@ -248,6 +254,8 @@
end
context 'when all questionnaires match the target type' do
it 'render the view with nonempty list of VmQuestionResponse' do
allow_any_instance_of(Assignment).to receive(:participants).and_return(assignemnt_with_participants.participants)
allow(assignemnt_with_participants.participants).to receive(:find_by).and_return(participant)
# mock the participant for the AssignmentParticipant.find
allow(AssignmentParticipant).to receive(:find).with(1).and_return(assignment_participant)
allow(assignment_participant).to receive(:team).and_return(team)
Expand All @@ -264,9 +272,13 @@

context 'when all questionnaires match the target type, but the assignment does not vary by round' do
it 'the round variable in the new VmQuestionResponse should be nil' do
participant_list = [viewgrid_participant]
# mock the participant for the AssignmentParticipant.find
# viewgrid_participant contains a assignment whose questionnaires' type is TeammateReviewQuestionnaire
allow(AssignmentParticipant).to receive(:find).with(2).and_return(viewgrid_participant)
allow(Assignment).to receive(:find).with(5).and_return(assignment_for_viewgrid)
allow(assignment_for_viewgrid).to receive(:participants).and_return(participant_list)
allow(participant_list).to receive(:find_by).and_return(viewgrid_participant)
allow(viewgrid_participant).to receive(:team).and_return(team)
view_heatgrid(2, 'TeammateReviewQuestionnaire')
# testing the object variable
Expand Down
10 changes: 6 additions & 4 deletions spec/models/assignment_spec.rb
Expand Up @@ -3,6 +3,8 @@
let(:instructor) { build(:instructor, id: 6) }
let(:student) { build(:student, id: 3, name: 'no one') }
let(:review_response_map) { build(:review_response_map, response: [response], reviewer: build(:participant), reviewee: build(:assignment_team)) }
let(:instructor_participant) { build(:participant, id: 6, user: instructor)}
let(:student_participant) { build(:participant, id: 3, user: student)}
let(:teammate_review_response_map) { build(:review_response_map, type: 'TeammateReviewResponseMap') }
let(:participant) { build(:participant, id: 1) }
let(:question) { double('Question') }
Expand All @@ -23,14 +25,14 @@
describe '#user_on_team?' do
context 'when the user is not on a team associated with the assignment' do
it 'returns false' do
allow_any_instance_of(Team).to receive(:users).and_return([instructor])
expect(assignment.user_on_team?(student)).to be_falsey
allow_any_instance_of(Team).to receive(:participants).and_return([instructor_participant])
expect(assignment.participant_on_team?(participant)).to be_falsey
end
end
context 'when the user is on a team associated with the assignment' do
it 'returns true' do
allow_any_instance_of(Team).to receive(:users).and_return([student])
expect(assignment.user_on_team?(student)).to be_truthy
allow_any_instance_of(Team).to receive(:participants).and_return([student_participant])
expect(assignment.participant_on_team?(student_participant)).to be_truthy
end
end
end
Expand Down
44 changes: 33 additions & 11 deletions spec/models/assignment_team_spec.rb
Expand Up @@ -2,8 +2,8 @@
let(:team_without_submitted_hyperlinks) { build(:assignment_team, submitted_hyperlinks: '') }
let(:team) { build(:assignment_team, id: 1, parent_id: 1) }
let(:assignment) { build(:assignment, id: 1) }
let(:participant1) { build(:participant, id: 1) }
let(:participant2) { build(:participant, id: 2) }
let(:participant1) { build(:participant, id: 1, user_id: 1) }
let(:participant2) { build(:participant, id: 2, user_id: 2) }
let(:user1) { build(:student, id: 2) }
let(:user2) { build(:student, id: 3) }
let(:review_response_map) { build(:review_response_map, reviewed_object_id: 1, reviewer_id: 1, reviewee_id: 1) }
Expand All @@ -27,15 +27,15 @@
describe '#includes?' do
context 'when an assignment team has one participant' do
it 'includes one participant' do
allow(team).to receive(:users).with(no_args).and_return([user1])
allow(team).to receive(:participants).with(no_args).and_return([participant1])
allow(AssignmentParticipant).to receive(:find_by).with(user_id: user1.id, parent_id: team.parent_id).and_return(participant1)
expect(team.includes?(participant1)).to eq true
end
end

context 'when an assignment team has no users' do
it 'includes no participants' do
allow(team).to receive(:users).with(no_args).and_return([])
allow(team).to receive(:participants).with(no_args).and_return([])
expect(team.includes?(participant1)).to eq false
end
end
Expand Down Expand Up @@ -115,17 +115,23 @@
describe '#participants' do
context 'when an assignment team has two participants' do
it 'has those two participants' do
allow(team).to receive(:users).with(no_args).and_return([user1, user2])
user_list = [user1, user2]
allow(AssignmentParticipant).to receive(:find_by).with(user_id: user1.id, parent_id: team.parent_id).and_return(participant1)
allow(AssignmentParticipant).to receive(:find_by).with(user_id: user2.id, parent_id: team.parent_id).and_return(participant2)
participants_list = [participant1, participant2]
allow(team).to receive(:users).with(no_args).and_return(user_list)
allow(team).to receive(:participants).with(no_args).and_return(participants_list)
allow(user_list).to receive(:where).and_return(participants_list)
allow(user_list).to receive(:flat_map).and_return(participants_list)
expect(team.participants).to eq [participant1, participant2]
end
end

context 'when an assignment team has a user but no participants' do
it 'includes no participants' do
allow(team).to receive(:users).with(no_args).and_return([user1])
allow(AssignmentParticipant).to receive(:find_by).with(user_id: user1.id, parent_id: team.parent_id).and_return(nil)
user_list = [user1]
allow(team).to receive(:users).with(no_args).and_return(user_list)
allow(user_list).to receive(:where).and_return([])
expect(team.participants).to eq []
end
end
Expand Down Expand Up @@ -299,13 +305,29 @@
end
end

describe '.team' do
context 'when there is a participant' do
describe '.team when there is a participant' do
context 'teams_user has user_id' do
it 'provides the team for participant' do
teamuser = build(:team_user, id: 1, team_id: team.id, user_id: user1.id)
teamuser_array = [teamuser]
empty_array = []
allow(team).to receive(:users).with(no_args).and_return([user1])
allow(AssignmentParticipant).to receive(:find_by).with(user_id: user1.id, parent_id: team.parent_id).and_return(participant1)
allow(TeamsParticipant).to receive(:where).with(user_id: participant1.user_id).and_return(teamuser_array)
allow(TeamsParticipant).to receive(:where).with(participant_id: participant1.id).and_return(empty_array)
allow(teamuser_array).to receive(:or).with(empty_array).and_return(teamuser_array)
allow(Team).to receive(:find).with(teamuser.team_id).and_return(team)
expect(AssignmentTeam.team(participant1)).to eq(team)
end
end
context 'teams_user has participant_id' do
it 'provides the team for participant' do
teamuser = build(:team_user, id: 1, team_id: team.id, user_id: user1.id)
teamuser_array = [teamuser]
empty_array = []
allow(team).to receive(:users).with(no_args).and_return([user1])
allow(AssignmentParticipant).to receive(:find_by).with(user_id: user1.id, parent_id: team.parent_id).and_return(participant1)
allow(TeamsUser).to receive(:where).with(user_id: participant1.user_id).and_return([teamuser])
allow(TeamsParticipant).to receive(:where).with(user_id: participant1.user_id).and_return([teamuser])
allow(Team).to receive(:find).with(teamuser.team_id).and_return(team)
expect(AssignmentTeam.team(participant1)).to eq(team)
end
Expand Down Expand Up @@ -369,7 +391,7 @@
@assignment = create(:assignment)
@student = create(:student)
@team = create(:assignment_team, parent_id: @assignment.id)
@team_user = create(:team_user, team_id: @team.id, user_id: @student.id)
@participant = create(:participant, id: 1, user_id: @student.id, parent_id: @assignment.id)
end
it 'should create a team with users' do
new_team = AssignmentTeam.create_team_with_users(@assignment.id, [@student.id])
Expand Down
4 changes: 2 additions & 2 deletions spec/models/course_spec.rb
Expand Up @@ -116,14 +116,14 @@
it 'returns false' do
allow(course).to receive(:teams).and_return([course_team1])
allow_any_instance_of(Team).to receive(:users).and_return([user1])
expect(course.user_on_team?(user2)).to be_falsey
expect(course.participant_on_team?(user2)).to be_falsey
end
end
context 'when the user is on a team associated with the assignment' do
it 'returns true' do
allow(course).to receive(:get_teams).and_return([course_team1])
allow_any_instance_of(CourseTeam).to receive(:users).and_return([user1, user2])
expect(course.user_on_team?(user2)).to be_truthy
expect(course.participant_on_team?(user2)).to be_truthy
end
end
end
Expand Down
14 changes: 8 additions & 6 deletions spec/models/course_team_spec.rb
Expand Up @@ -58,7 +58,8 @@
describe '#export' do
it 'writes to a csv' do
allow(CourseTeam).to receive(:where).with(parent_id: 1).and_return([course_team1])
allow(TeamsUser).to receive(:where).with(team_id: 1).and_return([team_user])
allow(TeamsParticipant).to receive(:where).with(team_id: 1).and_return([team_user])
allow(User).to receive(:find).with(user2.id).and_return(user2)
expect(CourseTeam.export([], 1, team_name: 'false')).to eq([['no team', 'no name']])
end
end
Expand All @@ -70,19 +71,20 @@
describe '#add_member' do
context 'when the user is already on the team' do
it 'raises an error' do
allow(course_team1).to receive(:user?).with(user2).and_return(true)
expect { course_team1.add_member(user2) }.to raise_error('The user "no name" is already a member of the team, "no team"')
allow(course_team1).to receive(:participant?).with(participant).and_return(true)
expect { course_team1.add_participant_to_team(participant) }.to raise_error('The user "no name" is already a member of the team, "no team"')
end
end
context 'when the user is not on the team' do
it 'creates and returns a participant' do
it 'adds user' do
node = TeamNode.new
allow(course_team1).to receive(:user?).with(user2).and_return(false)
allow(TeamsUser).to receive(:create).with(user_id: 2, team_id: 1).and_return(team_user)
allow(TeamsParticipant).to receive(:create).with(participant_id: participant.id, team_id: 1).and_return(team_user)
allow(TeamNode).to receive(:find_by).with(node_object_id: 1).and_return(node)
allow(course_team1).to receive(:add_participant).with(1, user2).and_return(participant)
allow(CourseParticipant).to receive(:find_by).with(parent_id: 1, user_id: user2.id).and_return(participant)
allow(course_team1).to receive(:parent_id).and_return(1)
expect(course_team1.add_member(user2)).to eq(participant)
expect(course_team1.add_participant_to_team(participant).node_object_id).to eq(team_user.id)
end
end
end
Expand Down

0 comments on commit a03c577

Please sign in to comment.