CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller

From Expertiza_Wiki
Jump to navigation Jump to search

About Expertiza

Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is Expertiza.

E2215. Refactoring student_quizzes_controller.rb in Expertiza

This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.

Controller Description

The student_quizzes_controller consists of methods involved in creating, scoring & recording responses of the quizzes taken by reviewers or students of the other teams with the same assignment. This controller has some issues that violate essential Rails design principles such as DRY principle. There are few methods in this controller that should have been in model classes. Some methods share code, which creates code repetition. Some method comments needs to be rewritten.

Files Modified

1. student_quizzes_controller.rb
2. finished_quiz.html

Modifications made to the existing code

1. Modification - Add comments for custom method in this controller explaining the purpose.
2. Modification - Line 24 - Shouldn’t .first really be .last? If someone took the quiz multiple times, we wouldn’t want to count the first score.
3. Modification - Change the variables like @map on line 28 and use names which are intuitive for the purpose it serves
4. Modification - Line 28 - Shouldn’t @participant be @quiz_taker? Also, this line of code seems to assume that only one person is on the team. I think that’s the team that took the quiz, but is it perhaps the team whose quiz was taken? This is not clear.
5. Modification - Line 34 - For self.take_quiz, if the method comment is correct, the name of the method should be changed to something relating to what it does. Something like create_quiz. However, what it does is not particularly clear.
6. Modification - calculate_score should be a model method, not a controller method. It has so much in common with calculating the score of other rubrics that the code should not be duplicated and separate methods for duplicated code should be generated.
7. Modification - Line 98 - record_response needs a method comment.
8. Modification - Line 108 calls the calculate_score method, which is going to change to something else in a current refactoring.
9. Modification - Line 110 - Fix the English in the message (no run-on sentence, what does “records” mean, etc.)
10. Modification - Line 119 - If the method is only for quiz_questionnaires, then why isn’t it in quiz_questionnaire.rb?? Method comment on review_questions does not say what the method does. Write a comment explaining how the method achieves the task instead of what task it achieves.

Tests on the Controller Methods

Video on changes made