CSC/ECE 517 Spring 2024 - E2408. Refactor course.rb and course team.rb models: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
(9 intermediate revisions by 3 users not shown)
Line 24: Line 24:


The following changes were made to the models course.rb and course_team.rb
The following changes were made to the models course.rb and course_team.rb
=== course.rb ===
=== Changes in course.rb ===
* The method get_participant was removed.
* '''Removal of get_participant Method'''
We performed a global search to see where all this method is being used. It was found that the function was not used anywhere else in the app and hence it was removed along with its respective rspec test.
        The method get_participant was removed.
* The method add_member was removed.
        A global search revealed it was unused throughout the app.
We found that add_member was present in the team class. Since Course_team is a subclass of Team it makes sense to leave the functionality in Team class itself to make the code more coherent and modular.
        Consequently, the method and its respective RSpec test were removed.
* Rename copy_participants.
After reading the function definition it made sense to rename the method to copy_assignment_participants since the method is specific to assignments. The new function name gives a better idea and clarity about what the function does.
* Improve error handling.
The methods add_participant and copy_assignment_participants were refactored to improve the error handling and code readability. We created a new method called "handle_errors" to raise any errors that the methods may encounter. This helped us to separate the error handling from the main function logic and made the code easier to understand.
* Others
Some other small changes were made such as using find_by instead of where.first to make SQL queries to the model, using "errors.any?" instead of unless "errors.empty?"  and adding comments to the code.


* '''Rename copy_participants Method'''
        Renamed the method to copy_assignment_participants.
        This new name accurately reflects the method's purpose, which is specific to assignments, enhancing clarity and understanding.
* '''Error Handling Enhancement'''
        Refactored add_participant and copy_assignment_participants methods for improved error handling and readability.
        Introduced a new method, handle_errors, to centralize error handling and separate it from main function logic.
* '''Other Changes'''
        Utilized find_by instead of where.first for SQL queries to the model.
        Employed errors.any? instead of unless errors.empty? for better readability.
        Added comments throughout the code for improved documentation and understanding.
=== Changes in course_team.rb  ===
* '''Removal of add_member method'''
        The method add_member was removed.
        As Course_team is a subclass of Team, it inherited the add_member functionality from the superclass. Hence, it was removed for better coherence and modularity.
* '''Removal of assignment_id method'''
        The method assignment_id was removed.
        The assignment_id method wasn't utilized anywhere in the code and therefore had to be removed to reduce redundancy.
* '''Refactoring Course.find(id) to Course.find(course_id)'''
        Any instances of Course.find(course_id) were replaced with Course.find(course_id) for better understandability of the code.
* '''Refactoring copy method to copy_to_assignment_team'''
        The copy method copied a Course team to an assignment team and thus refactored to copy_to_assigment_team making the code easy to understand.
* '''Refactoring the course_team.rb for importing and exporting csv files'''
        Refactored the course_team.rb file to adhere more closely to the Single Responsibility Principle (SRP).
        Removed the export and import methods from the model to create a more structured and uniform class.
* '''Creating "team_csv_handler" as a common mechanism for handling csv files'''
        We extracted the import and export functions into a new class named TeamCsvHandler.
        This new class is responsible solely for handling CSV operations related to teams, so that each class has a distinct reponsibility.
        Eliminated the need to duplicate code for exporting , importing and displaying the csv files in the model.


=== course_team.rb  ===
* Delete assignment_id method in CourseTeam class since it is no longer required.
* Refactor Course.find(id) to Course.find(course_id) for better understandability of the code.
* Refactor the copy method in CourseTeam class to something that better describes its functionality.


=== Other Changes ===
=== Other Changes ===


Fixed tests to incorporate the new changes in the code.
* The test corresponding to get_participant Method was removed from course_spec.rb
* The test corresponding to copy_participants Method was renamed to copy_assignment_participants.
 
== Testing ==
 
To validate the refactored models, we conducted UI testing. We mapped UI buttons and functionalities to their corresponding models and executed relevant tasks to verify the expected outcomes.
*'''Adding team members to a team'''
[[File:E2408 1.png|1000px|center|]]
 
[[File:E2408 2.png|1000px|center|]]
 
 
*'''Running RSpec Tests'''
 
[[File:E2408 3.png|1000px|center|]]


== Implementation ==
== Links ==
* '''GitHub Repo:''' https://github.com/dakshmehta23/expertiza
* '''Pull Request:''' https://github.com/expertiza/expertiza/pull/2752
* '''VCL URL:''' http://152.7.177.39:8080/

Latest revision as of 02:54, 25 March 2024

E2408. Refactor course.rb and course_team.rb models

Team

Members

  • Daksh Mehta, (unityID:dmehta4, GitHub:dakshmehta23)
  • Soham Patil, (unityID:sspatil6@ncsu.edu, GitHub:ThErOCk07)
  • Unnati Bukhariya, (unityID:ubukhar2@ncsu.edu, GitHub:unnzzz)

Mentor

  • Ameya Vaichalkar, (unityID:agvaicha, GitHub:ameyagv)

Expertiza Overview

Background

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. It is used in select courses at NC State and by professors at several other colleges and universities.

course.rb and course_team.rb models are objects containing information about the course and their associated teams respectively. CourseTeams are used when an instructor wants to use the same teams for the entire semester. CourseTeam is one subclass of Team ; AssignmentTeam is the other. An AssignmentTeam is a team that is created for students to do a single assignment. It is possible to copy CourseTeams to an assignment, where they become AssignmentTeams, or vice versa.

The Course and CourseTeam models had some code smells/issues that were fixed. There were a few methods in these models that shouldn’t be in those models, and a few methods that are no longer used. Certain method names were refactored in order to better understand their functionality.

Requirements

The following changes were made to the models course.rb and course_team.rb

Changes in course.rb

  • Removal of get_participant Method
       The method get_participant was removed.
       A global search revealed it was unused throughout the app.
       Consequently, the method and its respective RSpec test were removed.
  • Rename copy_participants Method
       Renamed the method to copy_assignment_participants.
       This new name accurately reflects the method's purpose, which is specific to assignments, enhancing clarity and understanding.
  • Error Handling Enhancement
       Refactored add_participant and copy_assignment_participants methods for improved error handling and readability.
       Introduced a new method, handle_errors, to centralize error handling and separate it from main function logic.
  • Other Changes
       Utilized find_by instead of where.first for SQL queries to the model.
       Employed errors.any? instead of unless errors.empty? for better readability.
       Added comments throughout the code for improved documentation and understanding.


Changes in course_team.rb

  • Removal of add_member method
       The method add_member was removed.
       As Course_team is a subclass of Team, it inherited the add_member functionality from the superclass. Hence, it was removed for better coherence and modularity.
  • Removal of assignment_id method
       The method assignment_id was removed.
       The assignment_id method wasn't utilized anywhere in the code and therefore had to be removed to reduce redundancy.
  • Refactoring Course.find(id) to Course.find(course_id)
       Any instances of Course.find(course_id) were replaced with Course.find(course_id) for better understandability of the code.
  • Refactoring copy method to copy_to_assignment_team
       The copy method copied a Course team to an assignment team and thus refactored to copy_to_assigment_team making the code easy to understand.
  • Refactoring the course_team.rb for importing and exporting csv files
       Refactored the course_team.rb file to adhere more closely to the Single Responsibility Principle (SRP). 
       Removed the export and import methods from the model to create a more structured and uniform class.
  • Creating "team_csv_handler" as a common mechanism for handling csv files
       We extracted the import and export functions into a new class named TeamCsvHandler.
       This new class is responsible solely for handling CSV operations related to teams, so that each class has a distinct reponsibility.
       Eliminated the need to duplicate code for exporting , importing and displaying the csv files in the model.


Other Changes

  • The test corresponding to get_participant Method was removed from course_spec.rb
  • The test corresponding to copy_participants Method was renamed to copy_assignment_participants.

Testing

To validate the refactored models, we conducted UI testing. We mapped UI buttons and functionalities to their corresponding models and executed relevant tasks to verify the expected outcomes.

  • Adding team members to a team


  • Running RSpec Tests

Links