CSC/ECE 517 Fall 2022 - E2255. Refactor review mapping helper.rb

From Expertiza_Wiki
Revision as of 02:23, 26 October 2022 by Zwang236 (talk | contribs)
Jump to navigation Jump to search

This page provides a description of the Expertiza based OSS project.



About Expertiza

Expertiza is an open-source project based on the Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams of Expertise to work on various projects and assignments. Students can also peer review other students' submissions. Expertise supports submission across various document types, including URLs and wiki pages.

Problem Statement

The following tasks were accomplished in this project:

  • Use Code Climate to do a diagnosis for Expertiza. Search for the issues involving the files mentioned above.
  • Fix all the methods having the issue with cyclomatic complexity, assignment branch condition size, extra commas, space or lack of it, and assigning branching condition.
  • Write test cases of any new code written. Test the existing functionality after refactoring

Problems and Solutions

  • Problem 1: Use Code Climate to do a diagnosis for Expertiza. Search for the issues involving the files mentioned above.
Example:

  • Problem 2: Fix all the methods having the issue with cyclomatic complexity, assignment branch condition size, extra commas, space or lack of it, and assigning branching condition.
Example: check_submission_state has Cyclomatic complexity 10 Maximum 5
 def check_submission_state(response_map, assignment_created, assignment_due_dates, round, color)
    if submitted_within_round?(round, response_map, assignment_created, assignment_due_dates)
      color.push 'purple'
    else
      link = submitted_hyperlink(round, response_map, assignment_created, assignment_due_dates)
      if link.nil? || (link !~ %r{https*:\/\/wiki(.*)}) # can be extended for github links in future
        color.push 'green'
      else
        link_updated_at = get_link_updated_at(link)
        color.push link_updated_since_last?(round, assignment_due_dates, link_updated_at) ? 'purple' : 'green'
      end
    end
 end
  • ::Solution: The problem is caused by nesting loops so we break it up
 def check_submission_state(response_map, assignment_created, assignment_due_dates, round, color)
    if submitted_within_round?(round, response_map, assignment_created, assignment_due_dates)
      color.push 'purple'
    return

    link = submitted_hyperlink(round, response_map, assignment_created, assignment_due_dates)
    if link.nil? || (link !~ %r{https*:\/\/wiki(.*)}) # Can be extended for github links in future
      color.push 'green'
      return

    link_updated_at = get_link_updated_at(link)
    color.push link_updated_since_last?(round, assignment_due_dates, link_updated_at) ? 'purple' : 'green'
  end
  • Problem 3: Write test cases of any new code written. Test the existing functionality after refactoring
Note: Due to the majority of the code already being refactored, Thus our team did not make any major changes to the review_mapping_helper.rb file. We did however use RSPEC to test all existing functions.
$ rspec spec/helpers/review_mapping_helper.rb