CSC/ECE 517 Spring 2017/oss E1712: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
(Modified tasks section)
(Adding specific tasks undertaken in the project)
Line 29: Line 29:
* Feature tests need to be written for the controller  
* Feature tests need to be written for the controller  


==Change Specifics==
The tasks identified above were implemented and the details are given below.
===Invitations Controller===
* A new private function check_users was added which performs some basic checks before the create function is called. In the original implementation, there were a lot of nested if conditions which checked if a user is valid, is a participant in the project, and if the team has slots available. All these checks were the cause of the nested if statements because they needed to be checked before an invitation is sent out to a student. The nested if's were removed by moving all these checks into the private function thereby reducing the ABC size of the create method.
* Nested if statements in the update_join_team_request were removed by breaking the nested statements into separate conditions and using return when the condition fails. For example, when checking if the user is valid, instead of using a nested condition to check validity, if the user is not valid then we throw an error message and return from the function.
* Call to the method find_by_user_id_and_assignment_id has been replaced by find_by and passing the user_id and assignment_id as arguments to find_by. The code snippet showing the change made is shown below.
Before refactoring
<pre>AssignmentParticipant.find_by_user_id_and_assignment_id(inviter_user_id, assignment_id)</pre>
After refactoring
<pre>AssignmentParticipant.find_by(user_id: inviter_user_id, parent_id: assignment_id)</pre>






 
== Test case charts ==
=== Test case charts ===
'''Decline:'''
'''Decline:'''
Assert the change of status to 'D' in the database
Assert the change of status to 'D' in the database

Revision as of 22:23, 30 March 2017

Introduction

This project is part of an educational web application called Expertiza. This wiki gives the details on the refactoring tasks undertaken as part of continuous improvement of Expertiza.

Background

Expertiza is an open source project managed by the faculty and students of NCSU. It is a web application which offers a platform for assignments and allows learning through peer reviews.

Motivation

In the existing code the InvitationController and the JoinTeamRequestsController do the expected task but the there is a lot of redundancy and duplicity in the code, and the comments in the code are few and sparse. The aim of our project was to reduce the complexity of the controller by removing redundant code adding comments so that the code is easy to understand and all the variables used in the code are clearly explained.

Current Implementation

Invitations Controller

Invitations controller handles the functions required to send invitations out to potential teammates for a project. Once a student decides to invite someone into his assignment team the controller performs some checks before sending out the invitations. These checks are performed in the create function. The current implementation has a lot of redundant code and many nested if statements. The ABC size of the method is also very high. The controller also has functions which take care of cases where an invitee accepts/declines an invitation. There is also an option to retract a sent invitation which is handled by the cancel function in the controller.

Tasks Identified

  • Rename to invitations_controller.rb, in accordance with current naming convention.
  • The ABC size for create method is too high and needs to be refactored along by removing other nested if's in create and update_join_team_request methods.
  • Use find_by instead of find_by_name and find_by_user_id_and_assignment_id.
  • Add comments explaining what each method does, and comments on how important variables are used.
  • Pending invitations needs to be displayed in the same format as other tables.
  • Feature tests need to be written for the controller

Join Team Requests Controller

JoinTeamRequests controller deals with the actions to be performed after a student comes across an advertisement to join a project team. Whenever a project team creates an advertisement for others to join their team, students can see a link to the advertisement in the signup sheet. Once the student clicks on the link to the advertisement the student can then request to join the team. The create function in the JoinTeamRequestsController handles the checks before sending out the request. Again, the ABC size for this method is very high as there a lot of nested if conditions. Also, there is duplicate code in some of the functions in this controller which can be moved to a separate function.

Tasks Identified

  • Add comments on why some important variables are used.
  • The ABC size for create method is too high.
  • Nested if's need to be refactored.
  • Duplicate code needs to be removed.
  • Pending join team requests needs to be displayed in the same format as other tables
  • Feature tests need to be written for the controller

Change Specifics

The tasks identified above were implemented and the details are given below.

Invitations Controller

  • A new private function check_users was added which performs some basic checks before the create function is called. In the original implementation, there were a lot of nested if conditions which checked if a user is valid, is a participant in the project, and if the team has slots available. All these checks were the cause of the nested if statements because they needed to be checked before an invitation is sent out to a student. The nested if's were removed by moving all these checks into the private function thereby reducing the ABC size of the create method.
  • Nested if statements in the update_join_team_request were removed by breaking the nested statements into separate conditions and using return when the condition fails. For example, when checking if the user is valid, instead of using a nested condition to check validity, if the user is not valid then we throw an error message and return from the function.
  • Call to the method find_by_user_id_and_assignment_id has been replaced by find_by and passing the user_id and assignment_id as arguments to find_by. The code snippet showing the change made is shown below.

Before refactoring

AssignmentParticipant.find_by_user_id_and_assignment_id(inviter_user_id, assignment_id)

After refactoring

AssignmentParticipant.find_by(user_id: inviter_user_id, parent_id: assignment_id)


Test case charts

Decline: Assert the change of status to 'D' in the database

Cancel


Create function

Running project remotely

VCL is used to host the project remotely. The login credentials as an instructor are "instructor6" with password "password". To login as a student, you can use 'student5425' with password 'password'

http://152.46.20.227:3000

References

  1. Expertiza on GitHub
  2. GitHub Project Repository Fork
  3. The live Expertiza website
  4. Expertiza project documentation wiki
  5. Rspec Documentation