<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sbkrishn</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sbkrishn"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Sbkrishn"/>
	<updated>2026-05-20T13:43:50Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142806</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142806"/>
		<updated>2021-12-09T05:12:26Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /* advertise_partner_controller.rb  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
The student teams controller is used to create teams, remove participants from teams and update team name. The following test cases are written to test the student_teams_controller.rb.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/student_teams_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
The controller is used to create, update and remove advertisements for partner. The following test cases are written to test the functionality of advertise_partner_controller.rb.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/advertise_partner_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  #create advertisement by passing team and participant details&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement request is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  # Update advertisement by passing team and paticipant details&lt;br /&gt;
  describe &amp;quot;POST #update&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142805</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142805"/>
		<updated>2021-12-09T05:12:06Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /* advertise_partner_controller.rb  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
The student teams controller is used to create teams, remove participants from teams and update team name. The following test cases are written to test the student_teams_controller.rb.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/student_teams_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
The controller is used to create, update and remove advertisements for partner. The following test cases are written to test the functionality of advertise_partner_controller.rb.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/advertise_partner_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  #create advertisement by passing team and participant details&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement request is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  # Update advertisement by passing team and paticipant details&lt;br /&gt;
  describe &amp;quot;POST #update&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142804</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142804"/>
		<updated>2021-12-09T05:11:22Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /* student_teams_controller.rb  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
The student teams controller is used to create teams, remove participants from teams and update team name. The following test cases are written to test the student_teams_controller.rb.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/student_teams_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
The controller is used to create, update and remove advertisements for partner. The following test cases are written to test the functionality of advertise_partner_controller.rb.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  #create advertisement by passing team and participant details&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement request is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  # Update advertisement by passing team and paticipant details&lt;br /&gt;
  describe &amp;quot;POST #update&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142803</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142803"/>
		<updated>2021-12-09T05:10:53Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /* student_teams_controller.rb  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
The student teams controller is used to create teams, remove participants from teams and update team name. The following test cases are written to test the student_teams_controller.rb.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/student_teams_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
The controller is used to create, update and remove advertisements for partner. The following test cases are written to test the functionality of advertise_partner_controller.rb.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  #create advertisement by passing team and participant details&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement request is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  # Update advertisement by passing team and paticipant details&lt;br /&gt;
  describe &amp;quot;POST #update&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142802</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142802"/>
		<updated>2021-12-09T05:10:07Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /* advertise_partner_controller.rb  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
The student teams controller is used to create teams, remove participants from teams and update team name. The following test cases are written to test the student_teams_controller.rb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/student_teams_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
The controller is used to create, update and remove advertisements for partner. The following test cases are written to test the functionality of advertise_partner_controller.rb.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  #create advertisement by passing team and participant details&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement request is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  # Update advertisement by passing team and paticipant details&lt;br /&gt;
  describe &amp;quot;POST #update&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142801</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142801"/>
		<updated>2021-12-09T05:07:46Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /* student_teams_controller.rb  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
The student teams controller is used to create teams, remove participants from teams and update team name. The following test cases are written to test the student_teams_controller.rb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/student_teams_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  #create advertisement by passing team and participant details&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement request is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  # Update advertisement by passing team and paticipant details&lt;br /&gt;
  describe &amp;quot;POST #update&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142800</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142800"/>
		<updated>2021-12-09T05:05:32Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /* teams_users_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  #create advertisement by passing team and participant details&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement request is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  # Update advertisement by passing team and paticipant details&lt;br /&gt;
  describe &amp;quot;POST #update&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142799</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142799"/>
		<updated>2021-12-09T05:03:55Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /*  Scenario 3: Remove the advertisement.  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  #create advertisement by passing team and participant details&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement request is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  # Update advertisement by passing team and paticipant details&lt;br /&gt;
  describe &amp;quot;POST #update&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142798</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142798"/>
		<updated>2021-12-09T05:03:07Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /*  Scenario 3: Remove the advertisement.  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  #create advertisement by passing team and participant details&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement request is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  # Update advertisement by passing team and paticipant details&lt;br /&gt;
  describe &amp;quot;POST #update&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142797</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142797"/>
		<updated>2021-12-09T05:02:55Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /*  Scenario 2: Updating the advertisement.  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  #create advertisement by passing team and participant details&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement request is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  # Update advertisement by passing team and paticipant details&lt;br /&gt;
  describe &amp;quot;POST #update&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142796</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142796"/>
		<updated>2021-12-09T05:02:43Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /*  Scenario 1: Creating new advertisement for partners.  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  #create advertisement by passing team and participant details&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement request is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  # Update advertisement by passing team and paticipant details&lt;br /&gt;
  describe &amp;quot;POST #update&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142795</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142795"/>
		<updated>2021-12-09T05:01:40Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /*  Scenario 3: Remove the advertisement.  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode. &amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  #create advertisement by passing team and participant details&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement request is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  # Update advertisement by passing team and paticipant details&lt;br /&gt;
  describe &amp;quot;POST #update&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142794</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142794"/>
		<updated>2021-12-09T05:00:05Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /*  Scenario 2: Updating the advertisement.  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode. &amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  #create advertisement by passing team and participant details&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement request is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  # Update advertisement by passing team and paticipant details&lt;br /&gt;
  describe &amp;quot;POST #update&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142793</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142793"/>
		<updated>2021-12-09T04:58:36Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /*  Scenario 1: Creating new advertisement for partners.  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode. &amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
  #create advertisement by passing team and participant details&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement request is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
  &lt;br /&gt;
 context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142792</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142792"/>
		<updated>2021-12-09T04:56:18Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /*  Scenario 3: Update team name:  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present in the database, it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name when the name is not already present in the database' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name when no team has name and only one matching team is found' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'when the team name is already in use flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode.&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when it is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
  &lt;br /&gt;
 context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142791</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142791"/>
		<updated>2021-12-09T04:55:03Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /*  Scenario 2: Create Student teams  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when all the team name is set correctly, create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team when all the team name is set correctly&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice when the team name is already in use&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode.&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when it is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
  &lt;br /&gt;
 context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142790</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142790"/>
		<updated>2021-12-09T04:51:27Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /* teams_shared.rb  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
&amp;lt;b&amp;gt;Why this file? &amp;lt;/b&amp;gt; - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt; Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
This creates single instances of superadmin, admin, instructor, teaching assistant, course and assignment.&lt;br /&gt;
There are 2 instances of students, 5 instances of assignment teams, 2 instances of course teams, 4 instances of team join requests, and single instances of participant, node and team user.&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '2.8'&amp;gt;action_allowed? method shared example tests&amp;lt;/font&amp;gt;==== &lt;br /&gt;
The action_allowed method is there in all controllers, so a shared example was created which allows the tests to run in scope of different controllers. It contains tests for access checks for superadmin, admin, instructor and ta users. Only the authorization of student changes between the team related files so that test was not included in here.&lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Super Admin access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2.8'&amp;gt; How to use this shared file?&lt;br /&gt;
Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
How to run the test?&lt;br /&gt;
 rspec spec/controllers/teams_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when correct parameters are passed' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is not Assignment or Course' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects back to the earlier page' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'copies teams from course to the assignment' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'copies the teams from assignment to the course' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'throws an error and fails to copy the teams' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'successfully returns the team with the given team id' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; Code correction in teams_users_controller.rb in list method: Team users list users page was not displaying users as expected and showed error for accessing @team.assignment_id. The error is rectified and corrected.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; The above code is corrected to following:&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where([&amp;quot;team_id = ?&amp;quot;, params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; How to run the test?&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  rspec spec/controllers/teams_users_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: List users under the team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# When list icon against a course or assignment team is selected&lt;br /&gt;
# Render list of users under selected team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users list functionality&lt;br /&gt;
  describe '#list' do&lt;br /&gt;
    context 'when list is clicked' do&lt;br /&gt;
    it 'renders list of users under Assignment team teams#users' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :list, @params, session&lt;br /&gt;
      expect(response).to render_template(:list)&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: New user under the course or assignment team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Sets the instance variable to team object&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  #Test team users controller new method&lt;br /&gt;
  describe '#new' do&lt;br /&gt;
    it ' sets the instance variable to team object' do&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      params = {id:  1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      get :new, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq(team1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 3: Create: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 #Test adding new user to assignment or course team&lt;br /&gt;
  describe '#create' do&lt;br /&gt;
    context 'when user is added to assignment or course team' do&lt;br /&gt;
    it 'it throws error when user is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: 'instructor6').and_return(nil)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'instructor6'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;instructor6\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;http://test.host/users/new\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when user added is not a participant of the current assignment' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Assignment\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
    it 'it throws error when assignmentTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 1&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to assignment team' do&lt;br /&gt;
      it 'new user gets successfully added to the assignment' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with(any_args).and_return(team1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).with('1').and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(TeamsUser).to receive(:last).with(any_args).and_return(student1)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 1&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when user added to course Team is not defined' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;\&amp;quot;student2065\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;http://test.host/participants/list?authorization=participant&amp;amp;id=1&amp;amp;model=Course\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
    it 'it throws error when courseTeam has maximum number of participants' do&lt;br /&gt;
      allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
      allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
      allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
      allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
      allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(false)&lt;br /&gt;
      session = {user: admin}&lt;br /&gt;
      params = {&lt;br /&gt;
          user: {name: 'student2065'}, id: 5&lt;br /&gt;
      }&lt;br /&gt;
      post :create, params, session&lt;br /&gt;
      expect(flash[:error]).to eq &amp;quot;This team already has the maximum number of members.&amp;quot;&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when user is added to course team' do&lt;br /&gt;
      it 'new user gets successfully added to course' do&lt;br /&gt;
        allow(User).to receive(:find_by).with(name: student1.name).and_return(student1)&lt;br /&gt;
        allow(Team).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(CourseTeam).to receive(:find).with('5').and_return(team5)&lt;br /&gt;
        allow(TeamsUser).to receive(:create).with(user_id: 1, team_id: 5).and_return(double('TeamsUser', id: 1))&lt;br /&gt;
        allow(TeamNode).to receive(:find_by).with(node_object_id: 5).and_return(double('TeamNode', id: 1))&lt;br /&gt;
        allow(TeamUserNode).to receive(:create).with(parent_id: 1, node_object_id: 1).and_return(double('TeamUserNode', id: 1))&lt;br /&gt;
        allow(Course).to receive(:find).with(1).and_return(course1)&lt;br /&gt;
        allow(CourseParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(participant)&lt;br /&gt;
        allow_any_instance_of(CourseTeam).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        session = {user: admin}&lt;br /&gt;
        params = {&lt;br /&gt;
            user: {name: 'student2065'}, id: 5&lt;br /&gt;
        }&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 4: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete user from team&lt;br /&gt;
  describe '#delete' do&lt;br /&gt;
    context 'when user is deleted' do&lt;br /&gt;
    it 'it deletes the user and redirects to Teams#list page' do&lt;br /&gt;
      allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(teamUser)&lt;br /&gt;
      allow(Team).to receive(:find).with(teamUser.team_id).and_return(team1)&lt;br /&gt;
      allow(User).to receive(:find).with(teamUser.user_id).and_return(student1)&lt;br /&gt;
      @params = {id:1}&lt;br /&gt;
      session = {user: instructor}&lt;br /&gt;
      post :delete, @params, session&lt;br /&gt;
      expect(response).to redirect_to('http://test.host/teams/list?id=1')&lt;br /&gt;
    end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 5: Delete selected users from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Selected users under assignment or course team is deleted: for each user in the selected users, association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
#Response is redirected to 'http://test.host/teams/list'.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 #Test delete selected users from team&lt;br /&gt;
  describe '#delete_selected' do&lt;br /&gt;
    context 'when selected users are deleted' do&lt;br /&gt;
      it 'it deletes the selected users and redirects to Teams#list page' do&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;1&amp;quot;).and_return([teamUser])&lt;br /&gt;
        allow(TeamsUser).to receive(:find).with(&amp;quot;2&amp;quot;).and_return([teamUser2])&lt;br /&gt;
        @params = {item:[1,2]}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        post :delete_selected, @params, session&lt;br /&gt;
        expect(response).to redirect_to('http://test.host/teams_users/list')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:teams_users.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[[File:teams_users_coverage.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #happy flow to create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
P = Pending status, D = Denied status, A = Accepted status. To test the controller, run the line:&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; All tests, except 1 pass. The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#We set the advertise_for_partner : True, comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam mode.&lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    context &amp;quot;when it is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful: If there is an error during update then the following error message is thrown &amp;quot;An error occurred, and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful: If the advertisement is successfully updated in the database, then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
  &lt;br /&gt;
 context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page: https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142397</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142397"/>
		<updated>2021-11-30T08:35:58Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 1- Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 2 - Action_allowed?: It gives access permission to different users &amp;lt;/font&amp;gt;==== &lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to use this shared file? &amp;lt;/font&amp;gt;====&lt;br /&gt;
# Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
# Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
# Why this file? - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to run the test? &amp;lt;/font&amp;gt;====&lt;br /&gt;
 rspec spec/controllers/teams_controller.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when everything is right' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is wrong' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'fails' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'passes the test' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #happy flow to create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name os already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;==&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
==&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;==&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;P = Pending status &amp;lt;br&amp;gt;&lt;br /&gt;
D = Denied status &amp;lt;br&amp;gt;&lt;br /&gt;
A = Accepted status &lt;br /&gt;
# Test the controller :&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# All tests, except 1 pass. &lt;br /&gt;
# The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model.&lt;br /&gt;
  &lt;br /&gt;
describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when it is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
  &lt;br /&gt;
 context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page : https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142396</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142396"/>
		<updated>2021-11-30T08:34:10Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /*  Test Pass/ Fail  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 1- Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 2 - Action_allowed?: It gives access permission to different users &amp;lt;/font&amp;gt;==== &lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to use this shared file? &amp;lt;/font&amp;gt;====&lt;br /&gt;
# Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
# Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
# Why this file? - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to run the test? &amp;lt;/font&amp;gt;====&lt;br /&gt;
 rspec spec/controllers/teams_controller.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when everything is right' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is wrong' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'fails' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'passes the test' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #happy flow to create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name os already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;P = Pending status &amp;lt;br&amp;gt;&lt;br /&gt;
D = Denied status &amp;lt;br&amp;gt;&lt;br /&gt;
A = Accepted status &lt;br /&gt;
# Test the controller :&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# All tests, except 1 pass. &lt;br /&gt;
# The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model.&lt;br /&gt;
  &lt;br /&gt;
describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when it is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
  &lt;br /&gt;
 context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page : https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:PassFail.png&amp;diff=142395</id>
		<title>File:PassFail.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:PassFail.png&amp;diff=142395"/>
		<updated>2021-11-30T08:33:31Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: Sbkrishn uploaded a new version of File:PassFail.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142394</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142394"/>
		<updated>2021-11-30T08:29:31Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /*  Coverage  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 1- Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 2 - Action_allowed?: It gives access permission to different users &amp;lt;/font&amp;gt;==== &lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to use this shared file? &amp;lt;/font&amp;gt;====&lt;br /&gt;
# Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
# Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
# Why this file? - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to run the test? &amp;lt;/font&amp;gt;====&lt;br /&gt;
 rspec spec/controllers/teams_controller.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when everything is right' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is wrong' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'fails' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'passes the test' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #happy flow to create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name os already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;P = Pending status &amp;lt;br&amp;gt;&lt;br /&gt;
D = Denied status &amp;lt;br&amp;gt;&lt;br /&gt;
A = Accepted status &lt;br /&gt;
# Test the controller :&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# All tests, except 1 pass. &lt;br /&gt;
# The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model.&lt;br /&gt;
  &lt;br /&gt;
describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when it is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
  &lt;br /&gt;
 context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page : https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142393</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142393"/>
		<updated>2021-11-30T08:26:07Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: /*  Coverage  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 1- Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 2 - Action_allowed?: It gives access permission to different users &amp;lt;/font&amp;gt;==== &lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to use this shared file? &amp;lt;/font&amp;gt;====&lt;br /&gt;
# Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
# Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
# Why this file? - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to run the test? &amp;lt;/font&amp;gt;====&lt;br /&gt;
 rspec spec/controllers/teams_controller.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when everything is right' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is wrong' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'fails' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'passes the test' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #happy flow to create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name os already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:NewCover.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;P = Pending status &amp;lt;br&amp;gt;&lt;br /&gt;
D = Denied status &amp;lt;br&amp;gt;&lt;br /&gt;
A = Accepted status &lt;br /&gt;
# Test the controller :&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# All tests, except 1 pass. &lt;br /&gt;
# The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model.&lt;br /&gt;
  &lt;br /&gt;
describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when it is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
  &lt;br /&gt;
 context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page : https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142392</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142392"/>
		<updated>2021-11-30T08:23:14Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 1- Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 2 - Action_allowed?: It gives access permission to different users &amp;lt;/font&amp;gt;==== &lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to use this shared file? &amp;lt;/font&amp;gt;====&lt;br /&gt;
# Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
# Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
# Why this file? - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to run the test? &amp;lt;/font&amp;gt;====&lt;br /&gt;
 rspec spec/controllers/teams_controller.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when everything is right' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is wrong' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'fails' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'passes the test' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #happy flow to create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name os already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:passFail.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:newCover.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;P = Pending status &amp;lt;br&amp;gt;&lt;br /&gt;
D = Denied status &amp;lt;br&amp;gt;&lt;br /&gt;
A = Accepted status &lt;br /&gt;
# Test the controller :&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# All tests, except 1 pass. &lt;br /&gt;
# The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model.&lt;br /&gt;
  &lt;br /&gt;
describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when it is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
  &lt;br /&gt;
 context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page : https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:PassFail.png&amp;diff=142391</id>
		<title>File:PassFail.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:PassFail.png&amp;diff=142391"/>
		<updated>2021-11-30T08:22:03Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142390</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142390"/>
		<updated>2021-11-30T08:19:11Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 1- Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 2 - Action_allowed?: It gives access permission to different users &amp;lt;/font&amp;gt;==== &lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to use this shared file? &amp;lt;/font&amp;gt;====&lt;br /&gt;
# Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
# Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
# Why this file? - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to run the test? &amp;lt;/font&amp;gt;====&lt;br /&gt;
 rspec spec/controllers/teams_controller.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when everything is right' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is wrong' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'fails' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'passes the test' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #happy flow to create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name os already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.12.35 AM]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;P = Pending status &amp;lt;br&amp;gt;&lt;br /&gt;
D = Denied status &amp;lt;br&amp;gt;&lt;br /&gt;
A = Accepted status &lt;br /&gt;
# Test the controller :&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# All tests, except 1 pass. &lt;br /&gt;
# The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model.&lt;br /&gt;
  &lt;br /&gt;
describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when it is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
  &lt;br /&gt;
 context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page : https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142389</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142389"/>
		<updated>2021-11-30T08:18:50Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:Example.jpg]]__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 1- Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 2 - Action_allowed?: It gives access permission to different users &amp;lt;/font&amp;gt;==== &lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to use this shared file? &amp;lt;/font&amp;gt;====&lt;br /&gt;
# Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
# Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
# Why this file? - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to run the test? &amp;lt;/font&amp;gt;====&lt;br /&gt;
 rspec spec/controllers/teams_controller.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when everything is right' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is wrong' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'fails' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'passes the test' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #happy flow to create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name os already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.12.35 AM]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:Screen Shot 2021-11-30 at 3.13.36 AM]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;P = Pending status &amp;lt;br&amp;gt;&lt;br /&gt;
D = Denied status &amp;lt;br&amp;gt;&lt;br /&gt;
A = Accepted status &lt;br /&gt;
# Test the controller :&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# All tests, except 1 pass. &lt;br /&gt;
# The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model.&lt;br /&gt;
  &lt;br /&gt;
describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when it is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
  &lt;br /&gt;
 context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page : https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Screen_Shot_2021-11-30_at_3.13.36_AM.png&amp;diff=142388</id>
		<title>File:Screen Shot 2021-11-30 at 3.13.36 AM.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Screen_Shot_2021-11-30_at_3.13.36_AM.png&amp;diff=142388"/>
		<updated>2021-11-30T08:16:17Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142387</id>
		<title>CSC/ECE 517 Fall 2021 - E2167. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2167._Testing_-_Team_Related_Files&amp;diff=142387"/>
		<updated>2021-11-30T08:09:59Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_shared.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# This controller can be found in spec/support&lt;br /&gt;
# It has all shared methods to be included in Teams related files.&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 1- Declared common stubbed objects &amp;lt;/font&amp;gt;====&lt;br /&gt;
 &amp;lt;font size =1&amp;gt;&lt;br /&gt;
 shared_context 'object initializations' do&lt;br /&gt;
  let(:superadmin) { build_stubbed(:superadmin) }&lt;br /&gt;
  let(:admin) { build_stubbed(:admin) }&lt;br /&gt;
  let(:instructor) { build_stubbed(:instructor, id: 1) }&lt;br /&gt;
  let(:ta) { build_stubbed(:teaching_assistant) }&lt;br /&gt;
  let(:student1) { build_stubbed(:student, id: 1, name: 'student2065') }&lt;br /&gt;
  let(:student2) { build_stubbed(:student, id: 2) }&lt;br /&gt;
  let(:course1) { build_stubbed(:course, name: 'TestCourse', id:1, instructor_id: instructor.id) }&lt;br /&gt;
  let(:assignment1) { build_stubbed(:assignment, name: 'TestAssignment', id: 1) }&lt;br /&gt;
  let(:team1) { build_stubbed(:assignment_team, id: 1, name: 'wolfers',parent_id: assignment1.id) }&lt;br /&gt;
  let(:team2) { build_stubbed(:assignment_team, id: 2, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team3) { build_stubbed(:assignment_team, id: 3, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team4) { build_stubbed(:assignment_team, id: 4, parent_id: assignment1.id) }&lt;br /&gt;
  let(:team5) { build_stubbed(:course_team, id: 5, parent_id: course1.id) }&lt;br /&gt;
  let(:team6) { build_stubbed(:course_team, id: 6, parent_id: course1.id) }&lt;br /&gt;
  let(:team7) { build_stubbed(:assignment_team, name: 'test',  parent_id: course1.id) }&lt;br /&gt;
  let(:join_team_request1) { build_stubbed(:join_team_request, id: 1, team_id: team1.id, status: 'P') }&lt;br /&gt;
  let(:join_team_request2) { build_stubbed(:join_team_request, id: 2, team_id: team2.id, status: 'P',comments: &amp;quot;Any comment&amp;quot;) }&lt;br /&gt;
  let(:join_team_request3) { build_stubbed(:join_team_request, id: 3, team_id: team2.id, status: 'D',comments: &amp;quot;Updated&amp;quot;) }&lt;br /&gt;
  let(:invalidrequest) { build_stubbed(:join_team_request) }&lt;br /&gt;
  let(:participant) { build_stubbed(:participant, id: 1) }&lt;br /&gt;
  let(:node1) { build_stubbed(:assignment_node,  node_object_id: 1) }&lt;br /&gt;
  let(:team_user1) { build_stubbed(:team_user, team_id:1, user_id:1)}&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Method 2 - Action_allowed?: It gives access permission to different users &amp;lt;/font&amp;gt;==== &lt;br /&gt;
 &amp;lt;font size = 1&amp;gt;&lt;br /&gt;
 shared_context 'authorization check', :shared_context =&amp;gt; :metadata do&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'superadmin credentials' do&lt;br /&gt;
    stub_current_user(superadmin, superadmin.role.name, superadmin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Admin access&lt;br /&gt;
  it 'admin credentials' do&lt;br /&gt;
    stub_current_user(admin, admin.role.name, admin.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check TA access&lt;br /&gt;
  it 'ta credentials' do&lt;br /&gt;
    stub_current_user(ta, ta.role.name, ta.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
  # Testing to check Instructor access&lt;br /&gt;
  it 'instructor credentials' do&lt;br /&gt;
    stub_current_user(instructor, instructor.role.name, instructor.role)&lt;br /&gt;
    expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
  end&lt;br /&gt;
 &amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to use this shared file? &amp;lt;/font&amp;gt;====&lt;br /&gt;
# Add a require statement:&lt;br /&gt;
 require './spec/support/teams_shared.rb'&lt;br /&gt;
# Add include_context statements in the controller.&lt;br /&gt;
 include_context &amp;quot;object initializations&amp;quot;&lt;br /&gt;
 include_context 'authorization check'&lt;br /&gt;
# Why this file? - There are a lot of methods common in the Teams Related Files, they basically use similar / same stubbed objects and methods. Implementing the teams_shared.rb file keeps the code DRY and makes use of good design principles.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; How to run the test? &amp;lt;/font&amp;gt;====&lt;br /&gt;
 rspec spec/controllers/teams_controller.rb&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create teams method' do&lt;br /&gt;
    context 'when everything is right' do&lt;br /&gt;
      it 'creates teams with random names' do&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
        allow(Version).to receive_message_chain(:where, :last).with(any_args).and_return(0.1)&lt;br /&gt;
        para = {id: assignment1.id, team_size: 2}&lt;br /&gt;
        session = {user: instructor, team_type: &amp;quot;Assignment&amp;quot;}&lt;br /&gt;
        result = get :create_teams, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check the team type passed in params to see if it is Assignment or Course type&lt;br /&gt;
# Get the teams belonging to that Assignment or Course and list them all&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'list method' do&lt;br /&gt;
    before(:each) { allow(Assignment).to receive(:find_by).and_return(assignment1) }&lt;br /&gt;
    context 'when type is Assignment' do&lt;br /&gt;
      it 'lists the teams for that Assignment' do&lt;br /&gt;
        params = {id: assignment1.id, type: 'Assignment'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq assignment1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is Course' do&lt;br /&gt;
      it 'lists the teams for that Course' do&lt;br /&gt;
        params = {id: course1.id, type: 'Course'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when type is wrong' do&lt;br /&gt;
      it 'throws error' do&lt;br /&gt;
        params = {id: 52, type: 'Subject'}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :list, params, session&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
        expect(controller.instance_variable_get(:@assignment)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'new method' do&lt;br /&gt;
    it 'creates a new team successfully when all parameters are provided correctly' do&lt;br /&gt;
      allow(Object).to receive_message_chain(:const_get, :find).with(any_args).and_return(assignment1)&lt;br /&gt;
      para = {id: assignment1.id}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :new, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@parent)).to eq assignment1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'update method' do&lt;br /&gt;
    it 'updates the team name' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
      para = { id: team1.id, team: {name: 'rando team'}}&lt;br /&gt;
      session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
      result = get :update, para, session&lt;br /&gt;
      expect(result.status).to eq 302&lt;br /&gt;
      expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
    end&lt;br /&gt;
    # this test will fail even though it should normally pass, that's because it runs into an error at @team.save&lt;br /&gt;
    # RumtimeError: stubbed models are not allowed to access the database - AssignmentTeam#save()&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'delete method' do&lt;br /&gt;
    before(:each) { request.env['HTTP_REFERER'] = root_url }&lt;br /&gt;
    context 'when called and team is nil' do&lt;br /&gt;
      it 'simply redirects' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to :back&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq nil&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when called and team is not nil and it does not hold a topic' do&lt;br /&gt;
      it 'deletes the team' do&lt;br /&gt;
        allow(Team).to receive(:find_by).and_return(team5)&lt;br /&gt;
        allow(Object).to receive_message_chain(:const_get, :find).and_return(course1)&lt;br /&gt;
        allow(team5).to receive(:destroy).and_return(nil)&lt;br /&gt;
        para = {id: 5}&lt;br /&gt;
        session = {user: instructor, team_type: 'CourseTeam'}&lt;br /&gt;
        result = get :delete, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(controller.instance_variable_get(:@team)).to eq team5&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'inherit method' do&lt;br /&gt;
    context 'called when assignment belongs to course and team is not empty' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        allow(course1).to receive(:get_teams).and_return([team5, team6])&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to course but team is empty' do&lt;br /&gt;
      it 'flashes note' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment belongs to no course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'flashes error' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team5.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :inherit, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'bequeath method' do&lt;br /&gt;
    context 'called when assignment has a course' do&lt;br /&gt;
      it 'runs successfully' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        allow(Course).to receive(:find).and_return(course1)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'called when assignment does not have a course' do&lt;br /&gt;
      let(:fasg) { build_stubbed(:assignment, id: 1074, course_id: -2) }&lt;br /&gt;
      # a temporary assigment object is created with an abnormal course_id so that we can check the fail condition of the method&lt;br /&gt;
      it 'fails' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team2)&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(fasg)&lt;br /&gt;
        para = {id: team2.id}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :bequeath, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:controller =&amp;gt; 'teams', :action =&amp;gt; 'list', :id =&amp;gt; fasg.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 8: Edit method &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team with the 'id' present in params&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'edit method' do&lt;br /&gt;
    it 'passes the test' do&lt;br /&gt;
      allow(Team).to receive(:find).and_return(team1)&lt;br /&gt;
      para = {id: team1.id}&lt;br /&gt;
      session = {user: ta}&lt;br /&gt;
      result = get :edit, para, session&lt;br /&gt;
      expect(result.status).to eq 200&lt;br /&gt;
      expect(controller.instance_variable_get(:@team)).to eq team1&lt;br /&gt;
    end&lt;br /&gt;
    # this method has only 1 line which is just to look up a team with the id present in the params&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 9: Create an empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the parent (Assignment or Course) based on the team type which starts the session&lt;br /&gt;
# It checks whether a team with the same exists in that category&lt;br /&gt;
# If team exists, it throws TeamExistsError and redirects to 'new' team form page&lt;br /&gt;
# If team doesn't exist, it creates a new team&lt;br /&gt;
# Successful message is displayed and user is redirected to 'list' teams page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = 1&amp;gt;&lt;br /&gt;
  describe 'create method' do&lt;br /&gt;
    context 'when invoked with a team which does not exist' do&lt;br /&gt;
      it 'creates it' do&lt;br /&gt;
        allow(Assignment).to receive(:find).and_return(assignment1)&lt;br /&gt;
        para = { id: assignment1.id, team: {name: 'rando team'}}&lt;br /&gt;
        session = {user: ta, team_type: 'Assignment'}&lt;br /&gt;
        result = get :create, para, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(:action =&amp;gt; 'list', :id =&amp;gt; assignment1.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams test.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 Teams controller.PNG]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size =1&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe 'POST #create' do&lt;br /&gt;
    #before(:each) do&lt;br /&gt;
    # @student = AssignmentParticipant.new&lt;br /&gt;
    #end&lt;br /&gt;
    # When assignment team is empty it flashes a notice&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return([])&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:''&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #happy flow to create team&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(User).to receive(:find).with(1).and_return(team_user1)&lt;br /&gt;
        allow_any_instance_of(Team).to receive(:add_member).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name os already in use, it flashes message&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:empty?).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'create'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#update' do&lt;br /&gt;
    #When the name is not already present it updates the name&lt;br /&gt;
    context 'update team name when matching name not found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return([])&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team7).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #When no team has name and only one matching team is found,update the name&lt;br /&gt;
    context 'update name when name is found' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:update_attribute).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        allow(team8).to receive(:name).and_return(&amp;quot;test&amp;quot;)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    #when the team name is already in use, then flash the error message&lt;br /&gt;
    context 'name is already in use' do&lt;br /&gt;
      it 'flash notice' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team1)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team8)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).with('1').and_return(student1)&lt;br /&gt;
        allow(AuthorizationHelper).to receive(:current_user_has_id).with(any_args).and_return(true)&lt;br /&gt;
        allow(student1).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team8).to receive(:user_id).with(any_args).and_return(1)&lt;br /&gt;
        allow(team1).to receive(:length).and_return(2)&lt;br /&gt;
&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          },&lt;br /&gt;
          action: 'update'&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '1'&amp;gt;&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
    #remove participant from team and remove team if he was the only particilant&lt;br /&gt;
    context 'remove team user' do&lt;br /&gt;
      it 'remove user' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
        allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
        allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
        allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          team_id:1,&lt;br /&gt;
          user_id:1,&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result = post :remove_participant, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;P = Pending status &amp;lt;br&amp;gt;&lt;br /&gt;
D = Denied status &amp;lt;br&amp;gt;&lt;br /&gt;
A = Accepted status &lt;br /&gt;
# Test the controller :&lt;br /&gt;
 rspec spec/controllers/join_team_request_controller_spec.rb&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt; &lt;br /&gt;
  describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      # Stubbing participant to receive an object with id = 1&lt;br /&gt;
      allow(Participant).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(participant)&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when resource is not saved!&amp;quot; do&lt;br /&gt;
      it &amp;quot;renders new page&amp;quot; do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(invalidrequest)&lt;br /&gt;
        params = {participant_id: participant.id, team_id: -2}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response).to render_template(&amp;quot;new&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # Testing when the object is being saved to the database&lt;br /&gt;
    context &amp;quot;when resource is saved&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:new).and_return(join_team_request2)&lt;br /&gt;
        allow(Team).to receive(:find).with(&amp;quot;1&amp;quot;).and_return(team1)&lt;br /&gt;
        allow(Assignment).to receive(:find).with(1).and_return(assignment1)&lt;br /&gt;
        allow(Participant).to receive(:where).with(user_id: 1,parent_id: '1').and_return([participant])&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;valid response&amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
        params = {&lt;br /&gt;
          id: 2,&lt;br /&gt;
          join_team_request2: {&lt;br /&gt;
            status: 'P'&lt;br /&gt;
          },&lt;br /&gt;
          team_id: 1,&lt;br /&gt;
          assignment_id: 1&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        post :create, params, session&lt;br /&gt;
        expect(response.status).to eq 302&lt;br /&gt;
        expect(join_team_request2.status).to eq('P')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;when it is not created&amp;quot; do&lt;br /&gt;
      it &amp;quot;will page for new &amp;quot; do&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(false)&lt;br /&gt;
        params = {action: 'new'}&lt;br /&gt;
        session = {user: student1}&lt;br /&gt;
        get :new, params, session&lt;br /&gt;
        expect(response.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
 &lt;br /&gt;
 describe &amp;quot;#decline&amp;quot; do&lt;br /&gt;
    context &amp;quot;when join team request is declined&amp;quot; do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        allow(JoinTeamRequest).to receive(:find).and_return(join_team_request2)&lt;br /&gt;
        allow(join_team_request2).to receive(:save).and_return(true)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will change status to 'D'&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;will redirect to view student teams path&amp;quot; do&lt;br /&gt;
        params = {action: 'decline'}&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :decline, params, session&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Since this method is private there is no test case written for it.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest coverage.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Test Pass/ Fail &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# All tests, except 1 pass. &lt;br /&gt;
# The test that fails is for the &amp;quot;get index&amp;quot; method. We have identified that there is no route the view/index is going to.&lt;br /&gt;
 def respond_after(request)&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html&lt;br /&gt;
      format.xml { render xml: request }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[[File:E2167 JoinTeamRequest test.PNG]]&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model.&lt;br /&gt;
  &lt;br /&gt;
describe &amp;quot;POST #create&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when it is valid&amp;quot; do&lt;br /&gt;
      it &amp;quot;will create an advertisement&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
          id: team1.id,&lt;br /&gt;
          team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
  &lt;br /&gt;
 context &amp;quot;when advertisement is updated&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is updated&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not updated due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :update, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not updated!&amp;quot;&lt;br /&gt;
        expect(result.status).to eq 200&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&lt;br /&gt;
 describe &amp;quot;POST #remove&amp;quot; do&lt;br /&gt;
&lt;br /&gt;
    context &amp;quot;when advertisement is removed&amp;quot; do&lt;br /&gt;
      it &amp;quot;the advertisement is removed&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_return(true)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
        expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;the advertisement is not removed due to error&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find_by).and_return(team1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:exists?).and_return(true)&lt;br /&gt;
        allow(team1).to receive(:assignment).and_return(assignment1)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find_by).and_return(participant)&lt;br /&gt;
        allow(team1).to receive(:update_attributes).and_raise(StandardError)&lt;br /&gt;
        params  = {&lt;br /&gt;
            id: team1.id,&lt;br /&gt;
            team_id: team1.id,&lt;br /&gt;
        }&lt;br /&gt;
        session = {user: ta}&lt;br /&gt;
        result = get :remove, params, session&lt;br /&gt;
        expect(flash[:error]).to eq &amp;quot;An error occurred and your advertisement was not removed!&amp;quot;&lt;br /&gt;
        expect(result).to redirect_to(request.env['HTTP_REFERER'] ? :back : (:root))&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage. &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 AdvertisePartner.PNG]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2127 Advertise run file.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Old Page Link =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
We have created a new page due to a title error at the new one.&lt;br /&gt;
Link to the old page : https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files#Description_about_project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Github Coverage &amp;lt;/font&amp;gt;====&lt;br /&gt;
[[File:E2167 JoinTeamRequest git.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu (mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=142004</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=142004"/>
		<updated>2021-11-29T22:48:56Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if the current list to display is at assignment or course level&lt;br /&gt;
# Display the teams according to the level&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;The student teams controller is used to add students to the team, update team name and remove participants from team. &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
   describe 'POST #create' do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      @student = AssignmentParticipant.new&lt;br /&gt;
    end&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return(nil)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(student1).to receive(:user_id)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(student1).to receive(:user_id)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(student1).to receive(:user_id)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
describe '#update' do&lt;br /&gt;
    context 'update team name' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team7)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(team7).to receive(:destroy_all)&lt;br /&gt;
        allow(student1).to receive(save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
   context 'remove team user' do&lt;br /&gt;
     it 'remove user' do&lt;br /&gt;
    allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
    allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
    allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
    allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
    allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
    session = {user:student1}&lt;br /&gt;
    params = {&lt;br /&gt;
      team_id:1,&lt;br /&gt;
      user_id:1,&lt;br /&gt;
      student_id:1,&lt;br /&gt;
      team:{&lt;br /&gt;
        name:'test'&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    result = post :remove_participant, params, session&lt;br /&gt;
    expect(result.status).to eq 302&lt;br /&gt;
    # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;P = Pending status &amp;lt;br&amp;gt;&lt;br /&gt;
D = Denied status &amp;lt;br&amp;gt;&lt;br /&gt;
A = Accepted status &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu(mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=142003</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=142003"/>
		<updated>2021-11-29T22:48:15Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if the current list to display is at assignment or course level&lt;br /&gt;
# Display the teams according to the level&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
The student teams controller is used to add students to the team, update team name and remove participants from team. &lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
   describe 'POST #create' do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      @student = AssignmentParticipant.new&lt;br /&gt;
    end&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return(nil)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(student1).to receive(:user_id)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(student1).to receive(:user_id)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(student1).to receive(:user_id)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
describe '#update' do&lt;br /&gt;
    context 'update team name' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team7)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(team7).to receive(:destroy_all)&lt;br /&gt;
        allow(student1).to receive(save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
   context 'remove team user' do&lt;br /&gt;
     it 'remove user' do&lt;br /&gt;
    allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
    allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
    allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
    allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
    allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
    session = {user:student1}&lt;br /&gt;
    params = {&lt;br /&gt;
      team_id:1,&lt;br /&gt;
      user_id:1,&lt;br /&gt;
      student_id:1,&lt;br /&gt;
      team:{&lt;br /&gt;
        name:'test'&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    result = post :remove_participant, params, session&lt;br /&gt;
    expect(result.status).to eq 302&lt;br /&gt;
    # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;P = Pending status &amp;lt;br&amp;gt;&lt;br /&gt;
D = Denied status &amp;lt;br&amp;gt;&lt;br /&gt;
A = Accepted status &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu(mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=142002</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=142002"/>
		<updated>2021-11-29T22:44:49Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if the current list to display is at assignment or course level&lt;br /&gt;
# Display the teams according to the level&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
   describe 'POST #create' do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      @student = AssignmentParticipant.new&lt;br /&gt;
    end&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return(nil)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(student1).to receive(:user_id)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(student1).to receive(:user_id)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(student1).to receive(:user_id)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
describe '#update' do&lt;br /&gt;
    context 'update team name' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team7)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(team7).to receive(:destroy_all)&lt;br /&gt;
        allow(student1).to receive(save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
   context 'remove team user' do&lt;br /&gt;
     it 'remove user' do&lt;br /&gt;
    allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
    allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
    allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
    allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
    allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
    session = {user:student1}&lt;br /&gt;
    params = {&lt;br /&gt;
      team_id:1,&lt;br /&gt;
      user_id:1,&lt;br /&gt;
      student_id:1,&lt;br /&gt;
      team:{&lt;br /&gt;
        name:'test'&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    result = post :remove_participant, params, session&lt;br /&gt;
    expect(result.status).to eq 302&lt;br /&gt;
    # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;P = Pending status &amp;lt;br&amp;gt;&lt;br /&gt;
D = Denied status &amp;lt;br&amp;gt;&lt;br /&gt;
A = Accepted status &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu(mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=142001</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=142001"/>
		<updated>2021-11-29T22:44:09Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
Github Repo : [https://github.com/MathewAaron/expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Create teams with random names &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After checking for the team type and team size, call function to randomize the teams&lt;br /&gt;
# Print message &amp;quot;Random teams have been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list of teams&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: List the teams assignment wise or course wise &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if the current list to display is at assignment or course level&lt;br /&gt;
# Display the teams according to the level&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Create a new empty team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team already exists with the same name&lt;br /&gt;
# If it doesn’t, create a new team with a name&lt;br /&gt;
# If a team is created, print &amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully created.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to create a new team and redirect to new team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Update an existing team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if a team with new suggested name already exists&lt;br /&gt;
# If it doesn’t, update and save the new team name&lt;br /&gt;
# Print &amp;quot;The team &amp;lt;new_team_name&amp;gt; has been successfully updated.&amp;quot;&lt;br /&gt;
# Redirect to list team page&lt;br /&gt;
# If error is there, fail to update team and redirect to edit team form page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 5: Delete a team &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Check if there is a team in waitlist for the topic that the team to be deleted holds&lt;br /&gt;
# If there is a team on the waitlist, assign the topic to that team. If multiple teams are there, assign the topic to the first team in the waitlist.&lt;br /&gt;
# Delete the team’s records in team, teams_users and sign_up_team tables&lt;br /&gt;
# Print “&amp;quot;The team &amp;lt;team_name&amp;gt; has been successfully deleted.&amp;quot;&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 6: Copy existing teams from a course down to an assignment &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the course that the assignment belongs to&lt;br /&gt;
# If a course for the assignment doesn’t exist, give the error message &amp;quot;No course was found for this assignment.&amp;quot;&lt;br /&gt;
# Otherwise fetch all the teams that exist in the course&lt;br /&gt;
# If no teams exist, give the error message &amp;quot;No teams were found when trying to inherit.&amp;quot;&lt;br /&gt;
# Else copy all teams and assign them the new assignment id&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 7: Copy existing team from assignment to course &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the assignment id to which the team belongs&lt;br /&gt;
# Find the course to which the assignment belongs&lt;br /&gt;
# If assignment doesn’t belong to a course, give the error message &amp;quot;This assignment is not &amp;lt;assignment_name&amp;gt; with a course.&amp;quot;&lt;br /&gt;
# Otherwise copy team from assignment and assign it the course id&lt;br /&gt;
# Print success message &amp;quot;The team &amp;lt;team_name&amp;gt; was successfully copied to &amp;lt;course_name&amp;gt;&amp;quot;&lt;br /&gt;
# Redirect to list page&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
 describe '#view' do&lt;br /&gt;
    it 'sets the student' do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find).with('12345').and_return student&lt;br /&gt;
      allow(student_teams_controller).to receive(:current_user_id?)&lt;br /&gt;
      allow(student_teams_controller).to receive(:params).and_return(student_id: '12345')&lt;br /&gt;
      allow(student).to receive(:user_id)&lt;br /&gt;
      student_teams_controller.view&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
   describe 'POST #create' do&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      @student = AssignmentParticipant.new&lt;br /&gt;
    end&lt;br /&gt;
    context 'when create Assignment team' do&lt;br /&gt;
      it 'flash notice when team is empty' do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: '', parent_id: 1).and_return(nil)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(student1).to receive(:user_id)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;create team&amp;quot; do&lt;br /&gt;
      it &amp;quot;saves the team&amp;quot; do&lt;br /&gt;
        allow(AssignmentNode).to receive(:find_by).with(node_object_id: 1).and_return(node1)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:new).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(student1).to receive(:user_id)&lt;br /&gt;
        allow(team7).to receive(:save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context &amp;quot;name already in use&amp;quot; do&lt;br /&gt;
      it &amp;quot;flash notice&amp;quot; do&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(student1).to receive(:user_id)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :create, params, session&lt;br /&gt;
        expect(result.status).to eq 302&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
describe '#update' do&lt;br /&gt;
    context 'update team name' do&lt;br /&gt;
      it 'update name' do&lt;br /&gt;
        allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:find).and_return(team7)&lt;br /&gt;
        allow(AssignmentTeam).to receive(:where).with(name: 'test', parent_id: 1).and_return(team7)&lt;br /&gt;
        allow(team7).to receive(:destroy_all)&lt;br /&gt;
        allow(student1).to receive(save).and_return(true)&lt;br /&gt;
        session = {user:student1}&lt;br /&gt;
        params = {&lt;br /&gt;
          student_id:1,&lt;br /&gt;
          team:{&lt;br /&gt;
            name:'test'&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        result= post :update, params, session&lt;br /&gt;
        expect(result.status).to eq(302)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
 describe '#remove_participant' do&lt;br /&gt;
   context 'remove team user' do&lt;br /&gt;
     it 'remove user' do&lt;br /&gt;
    allow(AssignmentParticipant).to receive(:find).and_return(participant)&lt;br /&gt;
    allow(TeamsUser).to receive(:where).and_return(team_user1)&lt;br /&gt;
    allow(team_user1).to receive(:destroy_all)&lt;br /&gt;
    allow(team_user1).to receive_message_chain(:where,:empty?).and_return(false)&lt;br /&gt;
    allow_any_instance_of(AssignmentParticipant).to receive(:save).and_return(false)&lt;br /&gt;
    session = {user:student1}&lt;br /&gt;
    params = {&lt;br /&gt;
      team_id:1,&lt;br /&gt;
      user_id:1,&lt;br /&gt;
      student_id:1,&lt;br /&gt;
      team:{&lt;br /&gt;
        name:'test'&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    result = post :remove_participant, params, session&lt;br /&gt;
    expect(result.status).to eq 302&lt;br /&gt;
    # expect(result).to redirect_to(view_student_teams_path(:student_id =&amp;gt; 1))&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;P = Pending status &amp;lt;br&amp;gt;&lt;br /&gt;
D = Denied status &amp;lt;br&amp;gt;&lt;br /&gt;
A = Accepted status &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;====&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Our Team =&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
Yi Qiu(mentor)&amp;lt;br&amp;gt;&lt;br /&gt;
Aaron Mathew (asmathew@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Priya Jakhar (pjakhar@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Supriya Krishna (sbkrishn@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Snehapriyaa Mathiyalaghan (smathiy@ncsu.edu)&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140781</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140781"/>
		<updated>2021-11-04T01:25:34Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;P = Pending status &amp;lt;br&amp;gt;&lt;br /&gt;
D = Denied status &amp;lt;br&amp;gt;&lt;br /&gt;
A = Accepted status &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140778</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140778"/>
		<updated>2021-11-04T01:24:26Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;P = Pending status&lt;br /&gt;
D = Denied status&lt;br /&gt;
A = Accepted status &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140777</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140777"/>
		<updated>2021-11-04T01:23:44Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted: user association to the respective team is deleted and hence user is no longer part of the team.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '3'&amp;gt;P = Pending status&lt;br /&gt;
&lt;br /&gt;
D = Denied status&lt;br /&gt;
&lt;br /&gt;
A = Accepted status &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140776</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140776"/>
		<updated>2021-11-04T01:21:14Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user.&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed.&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted. &amp;lt;br/&amp;gt;&lt;br /&gt;
user association to the respective team is deleted and hence user is no longer part of the team. &amp;lt;br/&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '3'&amp;gt;P = Pending status&lt;br /&gt;
&lt;br /&gt;
D = Denied status&lt;br /&gt;
&lt;br /&gt;
A = Accepted status &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140774</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140774"/>
		<updated>2021-11-04T01:19:23Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#Given user is not defined: When given user is defined, link is provided to create the user. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#Selected team to which user is being added belongs to an assignment: When user is not a participant of the assignment, link is provided to add the user to the assignment. When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &amp;lt;br/&amp;gt; &lt;br /&gt;
&lt;br /&gt;
#Selected team to which user is being added belongs to a course: When user is not a participant of the course, link is provided to add the user to the course. When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &amp;lt;br/&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#User under assignment or course team is deleted. &amp;lt;br/&amp;gt;&lt;br /&gt;
user association to the respective team is deleted and hence user is no longer part of the team. &amp;lt;br/&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path&amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '3'&amp;gt;P = Pending status&lt;br /&gt;
&lt;br /&gt;
D = Denied status&lt;br /&gt;
&lt;br /&gt;
A = Accepted status &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path.&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&amp;lt;font size = '2'&amp;gt;&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path. &amp;lt;/font&amp;gt;&lt;br /&gt;
[[File:Teams adv remove.png]]&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140770</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140770"/>
		<updated>2021-11-04T01:14:42Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '3'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
*Given user is not defined: &amp;lt;br/&amp;gt;&lt;br /&gt;
When given user is defined, link is provided to create the user. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Selected team to which user is being added belongs to an assignment:&amp;lt;br/&amp;gt;&lt;br /&gt;
When user is not a participant of the assignment, link is provided to add the user to the assignment. &amp;lt;br/&amp;gt;&lt;br /&gt;
When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &amp;lt;br/&amp;gt; &lt;br /&gt;
&lt;br /&gt;
*Selected team to which user is being added belongs to a course:&amp;lt;br/&amp;gt;&lt;br /&gt;
When user is not a participant of the course, link is provided to add the user to the course. &amp;lt;br/&amp;gt;&lt;br /&gt;
When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '3'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
*User under assignment or course team is deleted. &amp;lt;br/&amp;gt;&lt;br /&gt;
user association to the respective team is deleted and hence user is no longer part of the team. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;student_teams_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;===&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;join_team_requests_controller.rb&amp;lt;/font&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font size = '3'&amp;gt;P = Pending status&lt;br /&gt;
&lt;br /&gt;
D = Denied status&lt;br /&gt;
&lt;br /&gt;
A = Accepted status &amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;advertise_partner_controller.rb &amp;lt;/font&amp;gt;===&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path .&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '3'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path . &lt;br /&gt;
[[File:Teams adv remove.png]]&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140769</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140769"/>
		<updated>2021-11-04T01:07:46Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
=== teams_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;font size = '3'&amp;gt; Given user is not defined.&amp;lt;/font&amp;gt; &amp;lt;br/&amp;gt;&lt;br /&gt;
When given user is defined, link is provided to create the user. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;font size = '3'&amp;gt; Selected team to which user is being added belongs to an assignment:&amp;lt;/font&amp;gt; &amp;lt;br/&amp;gt;&lt;br /&gt;
When user is not a participant of the assignment, link is provided to add the user to the assignment. &amp;lt;br/&amp;gt;&lt;br /&gt;
When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &amp;lt;br/&amp;gt; &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;font size = '3'&amp;gt;Selected team to which user is being added belongs to a course:&amp;lt;/font&amp;gt; &amp;lt;br/&amp;gt;&lt;br /&gt;
When user is not a participant of the course, link is provided to add the user to the course. &amp;lt;br/&amp;gt;&lt;br /&gt;
When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;font size = '3'&amp;gt;User under assignment or course team is deleted.&amp;lt;/font&amp;gt; &amp;lt;br/&amp;gt;&lt;br /&gt;
user association to the respective team is deleted and hence user is no longer part of the team. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== student_teams_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;===&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
=== join_team_requests_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
P = Pending status&lt;br /&gt;
&lt;br /&gt;
D = Denied status&lt;br /&gt;
&lt;br /&gt;
A = Accepted status&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
=== advertise_partner_controller.rb ===&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 1: Creating new advertisement for partners. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 2: Updating the advertisement. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path .&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 3: Remove the advertisement. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path . &lt;br /&gt;
[[File:Teams adv remove.png]]&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140768</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140768"/>
		<updated>2021-11-04T01:05:23Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== teams_controller.rb ==&lt;br /&gt;
&lt;br /&gt;
== teams_users_controller.rb ==&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;font size = '3'&amp;gt; Given user is not defined.&amp;lt;/font&amp;gt; &amp;lt;br/&amp;gt;&lt;br /&gt;
When given user is defined, link is provided to create the user. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;font size = '3'&amp;gt; Selected team to which user is being added belongs to an assignment:&amp;lt;/font&amp;gt; &amp;lt;br/&amp;gt;&lt;br /&gt;
When user is not a participant of the assignment, link is provided to add the user to the assignment. &amp;lt;br/&amp;gt;&lt;br /&gt;
When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &amp;lt;br/&amp;gt; &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;font size = '3'&amp;gt;Selected team to which user is being added belongs to a course:&amp;lt;/font&amp;gt; &amp;lt;br/&amp;gt;&lt;br /&gt;
When user is not a participant of the course, link is provided to add the user to the course. &amp;lt;br/&amp;gt;&lt;br /&gt;
When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;font size = '3'&amp;gt;User under assignment or course team is deleted.&amp;lt;/font&amp;gt; &amp;lt;br/&amp;gt;&lt;br /&gt;
user association to the respective team is deleted and hence user is no longer part of the team. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
== student_teams_controller.rb ==&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;===&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
== join_team_requests_controller.rb ==&lt;br /&gt;
&lt;br /&gt;
P = Pending status&lt;br /&gt;
&lt;br /&gt;
D = Denied status&lt;br /&gt;
&lt;br /&gt;
A = Accepted status&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 1: Creating a team request &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 2: Decline a team request. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 3: Check team status. &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
== advertise_partner_controller.rb ==&lt;br /&gt;
Scenario 1: Creating new advertisement for partners.&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
Scenario 2: Updating the advertisement.&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path .&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
Scenario 3: Remove the advertisement.&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path . &lt;br /&gt;
[[File:Teams adv remove.png]]&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140767</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Testing - Team Related Files</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Testing_-_Team_Related_Files&amp;diff=140767"/>
		<updated>2021-11-04T01:03:54Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Relevant links =&lt;br /&gt;
&lt;br /&gt;
= About Expertiza =&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework.  It is a web based program that allows instructors to create and update/edit assignments/tasks, and then assigns them to students.  Students then can submit, edit, and update their assignments, as well as peer review other student's assignments.&lt;br /&gt;
&lt;br /&gt;
= Problem statement and background =&lt;br /&gt;
There are many files related to teams that don’t have enough tests: teams_controller, teams_users_controller, student_teams_controller, join_team_requests_controller, and advertise_for_partner_controller.  They all need essentially the same kind of fixtures or mocks to enable testing: A team that is created, a couple of students that can be added to the team, an invitation that can be sent from one student to another student to join a particular team&lt;br /&gt;
&lt;br /&gt;
= Approach Chosen &amp;amp; Why? =&lt;br /&gt;
In this project we have first identified all the set of scenarios related to team controllers. Each of the scenarios are identified as mentioned above and has been subdivided into a number of ways in which it can be realized. This will ensure that code is robust to any kind of unexpected changes and that the functionality will not be broken when deployed in production. &lt;br /&gt;
We have chosen to bring about this robustness of test by writing unit test and functional tests using RSpec and Capybara respectively. Unit Tests will ensure that the particular functionality is being tested in a isolated setup which would even include the edge cases whereas the functional tests will ensure that this teams feature is in resonance with the other features and works coherently.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
&lt;br /&gt;
== teams_controller.rb ==&lt;br /&gt;
&lt;br /&gt;
== teams_users_controller.rb ==&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;Scenario 1: Add new user to the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;font size = '3'&amp;gt; Given user is not defined.&amp;lt;/font&amp;gt; &amp;lt;br/&amp;gt;&lt;br /&gt;
When given user is defined, link is provided to create the user. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;font size = '3'&amp;gt; Selected team to which user is being added belongs to an assignment:&amp;lt;/font&amp;gt; &amp;lt;br/&amp;gt;&lt;br /&gt;
When user is not a participant of the assignment, link is provided to add the user to the assignment. &amp;lt;br/&amp;gt;&lt;br /&gt;
When the assignment team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &amp;lt;br/&amp;gt; &lt;br /&gt;
&lt;br /&gt;
*&amp;lt;font size = '3'&amp;gt;Selected team to which user is being added belongs to a course:&amp;lt;/font&amp;gt; &amp;lt;br/&amp;gt;&lt;br /&gt;
When user is not a participant of the course, link is provided to add the user to the course. &amp;lt;br/&amp;gt;&lt;br /&gt;
When the course team already has maximum number of users, &amp;quot;Maximum users reached&amp;quot; notification is flashed. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_create.png|600px]]&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;font size = '4'&amp;gt;Scenario 2: Delete user from the selected team.&amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;font size = '3'&amp;gt;User under assignment or course team is deleted.&amp;lt;/font&amp;gt; &amp;lt;br/&amp;gt;&lt;br /&gt;
user association to the respective team is deleted and hence user is no longer part of the team. &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:user_remove.png]]&lt;br /&gt;
&lt;br /&gt;
== student_teams_controller.rb ==&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 1: Set the variables for view &amp;lt;/font&amp;gt;===&lt;br /&gt;
#If the current user is student and their User Ids match, then the following values are set: @send_invs, @received_invs,  @current_due_date, @users_on_waiting_list, @teammate_review_allowed&lt;br /&gt;
# If the current user is not student or the User Ids do not match, then the return from method&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 2: Create Student teams &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# If team name is empty, flash an error message saying &amp;quot;Team name missing while creating team&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name already in use, &amp;quot;Team name being created was already in use&amp;quot; and redirect to view_student_teams_path&lt;br /&gt;
# If team name is not empty and team name not in use, save team data, add logged in student to team and redirect to view_student_teams_path.&lt;br /&gt;
[[File:Team stud create.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 3: Update team name: &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# Find the team that should be updated.&lt;br /&gt;
# If there are no matching teams, call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there is exactly one match, then call team_created_successfully and redirect to view_student_teams_path&lt;br /&gt;
# If there are more than one team, then show the following error message &amp;quot;Team name being updated to was already in use&amp;quot; and redirect to edit_student_teams_path&lt;br /&gt;
[[File:Team student update.png]]&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;font size = '4'&amp;gt; Scenario 4: Remove team participants &amp;lt;/font&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
# Find the user who has to be removed.&lt;br /&gt;
# Remove the user from team.&lt;br /&gt;
# If the team does not have any more participants, remove the team record from database.&lt;br /&gt;
# If the assignment has sign up sheet, then add the topic back to topics pool or assign the topic to a new team from waitlist&lt;br /&gt;
# Remove all the invitations sent and redirect to view_student_teams_path&lt;br /&gt;
[[File:Team stud remove.png]]&lt;br /&gt;
&lt;br /&gt;
== join_team_requests_controller.rb ==&lt;br /&gt;
&lt;br /&gt;
P = Pending status&lt;br /&gt;
&lt;br /&gt;
D = Denied status&lt;br /&gt;
&lt;br /&gt;
A = Accepted status&lt;br /&gt;
&lt;br /&gt;
Scenario 1: Creating a team request&lt;br /&gt;
# If the team id is verified along with user id and assignment id, create a new request and change @join_team_request = 'P' .&lt;br /&gt;
# If error occurs, flash error message.&lt;br /&gt;
&lt;br /&gt;
Scenario 2: Decline a team request.&lt;br /&gt;
# After verifying team_user_id, change @join_team_request.status = 'D' .&lt;br /&gt;
# Redirect to view_student_teams_path&lt;br /&gt;
&lt;br /&gt;
Scenario 3: Check team status.&lt;br /&gt;
# If team if full. Print error message &amp;quot;This team is full.&amp;quot; .&lt;br /&gt;
# If team is not empty, print message &amp;quot;You are already a member of this team.&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
== advertise_partner_controller.rb ==&lt;br /&gt;
Scenario 1: Creating new advertisement for partners.&lt;br /&gt;
# We set the advertise_for_partner : True , comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
[[File:Teams adv1.png]]&lt;br /&gt;
&lt;br /&gt;
Scenario 2: Updating the advertisement.&lt;br /&gt;
# We set the comments_for_advertisement[param] when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Update Unsuccessful : If there is an error during update then the following error message is thrown &amp;quot;An error occurred and your advertisement was not updated.&amp;quot; and edit page is rendered.&lt;br /&gt;
# Update Successful : If the advertisement is successfully updated in the database then the &amp;quot;Your advertisement was successfully updated!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path .&lt;br /&gt;
&lt;br /&gt;
[[File:Teams adv create.png]]&lt;br /&gt;
&lt;br /&gt;
Scenario 3: Remove the advertisement.&lt;br /&gt;
# We set the advertise_for_partner : False , comments_for_advertisement : nil when the user wants to set a new advertisement for partners in AssignmentTeam model. &lt;br /&gt;
# Remove Unsuccessful : If there is an error during removing the advertisement then the following error message is thrown &amp;quot;An error occurred and your advertisement was not removed.&amp;quot; and the previous page is rendered.&lt;br /&gt;
# Remove Successful : If the advertisement is successfully removed in the database then the &amp;quot;Your advertisement was successfully removed!&amp;quot; message is prompted and the user is redirected to the view_student_teams_path . &lt;br /&gt;
[[File:Teams adv remove.png]]&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021&amp;diff=139200</id>
		<title>CSC/ECE 517 Fall 2021</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021&amp;diff=139200"/>
		<updated>2021-10-19T20:01:47Z</updated>

		<summary type="html">&lt;p&gt;Sbkrishn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== OSS Projects ==&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - {$num}. {$desc.title}]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2128. Refactor student_quizzes_controller.rb &amp;amp; late_policies_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2132. Add tests cases for review mapping helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2134. Write unit tests for admin_controller.rb and institution_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2138. Auto-generate submission directory names based on assignment]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2142. Improve e-mail notifications]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2133. Write tests for popup_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2120. Refactor reputation_web_service_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2139. Remove multiple topics at a time]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2131. Improve assessment360_controller.rb]]&lt;/div&gt;</summary>
		<author><name>Sbkrishn</name></author>
	</entry>
</feed>