CSC/ECE 517 Fall 2016/E1644. Refactor and test Teams Controller

From Expertiza_Wiki
Jump to navigation Jump to search

E1644. Refactor and Test 'Teams_Controller' Controller<ref>Project Description document https://google.com</ref>

This page provides a brief description of the Expertiza project. The project is aimed at refactoring and testing the 'Teams_Controller' Controller, which contains the methods to create new teams, list the existing teams, create new teams by inheriting existing teams, deleting existing teams and creating multiple teams at once by assigning them random topics. The project entailed, refactoring some part of the controller to improve the readability of code and then creating test cases in RSpec to verify the methods it possesses.


Introduction to Expertiza

Expertiza is a peer review based system which provides incremental learning from the class. This project has been developed together by faculty and students using Ruby on Rails framework. Expertiza allows the instructor to create, edit and delete assignments, create new assignment topics, assign them to a particular class or selected students, have students work on teams and then review each other's assignments at the end. For the students, they can signup for topics, form teams, and submit their projects and assignments. Students then review the work done by other students and give suggestions to improve. Teams after reviews are allotted scores and they can refer to the peer comments to further improve their work. It also supports submission of different file types for assignments, including the URLs and wiki pages.


Project Description

Teams_Controller primarily handles the team creation, deletion and other behaviours. Most of those are called from the instructor’s view. When manual testing is done, most of the methods can be called by clicking the “Create teams” icon from both assignments and courses. The following tasks have been performed as per the requirements.

As a part of the project, some GUI's changes had to be made because they did not work the way they should have, some minor issues in the code were fixed and tests were written in RSpec for the methods delete, create, create teams, list and inherit.

Create Method

The method Create is called when an instructor tries to create a team manually. This works for both, creating assignment teams and course teams. Assignment teams are teams made to do a particular assignment together and Course Teams are teams which are made for the whole course.

Following Test Cases were written and executed in RSpec to test this method:

  • To verify that the Instructor is able to create course teams.
  • To verify that the Instructor is able to create assignment teams.

Delete Method

The method Delete is called when an instructor tries to delete a team manually. This works for both, deleting assignment teams and course teams.

Following Test Cases were written and executed in RSpec to test this method:

  • To verify that the Instructor is able to delete course teams.
  • To verify that the Instructor is able to delete assignment teams.

List Method

The method List lists all the team nodes and the instructor is able to expand each team node to see the user nodes as well.

Following Test Cases were written and executed in RSpec to test this method:

  • To check that all teams are being listed in the view.

Inherit Method

The method Inherit inherits teams from course to assignments, but the “Inherit Teams From Course” option should not display when either 1) we are editing a course object or 2) the current assignment object does not have a course associated with it.

Following Test Cases were written and executed in RSpec to test this method:

  • To check that inherit teams is displayed while creating an assignment team.
  • To check that inherit teams is not displayed while creating a course team.
  • To check that inherit teams is not displayed while creating teams for an assignment without a course.


Refactoring

Refactoring<ref>Refactoring https://en.wikipedia.org/wiki/Code_refactoring</ref> is restructuring of code without the need of changing any external behavior. It reduces complexity and improves readability. It also becomes easy to extend the application with respect to different modules and their functionalities. Some common techniques to refactor are:

  • Moving methods to appropriate modules
  • Breaking methods into more meaningful functionality
  • Creating more generalized code.
  • Renaming methods and variable.
  • Inheritance

As the part of the project, the variable @signUps in the delete method in the teams_controller was changed to snake case, tp improve readability of code.


Changes in UI, to fix view for inherit team In the new.html.erb file of teams, we enclose the inherit teams section in an if condition that checks that the parent of the team is not a Course and it is not an Assignment whose course is nil.

Testing the Teams_Controller

Testing Inherit Method

 it 'should display inherit teams while creating an assignment team' do
   create(:assignment)
   create(:assignment_node)
   create(:assignment_team)
   login_as("instructor6")
   visit '/teams/list?id=1&type=Assignment'
   click_link 'Create Team'
   expect(page).to have_content('Inherit Teams From Course')
 end



 it 'should not display inherit teams while creating a course team' do
   create(:course)
   create(:course_node)
   create(:course_team)
   login_as("instructor6")
   visit '/teams/list?id=1&type=Course'
   click_link 'Create Team'
   expect(page).to have_no_content('Inherit Teams From Course')
 end



 it 'should not display inherit teams while creating team for an assignment without a course' do
   create(:assignment_without_course)
   create(:assignment_without_course_node)
   create(:assignment_without_course_team)
   login_as("instructor6")    
   visit '/teams/list?id=1&type=Assignment'
   click_link 'Create Team'
   expect(page).to have_no_content('Inherit Teams From Course')
 end

Testing Create Method

Testing Delete Method

Testing Inherit Method

Testing List Method