CSC/ECE 517/Spring 2023/E2308. Refactor course.rb and course team.rb models

From Expertiza_Wiki
Jump to navigation Jump to search


Team Contact

Team Members

  • Kartik Rawool, (unityID:khrawool, GitHub:kartikrawool)
  • Ameya Vaichalkar, (unityID:agvaicha, GitHub:ameyagv)
  • Vikram Pande, (unityID:vspande, GitHub:vikrampande7)

Mentor

  • Kartiki Bhandakkar, kbhanda3

Overview of Expertiza

Expertiza is an open-source software written using Ruby on Rails which functions as a learning management software system. It has many different functions and abilities including the ability to create assignments, quizzes, assignment groups, and topics, and also a complete mechanism for providing peer reviews and feedback for other groups and other teammates. Part of its functionality is a system containing information about the course and its associated teams respectively. The Course and CourseTeam which are the models primarily addressed in this project are both critical components in providing this functionality.

Description of Project

course model stores information about the instructor and institution and is associated with other models such as User, CourseParticipant, CourseTeam, Assignment, AssignmentParticipant, and Notification. The course model is responsible for completing a variety of tasks, including returning course teams, returning the submission directory for the course, viewing participants enrolled in the course, adding a participant to the course, copying the Assignment Participants to Course Participants, and checking whether a user is part of any CourseTeam. The problem description lists code smells that need to be fixed. We fixed some issues, such as deleting the unused methods and renaming methods to indicate their action. The renaming problem required us to change a few methods calls where the function to be renamed was used. Also, to reduce the cognitive complexity of the copy_assignment_participants method, we created a method to separate the raising error functionality. Comments were added to indicate the action of the methods.

The course_team is a subclass of the team class. CourseTeams are a type of team that an instructor can use throughout an entire semester, providing consistency in team membership over time. The course_team model is responsible for completing various tasks, including returning the course of the team, adding a participant to the CourseTeam, and copying the CourseTeam Participants to AssignmentTeam Participants. There are methods for importing and exporting data to/from CSV files for CourseTeam objects. The problem description lists code smells/issues that need to be fixed. The issues that we fixed were deleting unused methods, renaming methods, and changing method calls, changing rspec expectations, adding meaningful comments. To refactor methods, DRY principles were used. In addition, analogous changes were made in the assignment_team model.

Files Modified

CHANGES IN MODEL FILES

Changes to app/models/course.rb

 #  Change Rationale Commit Link
1 Checked and Removed get_participant method Checked the usage of Method through IDE whether the function is used, the only call was from course_spec.rb and not from anywhere else. Hence, removed from course.rb Commit
2 Renamed copy_participants method Renamed copy_participants to copy_assignment_participants which makes more sense and a clear idea of how method works and what is the purpose of method. Commit
3 Removed add_member method from course_team model Assignment_team and Course_team are subclasses of Team. Both should follow the similar logic of adding members of respective teams. As of for, add_participants, usage is different for course.rb and course_team.rb, hence it should be present in both. However, to make the code more consistent among classes, team, course_team, and assignment_team, the add_member method should only be present in the team class. Commit
4 Created method raise_errors To reduce Cognitive Complexity of method copy_participants Commit

Changes to app/models/course_team.rb

 #  Change Rationale Commit Link
1 Removed assignment_id CourseTeam and AssignmentTeam inherit from Team class. The teams' table has an attribute parent_id that helps determine whether the team is AssigmentTeam or CourseTeam. Thus, there is no need for assignment_id in the CourseTeam class and no need for course_id in AssignmentTeam class. It will be a bad coding practice to call the assignment_id method on the CourseTeam object, calling the course_id method on the AssignmentTeam object as it would be inappropriate. Commit
2 Renamed copy method as copy_to_assignment_team As this method is copying a CourseTeam to an AssignmentTeam, renamed it as copy_to_assignment_team. A suggestion for copy method in AssignmentTeam would be to rename it as copy_to_course_team. Commit
3 Added Import Functionality Refactored import method, added methods import_options, optional_import_fields, import_options which are being called in the ImportFileController. Commit

Changes to app/models/assignment_team.rb

 #  Change Rationale Commit Link
1 Renamed copy method for AssignmentTeam Renamed copy for copying current AssignmentTeam to CourseTeam as copy_to_course_team Commit
2 Added Import Functionality Refactored import method, added methods import_options, optional_import_fields, import_options which are being called in the ImportFileController to get required and optional fields from the respective model. Commit

Changes to app/models/team.rb

 #  Change Rationale Commit Link
1 Added Import Functionality Refactored import_team_members and added import_helper, that is used for importing CourseTeam and AssignmentTeam objects. Commit

CHANGES IN RSPEC FILES

Changes to spec/models/course_spec.rb

 #  Change Rationale Commit Link
1 Removed the test case for get_paprticipant method test case Removed the test case for get_participant method as the method was not used anywhere else in the code. Commit
2 Renamed copy_participants method test case Renamed the respective method of copy_participants to copy_assignment_participantsin rspec file as well. Commit

Changes to spec/models/course_team_spec.rb

 #  Change Rationale Commit Link
1 Renamed copy to copy_to_assignment_team Renamed copy to copy_to_assignment_teamin rspec file as well. Commit

Changes to spec/models/course_team_spec.rb

 #  Change Rationale Commit Link
1 Import functionality changes Test cases are added to rspec file as well for import functionality changes. Commit

Changes to spec/models/assignment_team_spec.rb

 #  Change Rationale Commit Link
1 Import functionality changes Test cases are added to rspec file as well for import functionality changes. Commit

Changes to spec/models/team_spec.rb

 #  Change Rationale Commit Link
1 Import functionality changes Test cases are added to rspec file as well for import functionality changes. Commit

CHANGES IN CONTROLLER FILES

Changes to app/controllers/teams_controller.rb

 #  Change Rationale Commit Link
1 Renamed copy to copy_to_assignment_team The change was directly related to changes of copy method in course_team.rb. Commit

Test Plan

Manual Testing

  • Adding Course Team member
    • Adding member student1922 to course CSC540
Add course member to team Radical
Add course member to team Radical
Succesffully added member to the team
Succesffully added member to the team
  • Importing Course Teams
    • Importing Course Teams
    • Import Preview
    • Import Error: We have refactored the import functionality according to E1923. The ImportFileController calls the import methods of the models course_team, assignment_team, team, etc. To debug this error, we need to change other models, such as assignment_participant, assignment_team, course_participant, metareview_response_map, question, review_response_map, sign_up_sheet, sign_up_topic, and user so that importing of all models would be generalised and would be functional. Some UI changes would be needed accordingly.
Import error
Import error

Automated Testing All the suggested changes were made to course.rb and course_team.rb, all these models were amended and as a result we need to update the tests. We added or amended tests in their respective .spec files. The methods were tested for edge cases and positive and negative test cases were written. The refactored methods were updated in the test cases.

  • course_team


Test passing for course_team.rb
Test passing for course_team.rb


  • course


Test passing for course_team.rb
Test passing for course_team.rb


  • assignment_team


Test passing for course_team.rb
Test passing for course_team.rb


  • team.rb


Test passing for course_team.rb
Test passing for course_team.rb


Coverage:

Before refactoring

Coverage of codebase before refactoring


Coverage of course_team.rb before refactoring


Coverage of course.rb before refactoring


Coverage of assignment_team.rb before refactoring


Coverage of team.rb before refactoring


After refactoring

Coverage of codebase after refactoring


Coverage of course_team.rb after refactoring


Coverage of course.rb after refactoring


Coverage of assignment_team.rb after refactoring


Coverage of team.rb after refactoring

Relevant Links

Contributors to this project

  • Kartik Rawool, (unityID:khrawool, GitHub:kartikrawool)
  • Ameya Vaichalkar, (unityID:agvaicha, GitHub:ameyagv)
  • Vikram Pande, (unityID:vspande, GitHub:vikrampande7)