CSC/ECE 517 Sping 2023 - E2322: Refactor Questionnaire View to display Bookmark Rating

From Expertiza_Wiki
Jump to navigation Jump to search

Expertiza

Expertiza is a Ruby on Rails based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on a different projects and assignments and submit their work. They can also review other students' submissions.

Questionnaires Controller

Questionnaire is the superclass for all types of questionnaires and rubrics. We can create, display, and manage questionnaires using this controller. Expertiza allows users to create a variety of questionnaires, including reviews, metareviews, teammate reviews, assignments, global surveys, course surveys, and bookmark ratings.

Problem Statement

The following tasks were accomplished in this project:

  • Refactoring the methods doing multiple tasks and breaking them in different modules.
  • Refactoring duplicate code into a single method.
  • Add comments to methods and complex lines of code.
  • Removing code that is no longer being used or required
  • Try to fix issues from Code Climate.

Files Modified

Below are the files we changed as part of refactoring

Bookmarks Controller

This is the bookmarks_controller.rb which handles all the CRUD operation performed on bookmarks. Multiple things were done in just one method which we broke in modules doing that specific task. We have the same code repeating in multiple places which we moved into a single method.

Questionnaire Node

In the file app/models/questionnaire_node.rb which deals with the attributes of quesstionnaire.

Questionnaire Type Node

In the file app/models/questionnaire_type_node.rb which handles and defines the structure of the questionnaire Node template.

Refactoring

Refactor Bookmark Controller

The file that is no longer being used in project and was written long ago to add bookmark functionality can be considered as "dead code". And the bookmark functionality that was originally implemented in this file has been moved to another file in the project, making the original file redundant. To address this issue, the dead code in the form of the original file can be safely removed from the project.

By removing this unused code, we can simplify the codebase and improve the maintainability of the application, as well as potentially reduce the size of the project and improve its performance.

Refactor Questionnaire Type Node

The file questionnaire_type_node.rb serves as a template for all the questionnaire nodes which handles the folders list of questionnaires of various types. we have refactored by creating a helper method for the return_nodes_list, which returns a list of folder nodes for the corresponding list of folders.

Refactor Questionnaire Node

The file questionnaire_node.rb deals with the attributes associated with questionnaire. This refactored code uses a single method get_attr that takes the name of the attribute as an argument and retrieves it. Then, each of the get_* methods simply calls get_attr with the appropriate attribute name. This eliminates the duplication in the original code and makes it easier to maintain if changes need to be made.

Design Pattern

The DRY pattern is used during refactoring to extract common functionality into reusable functions or methods. For example, if a section of code is repeated in multiple places, it can be extracted into a reusable function or method that can be called from those places instead. This not only reduces duplication but also makes the code easier to read and maintain.

We implemented the Dry design pattern to remove redundant code in questionnaire_node.rb and questionnaire_type_node.rb and removed the dead code in bookmark_controller.rb.

Testing Plan

Testing From UI

  • View Bookmark Rating Before creation
  1. After logging in as instructor, go to Manage > Questionnaires.
  2. Initially there will be no bookmarks rating.
  3. Click on the Bookmark Rating, there wont be a dropdown as there are no ratings.
  • Create new Bookmark Rating
  1. As an instructor, go to Manage > Questionnaires,
  2. In bookmark Rating field, click on plus button.
  3. Create a new Bookmark Rating with required details.
  4. After creating Bookmark Rating, Start adding questions.
  • View Bookmark Rating After creation
  1. After logging in as instructor, go to Manage > Questionnaires.
  2. Click on the Bookmark Rating, there will be a dropdown with list of Bookmark Ratings.

Automated Testing with RSpec

For most of our changes we did not have to create new test cases or modified exiting test cases for all the functionalities that we have been modifying. After refactoring we run the test cases in respective files.

Below is the screenshot of the result after running the test cases.

Team

Mentor
  • Kartiki Bhandakkar
  • Divyang Doshi
Members
  • Mithila Reddy Tatigotla, mtatigo
  • Vineeth Dasi, vdasi
  • Kalyan Karnati, kkarnat

References

  1. Expertiza
  2. Expertiza GitHub
  3. Pull Request to Merge
  4. Deployed Changes Userid - instructor6 and Password - password
  5. GitHub Project Board