CSC/ECE 517 Spring 2022 - E2218: Refactor response controller

From Expertiza_Wiki
Jump to navigation Jump to search

This page details project documentation for the CSC/ECE 517 Spring 2022, E2218 refactor response_controller.rb project.


Background

A response is the object that is created when someone fills out a review rubric, such as when one writes a review, gives feedback to a reviewer, or fills out a survey. Responses to the individual rubric items are kept in Answer objects; each Answer object has a response_id to say what Response it is part of. Since response_controller needs to work with many kinds of responses, its code is pretty general. It is not the worst controller in the system, but it would be much clearer if its method names were more descriptive of what they do.

Mentor

Ed Gehringer, efg@ncsu.edu

Team Members

  • Sai Naga Vamshi Chidara (schidar@ncsu.edu)
  • Akhil Kumar Mengani (amengan@ncsu.edu)
  • Samson Reddy Mulkur (smulkur@ncsu.edu)

Modified Files and Refactorization

A. response_controller.rb

  authorize_show_calibration_results
  This method is used to authorize if the user(reviewer) is allowed to view the calibration results for the corresponding 
  calibration_response_map_id and review_response_map_id 
  passed as parameters in the URL.
  Ex: https://expertiza.ncsu.edu/response/show_calibration_results_for_student?calibration_response_map_id=165688&review_response_map_id=165790
  When someone tries to change the map_id's, the request should be authorized to check if the user can access the calibration result or not. 
  set_response
  @response and @map instance variables are initialized the same way across multiple methods.
  In order to avoid duplication, we created a before_action action which will be called first before calling the corresponding methods.
  


B. response_helper.rb

  Following methods are moved from the response_controller.rb class to response_helper.rb class since these methods are called from the 
  controller action methods.
   i) current_user_is_reviewer 
   ii) sort_questions
   iii) store_total_cake_score
   iv) set_content 
   

C. assignment_questionnaire.rb

  get_questions_by_assignment_id
  Parameters : assignment_id 
  When a user clicks on 'calibration results' from UI, questions in the assignment that has been reviewed are displayed.
  A new method is added in the AssignmentQuestionnaire model class that returns the appropriate questions by querying the 
  AssignmentQuestionnaire using the assignment_id.
  This method is added to separate the business logic of retrieving the questions from the controller class.
    
  

D. awarded_badge.rb

  award_badge
  Parameters :  participant_id, badge_name
  This method adds the badge_name to a specific participant_id in the AwardedBadges table. 
  A separate method is created in the AwardedBadges model class to avoid the controller class from knowing the business logic of adding a badge 
  name to a participant.
  
  
  
   

E. cake.rb

  store_total_cake_score
  This method clearly exposes the logic of retrieving the score for a cake question in the response_controller.rb class which is an incorrect 
  design.  
  So, a model class method get_total_score_for_questions is added and the same logic of iterating over the Cake questions is moved there.
  Return results for this method remains same here.
  

F. response.rb

  calibration_results_info
  This method in response.rb model is completely removed because this method only adds more complexity to the model class.
  We refactored the method show_calibration_results_for_student in the response_controller.rb class. 
  Previously, calibration_results_info was just doing nothing but getting responses using calibration_response_map_id and 
  review_response_map_id, and querying AssignmentQuestionnaire.
  Both of these operations can be done by using find method of model class and adding model class get_questions_by_assignment_id method.
  create_or_get_response
  Method name populate_new_response is changed to create_or_get_response to convey the functionality of the method.
    
  

G. Code Climate issues

  Update
  Made changes to split a line into multiple lines because it is too long.
  
  
  Create
  Made changes to split a line into multiple lines because it is too long.
  

Testing

Running Tests

  rspec spec/models/responses_spec.rb
  rspec spec/controllers/questionnaires_controller_spec.rb


UI Testing

1) Login using the following details. User Name: student432 Password: password

2) Click on the assignment Design Exercise pertaining to course CSC/ECE 517, Spring 2017

3) Click on other's work

4) Click on show calibration results, verify if the calibration results are displayed on the UI.

GitHub links and Pull Request

Link to Expertiza repository: here

Link to the forked repository: here

Link to Pull Request: here