CSC/ECE 517 Spring 2019 - E1919 CodeClimate Issues

From Expertiza_Wiki
Jump to navigation Jump to search

This wiki page is for the description of changes made according to the specification of E1919, OSS project.

Team Members

  • Rahul Sethi
  • Shraddha Bhadauria
  • Vijaya Ganesh Mohan

About Expertiza

Expertiza is a platform where assignments and related quizzes are managed. On this portal instructor upload assignments/questionnaires, create list of topics for students and edit the existing assignments. Students can form teams, work on projects and submit their assignments as URL or files. It also helps in improving the work quality by allowing students to provide anonymous reviews. It is an Open source platform which is based on Ruby with Rails.

Problem Statement

There were code smells detected in the application by code climate which violated the best practices of Ruby Rails. The goal was to fix those code smells by refactoring. Consider the following examples.

Add inverse_of option

File: Participant.rb belongs_to :topic, class_name: 'SignUpTopic'.

In the class 'SignUpTopic', we have has_many :teams

When you have two models in a has_many, has_one or belongs_to association, the :inverse_of option in Rails tells ActiveRecord that they're two sides of the same association. Knowing the other side of the same association Rails can optimize object loading and will reference the same object in memory, instead of loading another copy of the same record.

Add dependent property

In the file roles.rb we have has_many :users

We need to specify "dependent" option here.

With associations of Active Record , we can make transitions smooth of such operations(relationships) by telling Rails that there is a connection between the two models. It would make more sense here if we add "dependent :destroy" option for users. If a particular role is deleted, all the users under that role must also disappear.

dependent :destroy

useless assignment of a variable

In the file role.rb, we have

The variable e is not being used anywhere. Such values are assigned to "_" so that it doesnt get assigned to a variable and uses space.

rescue StandardError => _

Using snake case for method names

In file roles.rb, we have

A standard good practice is to follow snake cases for naming methods.

Use find_by instead of where.first

In file scored_question.rb, we have

Rails prefers "find_by" over "where" as "find_by" returns a single record as result, whereas "where" returns an array of record, to which we need to append "first" or "each" to get single record out of it.

<prev>answer = Answer.find_by(question_id: self.id, response_id: response_id) </prev>

And, there were many more code smells which needed a fix.

Files Modified for this requirement

  • app/models/http_request.rb
  • app/models/Import_error.rb
  • app/models/Institution.rb
  • app/models/Instructor.rb
  • app/models/Invitation.rb
  • app/models/Join_team_request.rb
  • app/models/Language.rb
  • app/models/Late_policy.rb
  • app/models/Logger_message.rb
  • app/models/Markup_style.rb
  • app/models/Menu_item.rb
  • app/models/Menu.rb
  • app/models/Metareview_questionnaire.rb
  • app/models/Metareview_response_map.rb
  • app/models/Missing_object_id_error.rb
  • app/models/Multiple_choice_checkbox.rb
  • app/models/Multiple_choice_radio.rb
  • app/models/Node.rb
  • app/models/Notification.rb
  • app/models/On_the_fly_calc.rb
  • app/models/Participant.rb
  • app/models/Password_reset.rb
  • app/models/Path_error.rb
  • app/models/Permission.rb
  • . app/models/Plagiarism_checker_assignment_submission.rb
  • app/models/Plagiarism_checker_comparison.rb
  • app/models/question_advice.rb  
  • app/models/Questionnaire_header.rb
  • app/models/Questionnaire_node.rb
  • app/models/Questionnaire.rb
  • app/models/Questionnaire_type_node.rb
  • app/models/Question.rb
  • app/models/Quiz_assignment.rb
  • app/models/Quiz_question_choice.rb
  • app/models/Quiz_questionnaire.rb
  • app/models/Quiz_question.rb
  • app/models/Quiz_response_map.rb
  • app/models/Quiz_response.rb
  • app/models/Requested_user.rb
  • app/models/Response_map.rb
  • app/models/Response.rb  
  • app/models/review_assignment.rb
  • app/models/Review_comment_paste_bin.rb
  • app/models/Review_grade.rb
  • app/models/Review_questionnaire.rb
  • app/models/Review_response_map.rb
  • app/models/Role.rb
  • app/models/Rscore.rb
  • app/models/rubric.rb  
  • app/models/Scale.rb
  • app/models/Scored_question.rb
  • app/models/Score_view.rb


Total Modifications

32 Files changed

168 additions

111 Deletions