CSC/ECE 517 Spring 2023 - E2312 + E2313. Reimplement response.rb and responses controller.rb

From Expertiza_Wiki
Jump to navigation Jump to search

In order to accommodate issues with another team, our team picked up another member and did both projects. The summaries of the projects are combined here to reflect that. Note that the requirements on the original projects are being treated more loosely to account for the additional work.

E2312 Reimplement Response

Summary of Changes

The previous version of response.rb was described as "a mess." The goal of E2312 was to reimplement it to follow better coding standards.

  • Made method names clearer, many method names were opaque and did not properly convey their functionality. For example, add_table_rows:

  • Moved many functionalities to mixins or helper classes to not violate the Single-Responsibility Principle (also many comments with no useful information)

  • Split the avg_scores_and_count_for_prev_reviews method into two separate methods
  • Implemented additional functionally

Functionality Moved

This section covers the functionality that was moved out of the response model.

Score Calculation

Score calculation is not inherently tied to the idea of a response. Any object with multiple scores could take advantage of a mixin that provided methods to do calculations on those scores. This created multiple responsibilities for the response object and encouraged non-DRY code. Functionality for calculating total, average, and maximum scores were all moved to a new Scorable mixin which can be leveraged by other models moving forward.

Previously that functionality was implemented directly on the response class:

Now it exists in a mixin, as demonstrated with this snippet:

Emails

The response model provided a method for creating emails. This was moved to a new MailMixin, which can be expanded to provide email functionality to more models in the future. This removed additional responsibilities to help maintain the Single Responsibility principle and helps move email-based code toward a more DRY implementation in the future.

Metrics

The response model provided a method for getting the volume of review comments on a response. This was moved to a ReviewCommentMixin as it is not necessarily specific to response models. This helps maintain the Single-Responsibility Principle for the response model.

Improved Naming

Fix instances of bad and opaque naming, like aggregate_question_score(), add_table_row(), and concatenate_all_review_comments() (which does more than the name implies).

Method Split

The method avg_scores_and_count_for_prev_reviews was split into two separate functions, prev_reviews_count and prev_reviews_avg_scores.

Additional Functionality

Two methods were added, get_latest_response and get_all_responses. These two methods both get responses made by a particular reviewer for a particular reviewee for an assignment. Get_latest_response returns the latest of the responses and get_all_responses returns all of the responses.

Test Plan

Many other parts of the software were stubbed out in the implementation project in order to run unit tests. The existing test suite was run against the implementation and passed successfully. Due to the fact that this project has no front end, the professor asked us to record a video of tests being run to demonstrate functionality, which is linked in the project submission.


Test cases:

  • Total score of a review
  • Average scores across a review when the maximum score is 0
  • Average scores across a review when the maximum score is not 0
  • Maximum scores for a response when there are no points available
  • Maximum scores for a response standard case
  • Volume of review comments
  • Concatenating all review comments

E2313 Reimplement Response Controller

Summary of Changes

The previous version of response_controller.rb was too long. It included too many functions besides the basic CRUD methods. The goal of E2313 was to reimplement it to follow better coding standards.

  • Made method name to follow plural convention not singular convention.
  • Moved many functionalities to mixins or helper classes

Functionality Moved

This section covers the functionality that was moved out of the responses controller.

Authentication and Authorization

There were authentication and authorization methods in the response controller. These were moved to authorization helper.

Redirect

There was a redirect function that helps redirect by params. It is moved to response helper.

Sort Reviews

There was functionality to sort reviews. We made a new function named sortReviews to perform this functionality and placed it in the response model

Singular convention to Plural convention

There were some function and classes that followed singular conventions, but were changed to follow plural convention.


Reducing code

There were multiple method invocations to set parameters (assign_action_parameters, set_content). We used the macro, before_action, so that we reduced the number of calls for these methods.

Testing

1. Response Deletion

- Verify that if the response is enabled for team reviewing, but lock is not existent, proceed to lock response
- Verify that if the response is not team review enabled, proceed to delete the response and redirect the user

2. Response Edit

- Verify preparing already existent response for editing purposes
- Verify creating new response if non-existent for editing purposes

3. Response Update

- Verify submitted response contains the new updated fields upon submission

4. Response New Feedback

- Redirect user to the new feedback page with relevant Response, Participant, and FeedbackResponseMap data
- If a review is not found, redirect user to the root path

5. Response Create

- If Response is found by query parameter, update with additional comments and instantiate answers
- If Response is not found by query parameter, create new Response instance with additional comments and instantiate answers

6. Response Save

- With the found ResponseMap, save with existing query parameters

7. Initialize Answers

- Verify answers are created from a passed-in list of questions

8. Questionnaire from Response Map

- Verify if current map type is ReviewResponseMap, set current round and questionnaire accordingly
- Verify if current map type is SelfReviewResponseMap, set current round and questionnaire accordingly
- Verify if current map type is MetareviewResponseMap, set questionnaire based on if assignment is duty based
- Verify if current map type is TeammateReviewResponseMap, set questionnaire based on if assignment is duty based
- Verify if current map type is FeedbackResponseMap, set questionnaire based on if assignment is duty based
- Verify if current map type is CourseSurveyResponseMap, set questionnaire based on if assignment is duty based
- Verify if current map type is AssignmentSurveyResponseMap, set questionnaire based on if assignment is duty based
- Verify if current map type is GlobalSurveyResponseMap, set questionnaire based on if assignment is duty based
- Verify if current map type is BookmarkRatingResponseMap, set questionnaire based on if assignment is duty based

9. Assign Action Parameters

- Verify when action is edit, header and next_action are assigned as "Edit" and "update" respectively
- Verify when action is new, header and next_action are assigned as "New" and "create" respectively

10. Setting Response

- Verify response and map instances are set based on the query parameter passed in

11. Toggling permission

- Verify a given response is found and its visibility attribute is toggled to its corresponding opposite value

12. Show Calibration Results for Student

- Verify with the given query parameters: assignment_id, calibration_response_map_id, review_response_map_id, that the assignment, calibration response, review response and questions instances are set correctly

13. Previous Review Count

- Verify that when given a list of reviews and the current review that the number of non current reviews is accurate

14. Previous Review Average Score

- Verify that when given a list of reviews and the current review that the average score of all non current reviews is accurate

15. Gets Latest Response by a Reviewer

- Verify that the latest response by a reviewer given the assignment, reviewer, and reviewee is accurate

16. Gets All Responses by a Reviewer

- Verify that all responses by a reviewer given the assignment, reviewer, and reviewee is accurate