<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aankara</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aankara"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Aankara"/>
	<updated>2026-09-08T22:20:42Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98520</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98520"/>
		<updated>2015-11-06T23:04:59Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Refactoring of metareview_response_maps method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.  Prior to refactoring, all null checks were performed within the import method.   After refactoring, the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that any existing functionality did not break. &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Before refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def self.import(row, session, id)&lt;br /&gt;
    if row.length &amp;lt; 2&lt;br /&gt;
      raise ArgumentError, &amp;quot;Not enough items&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    assignment = Assignment.find(id)&lt;br /&gt;
    if assignment.nil?&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    index = 1&lt;br /&gt;
    while index &amp;lt; row.length&lt;br /&gt;
      user = User.find_by_name(row[index].to_s.strip)&lt;br /&gt;
      if user.nil?&lt;br /&gt;
        raise ImportError, &amp;quot;The user account for the reviewer \&amp;quot;#{row[index]}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: user.id, parent_id:  assignment.id).first&lt;br /&gt;
      if reviewer == nil&lt;br /&gt;
        raise ImportError, &amp;quot;The reviewer \&amp;quot;#{row[index]}\&amp;quot; is not a participant in this assignment. &amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if assignment.team_assignment&lt;br /&gt;
        reviewee = AssignmentTeam.where(name: row[0].to_s.strip, parent_id:  assignment.id).first&lt;br /&gt;
        if reviewee == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The author \&amp;quot;#{row[0].to_s.strip}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        existing = ReviewResponseMap.where(reviewee_id: reviewee.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
        if existing.nil?&lt;br /&gt;
          ReviewResponseMap.create(:reviewer_id =&amp;gt; reviewer.id, :reviewee_id =&amp;gt; reviewee.id, :reviewed_object_id =&amp;gt; assignment.id)&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        puser = User.find_by_name(row[0].to_s.strip)&lt;br /&gt;
        if user == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The user account for the reviewee \&amp;quot;#{row[0]}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        reviewee = AssignmentParticipant.where(user_id: puser.id, parent_id:  assignment.id).first&lt;br /&gt;
        if reviewee == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The author \&amp;quot;#{row[0].to_s.strip}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        team_id = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
        existing = ReviewResponseMap.where(reviewee_id: team_id, reviewer_id:  reviewer.id).first&lt;br /&gt;
        if existing.nil?&lt;br /&gt;
          ReviewResponseMap.create(:reviewee_id =&amp;gt; team_id, :reviewer_id =&amp;gt; reviewer.id, :reviewed_object_id =&amp;gt; assignment.id)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      index += 1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality.  This is why it was renamed to get_team_responses_for_round, the new name of the method provides a clearer idea of its purpose. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  We also removed the return statement at the end of the method.  &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Before refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_assessments_round_for(team,round)&lt;br /&gt;
    team_id =team.id&lt;br /&gt;
    responses = Array.new&lt;br /&gt;
    if team_id&lt;br /&gt;
      maps = ResponseMap.where(:reviewee_id =&amp;gt; team_id, :type =&amp;gt; &amp;quot;ReviewResponseMap&amp;quot;)&lt;br /&gt;
      maps.each{ |map|&lt;br /&gt;
        if !map.response.empty? &amp;amp;&amp;amp; !map.response.reject{|r| r.round!=round}.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject{|r| r.round!=round}.last&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      responses.sort! {|a,b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    return responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # return the responses for specified round,&lt;br /&gt;
  # for varying rubric feature -Yang&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:    &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  assessments = ReviewResponseMap.get_assessments_round_for(team,i)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt; &lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 scores[questionnaire_symbol][:assessments] = questionnaire.get_assessments_round_for(self,round)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of metareview_response_maps method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex.  It contained an unneeded private variable and an unnecessary nested loop.  Originally, it added each metareview map individually in the nested loop.  We decided to remove the nested loop and use the concat method for readability and maintainability.  These changes allowed us to remove the private variable &amp;quot;metareview_list&amp;quot; and only maintain the &amp;quot;metareview_response_maps&amp;quot; variable.  We also renamed the metareview_response_maps method to get_metareview_response_maps method to be more descriptive about the intent of the method. &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Before refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id:self.id)&lt;br /&gt;
    metareview_list=[]&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps = MetareviewResponseMap.where(reviewed_object_id:response.id)&lt;br /&gt;
      metareview_response_maps.each do |metareview_response_map|&lt;br /&gt;
        metareview_list&amp;lt;&amp;lt;metareview_response_map&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    metareview_list&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Returns the response maps for all the metareviews&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps.concat MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The change from this renaming also requires changes in the following files:&lt;br /&gt;
app/models/assignment.rb:361:   &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 response_map_set.sort! { |a, b| a.metareview_response_maps.count &amp;lt;=&amp;gt; b.metareview_response_maps.count }&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
app/models/assignment.rb:362:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 min_metareviews = response_map_set.first.metareview_response_maps.count&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
app/ models/assignment.rb:363:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 response_map_set.reject! { |response_map| response_map.metareview_response_maps.count &amp;gt; min_metareviews }&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
app/models/assignment.rb:377:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 response_map_set.sort! { |a, b| a.metareview_response_maps.count &amp;lt;=&amp;gt; b.metareview_response_maps.count }&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
app/models/assignment.rb:378:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 min_metareviews = response_map_set.first.metareview_response_maps.count&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
app/models/assignment.rb:379:   &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 response_map_set.sort! { |a, b| a.metareview_response_maps.last.id &amp;lt;=&amp;gt; b.metareview_response_maps.last.id } if min_metareviews &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
app/models/assignment_participant.rb:73:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 self.response_maps.metareview_response_maps.each do |metaresponse_map|&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
app/models/response.rb:4:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 has_many :metareview_response_maps, :class_name =&amp;gt; 'MetareviewResponseMap', :foreign_key =&amp;gt; 'reviewed_object_id', dependent: :destroy&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of export method ===&lt;br /&gt;
The export method contained mappings.sort! { |a, b| a.reviewee.name &amp;lt;=&amp;gt; b.reviewee.name }.  We could not get past this when running tests, we kept getting a message saying, &amp;quot;sort! was not a method for an ActiveRecord_Relation&amp;quot;.  But, ActiveRecord_Relation does allow the use of sort.  So we changed that line of code to  mappings = mappings.sort { |a, b| a.reviewee.name &amp;lt;=&amp;gt; b.reviewee.name }&lt;br /&gt;
&lt;br /&gt;
Before refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.export(csv, parent_id, options)&lt;br /&gt;
    mappings = where(reviewed_object_id: parent_id)&lt;br /&gt;
    mappings.sort! { |a, b| a.reviewee.name &amp;lt;=&amp;gt; b.reviewee.name }&lt;br /&gt;
    mappings.each {&lt;br /&gt;
      |map|&lt;br /&gt;
      csv &amp;lt;&amp;lt; [&lt;br /&gt;
        map.reviewee.name,&lt;br /&gt;
        map.reviewer.name&lt;br /&gt;
      ]&lt;br /&gt;
    }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # options parameter used as a signature in other models&lt;br /&gt;
  def self.export(csv, parent_id, options)&lt;br /&gt;
    mappings = where(reviewed_object_id: parent_id)&lt;br /&gt;
    mappings = mappings.sort { |a, b| a.reviewee.name &amp;lt;=&amp;gt; b.reviewee.name }&lt;br /&gt;
    mappings.each do&lt;br /&gt;
    |map|&lt;br /&gt;
      csv &amp;lt;&amp;lt; [map.reviewee.name, map.reviewer.name]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of final_versions_from_reviewer method ===&lt;br /&gt;
The final_versions_from_reviewer method was too long and repetitive.  We removed common functionality from within the if and else statement and put it in a private method final_versions_from_reviewer.  Then we created the get_responses method to find the responses based on the arguments values.  These private methods make the class more readable for other programmers.&lt;br /&gt;
 &lt;br /&gt;
Before refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.final_versions_from_reviewer(reviewer_id)&lt;br /&gt;
    maps = ReviewResponseMap.where(reviewer_id: reviewer_id)&lt;br /&gt;
    assignment = Assignment.find(Participant.find(reviewer_id).parent_id)&lt;br /&gt;
    review_final_versions = Hash.new&lt;br /&gt;
    if !assignment.varying_rubrics_by_round?&lt;br /&gt;
      #same review rubric used in multiple rounds&lt;br /&gt;
      review_final_versions[:review] = Hash.new&lt;br /&gt;
      review_final_versions[:review][:questionnaire_id] = assignment.get_review_questionnaire_id&lt;br /&gt;
      response_ids = Array.new&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        responses = Response.where(map_id:map.id)&lt;br /&gt;
        if !responses.empty?&lt;br /&gt;
          response_ids &amp;lt;&amp;lt; responses.last.id&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      review_final_versions[:review][:response_ids] = response_ids&lt;br /&gt;
    else&lt;br /&gt;
      #vary rubric by round&lt;br /&gt;
      rounds_num = assignment.rounds_of_reviews&lt;br /&gt;
      for round in 1..rounds_num&lt;br /&gt;
        symbol = (&amp;quot;review round&amp;quot;+round.to_s).to_sym&lt;br /&gt;
        review_final_versions[symbol] = Hash.new&lt;br /&gt;
        review_final_versions[symbol][:questionnaire_id] = assignment.get_review_questionnaire_id(round)&lt;br /&gt;
        response_ids = Array.new&lt;br /&gt;
        maps.each do |map|&lt;br /&gt;
          responses = Response.where(map_id:map.id, round:round)&lt;br /&gt;
          if !responses.empty?&lt;br /&gt;
            response_ids &amp;lt;&amp;lt; responses.last.id&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        review_final_versions[symbol][:response_ids] = response_ids&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    review_final_versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # wrap The latest version of responses in each response map,&lt;br /&gt;
  # together with the questionnaire_id will be used to&lt;br /&gt;
  # display the reviewer summary&lt;br /&gt;
  def self.final_versions_from_reviewer(reviewer_id)&lt;br /&gt;
    maps = ReviewResponseMap.where(reviewer_id: reviewer_id)&lt;br /&gt;
    assignment = find_assignment(Participant.find(reviewer_id).parent_id)&lt;br /&gt;
    review_final_versions = {}&lt;br /&gt;
    unless assignment.varying_rubrics_by_round?&lt;br /&gt;
      #same review rubric used in multiple rounds&lt;br /&gt;
      review_final_versions = review_final_version_responses(:review, :questionnaire_id, assignment, maps)&lt;br /&gt;
    else&lt;br /&gt;
      # vary rubric by round&lt;br /&gt;
      rounds_num = assignment.rounds_of_reviews&lt;br /&gt;
      (1..rounds_num).each do |round|&lt;br /&gt;
        symbol = ('review round' + round.to_s).to_sym&lt;br /&gt;
        review_final_versions = review_final_version_responses(symbol, :questionnaire_id, assignment, maps, round)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    review_final_versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Compute list of responses and return it&lt;br /&gt;
  def self.review_final_version_responses(symbol, questionnaire_id, assignment, maps, round = nil)&lt;br /&gt;
    review_final_versions = {}&lt;br /&gt;
    review_final_versions[symbol] = {}&lt;br /&gt;
    review_final_versions[symbol][questionnaire_id] = assignment.get_review_questionnaire_id(round)&lt;br /&gt;
    response_ids = []&lt;br /&gt;
    maps.each do |map|&lt;br /&gt;
      responses =  get_responses(map.id, round)&lt;br /&gt;
      unless responses.empty?&lt;br /&gt;
        response_ids &amp;lt;&amp;lt; responses.last.id&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    review_final_versions[symbol][:response_ids] = response_ids&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  #Get responses by map_id and round (if exists)&lt;br /&gt;
  def self.get_responses(id, round)&lt;br /&gt;
     if round.nil?&lt;br /&gt;
       responses = Response.where(map_id: id)&lt;br /&gt;
     else&lt;br /&gt;
       responses = Response.where(map_id: id, round: round)&lt;br /&gt;
     end	&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of other methods ===&lt;br /&gt;
We removed the return statement from the get_title, export_fields, and show_feedback methods because return statements are unnecessary in Ruby.&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
=== Code Improvements ===&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot internal functionality. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focused on refactoring the existing model, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
The previous unit tests had syntactical and run time errors.  We were not able to get the previous unit tests to run without errors.  Because of this we rewrote all of the unit tests for the &amp;lt;b&amp;gt;ReviewResponseModel&amp;lt;/b&amp;gt;.  It is important to have working unit tests so that when internal changes are made to functions the external output remains the same.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of Unit Tests===&lt;br /&gt;
&lt;br /&gt;
We added a test_helper file to the main test folder that requires a needed configuration file and needed gems.  We also added 8 fixtures that were needed for data to run the unit tests.  The following fixture files were added:&lt;br /&gt;
&lt;br /&gt;
* assignment_questionnaires.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* questionnaires.yml&lt;br /&gt;
* response_maps.yml&lt;br /&gt;
* responses.yml&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There is at least one unit test for every public method within the &amp;lt;b&amp;gt;ReviewResponseModel&amp;lt;/b&amp;gt;.  The test naming convention used is &amp;quot;method_&amp;lt;name of method that is being tested&amp;gt;&amp;quot;.  For example, the unit test for the export method is &amp;quot;method_export&amp;quot;.  If there are multiple test for one method the name of the test will include the test case after the normal naming convention.  For example, one of the unit tests for the import method checks for an invalid assignment.  The name of this method is &amp;quot;method_import_invalid_assignment&amp;quot;.  The following are the unit tests we created:&lt;br /&gt;
&lt;br /&gt;
* method_export&lt;br /&gt;
* method_get_metareview_response_maps&lt;br /&gt;
* method_get_team_response_for_round&lt;br /&gt;
* method_final_versions_from_reviewer&lt;br /&gt;
* method_import&lt;br /&gt;
* method_import_invalid_reviewee&lt;br /&gt;
* method_import_invalid_reviewer&lt;br /&gt;
* method_import_invalid_assignment&lt;br /&gt;
* method_delete&lt;br /&gt;
* method_delete_no _force&lt;br /&gt;
* method_show_feedback&lt;br /&gt;
* method_get_title&lt;br /&gt;
* method_export_fields&lt;br /&gt;
* method_questionnaire&lt;br /&gt;
* method_add_reviewer&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== How to Run Unit Tests ===&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up [[ http://152.46.16.195:5902/ | Expertiza]] and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= External Links =&lt;br /&gt;
&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
# [http://152.46.16.195:5902/ Expertiza Deployed Site]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98517</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98517"/>
		<updated>2015-11-06T23:03:05Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Refactoring of metareview_response_maps method */ changed formatting of method used in other files&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.  Prior to refactoring, all null checks were performed within the import method.   After refactoring, the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that any existing functionality did not break. &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Before refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def self.import(row, session, id)&lt;br /&gt;
    if row.length &amp;lt; 2&lt;br /&gt;
      raise ArgumentError, &amp;quot;Not enough items&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    assignment = Assignment.find(id)&lt;br /&gt;
    if assignment.nil?&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    index = 1&lt;br /&gt;
    while index &amp;lt; row.length&lt;br /&gt;
      user = User.find_by_name(row[index].to_s.strip)&lt;br /&gt;
      if user.nil?&lt;br /&gt;
        raise ImportError, &amp;quot;The user account for the reviewer \&amp;quot;#{row[index]}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: user.id, parent_id:  assignment.id).first&lt;br /&gt;
      if reviewer == nil&lt;br /&gt;
        raise ImportError, &amp;quot;The reviewer \&amp;quot;#{row[index]}\&amp;quot; is not a participant in this assignment. &amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if assignment.team_assignment&lt;br /&gt;
        reviewee = AssignmentTeam.where(name: row[0].to_s.strip, parent_id:  assignment.id).first&lt;br /&gt;
        if reviewee == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The author \&amp;quot;#{row[0].to_s.strip}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        existing = ReviewResponseMap.where(reviewee_id: reviewee.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
        if existing.nil?&lt;br /&gt;
          ReviewResponseMap.create(:reviewer_id =&amp;gt; reviewer.id, :reviewee_id =&amp;gt; reviewee.id, :reviewed_object_id =&amp;gt; assignment.id)&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        puser = User.find_by_name(row[0].to_s.strip)&lt;br /&gt;
        if user == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The user account for the reviewee \&amp;quot;#{row[0]}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        reviewee = AssignmentParticipant.where(user_id: puser.id, parent_id:  assignment.id).first&lt;br /&gt;
        if reviewee == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The author \&amp;quot;#{row[0].to_s.strip}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        team_id = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
        existing = ReviewResponseMap.where(reviewee_id: team_id, reviewer_id:  reviewer.id).first&lt;br /&gt;
        if existing.nil?&lt;br /&gt;
          ReviewResponseMap.create(:reviewee_id =&amp;gt; team_id, :reviewer_id =&amp;gt; reviewer.id, :reviewed_object_id =&amp;gt; assignment.id)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      index += 1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality.  This is why it was renamed to get_team_responses_for_round, the new name of the method provides a clearer idea of its purpose. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  We also removed the return statement at the end of the method.  &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Before refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_assessments_round_for(team,round)&lt;br /&gt;
    team_id =team.id&lt;br /&gt;
    responses = Array.new&lt;br /&gt;
    if team_id&lt;br /&gt;
      maps = ResponseMap.where(:reviewee_id =&amp;gt; team_id, :type =&amp;gt; &amp;quot;ReviewResponseMap&amp;quot;)&lt;br /&gt;
      maps.each{ |map|&lt;br /&gt;
        if !map.response.empty? &amp;amp;&amp;amp; !map.response.reject{|r| r.round!=round}.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject{|r| r.round!=round}.last&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      responses.sort! {|a,b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    return responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # return the responses for specified round,&lt;br /&gt;
  # for varying rubric feature -Yang&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:    &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  assessments = ReviewResponseMap.get_assessments_round_for(team,i)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt; &lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 scores[questionnaire_symbol][:assessments] = questionnaire.get_assessments_round_for(self,round)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of metareview_response_maps method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex.  It contained an unneeded private variable and an unnecessary nested loop.  Originally, it added each metareview map individually in the nested loop.  We decided to remove the nested loop and use the concat method for readability and maintainability.  These changes allowed us to remove the private variable &amp;quot;metareview_list&amp;quot; and only maintain the &amp;quot;metareview_response_maps&amp;quot; variable.  We also renamed the metareview_response_maps method to get_metareview_response_maps method to be more descriptive about the intent of the method. &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Before refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id:self.id)&lt;br /&gt;
    metareview_list=[]&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps = MetareviewResponseMap.where(reviewed_object_id:response.id)&lt;br /&gt;
      metareview_response_maps.each do |metareview_response_map|&lt;br /&gt;
        metareview_list&amp;lt;&amp;lt;metareview_response_map&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    metareview_list&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Returns the response maps for all the metareviews&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps.concat MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The change from this renaming also requires changes in the following files:&lt;br /&gt;
app/models/assignment.rb:361:   &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 response_map_set.sort! { |a, b| a.metareview_response_maps.count &amp;lt;=&amp;gt; b.metareview_response_maps.count }&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
app/models/assignment.rb:362:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 min_metareviews = response_map_set.first.metareview_response_maps.count&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
app/ models/assignment.rb:363:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 response_map_set.reject! { |response_map| response_map.metareview_response_maps.count &amp;gt; min_metareviews }&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
app/models/assignment.rb:377:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 response_map_set.sort! { |a, b| a.metareview_response_maps.count &amp;lt;=&amp;gt; b.metareview_response_maps.count }&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
app/models/assignment.rb:378:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 min_metareviews = response_map_set.first.metareview_response_maps.count&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
app/models/assignment.rb:379:   &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 response_map_set.sort! { |a, b| a.metareview_response_maps.last.id &amp;lt;=&amp;gt; b.metareview_response_maps.last.id } if min_metareviews &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
app/models/assignment_participant.rb:73:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 self.response_maps.metareview_response_maps.each do |metaresponse_map|&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
app/models/response.rb:4:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 has_many :metareview_response_maps, :class_name =&amp;gt; 'MetareviewResponseMap', :foreign_key =&amp;gt; 'reviewed_object_id', dependent: :destroy&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of export method ===&lt;br /&gt;
The export method contained mappings.sort! { |a, b| a.reviewee.name &amp;lt;=&amp;gt; b.reviewee.name }.  We could not get past this when running tests, we kept getting a message saying, &amp;quot;sort! was not a method for an ActiveRecord_Relation&amp;quot;.  But, ActiveRecord_Relation does allow the use of sort.  So we changed that line of code to  mappings = mappings.sort { |a, b| a.reviewee.name &amp;lt;=&amp;gt; b.reviewee.name }&lt;br /&gt;
&lt;br /&gt;
Before refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.export(csv, parent_id, options)&lt;br /&gt;
    mappings = where(reviewed_object_id: parent_id)&lt;br /&gt;
    mappings.sort! { |a, b| a.reviewee.name &amp;lt;=&amp;gt; b.reviewee.name }&lt;br /&gt;
    mappings.each {&lt;br /&gt;
      |map|&lt;br /&gt;
      csv &amp;lt;&amp;lt; [&lt;br /&gt;
        map.reviewee.name,&lt;br /&gt;
        map.reviewer.name&lt;br /&gt;
      ]&lt;br /&gt;
    }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # options parameter used as a signature in other models&lt;br /&gt;
  def self.export(csv, parent_id, options)&lt;br /&gt;
    mappings = where(reviewed_object_id: parent_id)&lt;br /&gt;
    mappings = mappings.sort { |a, b| a.reviewee.name &amp;lt;=&amp;gt; b.reviewee.name }&lt;br /&gt;
    mappings.each do&lt;br /&gt;
    |map|&lt;br /&gt;
      csv &amp;lt;&amp;lt; [map.reviewee.name, map.reviewer.name]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of final_versions_from_reviewer method ===&lt;br /&gt;
The final_versions_from_reviewer method was too long and repetitive.  We removed common functionality from within the if and else statement and put it in a private method final_versions_from_reviewer.  Then we created the get_responses method to find the responses based on the arguments values.  These private methods make the class more readable for other programmers.&lt;br /&gt;
 &lt;br /&gt;
Before refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.final_versions_from_reviewer(reviewer_id)&lt;br /&gt;
    maps = ReviewResponseMap.where(reviewer_id: reviewer_id)&lt;br /&gt;
    assignment = Assignment.find(Participant.find(reviewer_id).parent_id)&lt;br /&gt;
    review_final_versions = Hash.new&lt;br /&gt;
    if !assignment.varying_rubrics_by_round?&lt;br /&gt;
      #same review rubric used in multiple rounds&lt;br /&gt;
      review_final_versions[:review] = Hash.new&lt;br /&gt;
      review_final_versions[:review][:questionnaire_id] = assignment.get_review_questionnaire_id&lt;br /&gt;
      response_ids = Array.new&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        responses = Response.where(map_id:map.id)&lt;br /&gt;
        if !responses.empty?&lt;br /&gt;
          response_ids &amp;lt;&amp;lt; responses.last.id&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      review_final_versions[:review][:response_ids] = response_ids&lt;br /&gt;
    else&lt;br /&gt;
      #vary rubric by round&lt;br /&gt;
      rounds_num = assignment.rounds_of_reviews&lt;br /&gt;
      for round in 1..rounds_num&lt;br /&gt;
        symbol = (&amp;quot;review round&amp;quot;+round.to_s).to_sym&lt;br /&gt;
        review_final_versions[symbol] = Hash.new&lt;br /&gt;
        review_final_versions[symbol][:questionnaire_id] = assignment.get_review_questionnaire_id(round)&lt;br /&gt;
        response_ids = Array.new&lt;br /&gt;
        maps.each do |map|&lt;br /&gt;
          responses = Response.where(map_id:map.id, round:round)&lt;br /&gt;
          if !responses.empty?&lt;br /&gt;
            response_ids &amp;lt;&amp;lt; responses.last.id&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        review_final_versions[symbol][:response_ids] = response_ids&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    review_final_versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # wrap The latest version of responses in each response map,&lt;br /&gt;
  # together with the questionnaire_id will be used to&lt;br /&gt;
  # display the reviewer summary&lt;br /&gt;
  def self.final_versions_from_reviewer(reviewer_id)&lt;br /&gt;
    maps = ReviewResponseMap.where(reviewer_id: reviewer_id)&lt;br /&gt;
    assignment = find_assignment(Participant.find(reviewer_id).parent_id)&lt;br /&gt;
    review_final_versions = {}&lt;br /&gt;
    unless assignment.varying_rubrics_by_round?&lt;br /&gt;
      #same review rubric used in multiple rounds&lt;br /&gt;
      review_final_versions = review_final_version_responses(:review, :questionnaire_id, assignment, maps)&lt;br /&gt;
    else&lt;br /&gt;
      # vary rubric by round&lt;br /&gt;
      rounds_num = assignment.rounds_of_reviews&lt;br /&gt;
      (1..rounds_num).each do |round|&lt;br /&gt;
        symbol = ('review round' + round.to_s).to_sym&lt;br /&gt;
        review_final_versions = review_final_version_responses(symbol, :questionnaire_id, assignment, maps, round)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    review_final_versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Compute list of responses and return it&lt;br /&gt;
  def self.review_final_version_responses(symbol, questionnaire_id, assignment, maps, round = nil)&lt;br /&gt;
    review_final_versions = {}&lt;br /&gt;
    review_final_versions[symbol] = {}&lt;br /&gt;
    review_final_versions[symbol][questionnaire_id] = assignment.get_review_questionnaire_id(round)&lt;br /&gt;
    response_ids = []&lt;br /&gt;
    maps.each do |map|&lt;br /&gt;
      responses =  get_responses(map.id, round)&lt;br /&gt;
      unless responses.empty?&lt;br /&gt;
        response_ids &amp;lt;&amp;lt; responses.last.id&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    review_final_versions[symbol][:response_ids] = response_ids&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  #Get responses by map_id and round (if exists)&lt;br /&gt;
  def self.get_responses(id, round)&lt;br /&gt;
     if round.nil?&lt;br /&gt;
       responses = Response.where(map_id: id)&lt;br /&gt;
     else&lt;br /&gt;
       responses = Response.where(map_id: id, round: round)&lt;br /&gt;
     end	&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of other methods ===&lt;br /&gt;
We removed the return statement from the get_title, export_fields, and show_feedback methods because return statements are unnecessary in Ruby.&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
=== Code Improvements ===&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot internal functionality. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focused on refactoring the existing model, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
The previous unit tests had syntactical and run time errors.  We were not able to get the previous unit tests to run without errors.  Because of this we rewrote all of the unit tests for the &amp;lt;b&amp;gt;ReviewResponseModel&amp;lt;/b&amp;gt;.  It is important to have working unit tests so that when internal changes are made to functions the external output remains the same.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of Unit Tests===&lt;br /&gt;
&lt;br /&gt;
We added a test_helper file to the main test folder that requires a needed configuration file and needed gems.  We also added 8 fixtures that were needed for data to run the unit tests.  The following fixture files were added:&lt;br /&gt;
&lt;br /&gt;
* assignment_questionnaires.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* questionnaires.yml&lt;br /&gt;
* response_maps.yml&lt;br /&gt;
* responses.yml&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There is at least one unit test for every public method within the &amp;lt;b&amp;gt;ReviewResponseModel&amp;lt;/b&amp;gt;.  The test naming convention used is &amp;quot;method_&amp;lt;name of method that is being tested&amp;gt;&amp;quot;.  For example, the unit test for the export method is &amp;quot;method_export&amp;quot;.  If there are multiple test for one method the name of the test will include the test case after the normal naming convention.  For example, one of the unit tests for the import method checks for an invalid assignment.  The name of this method is &amp;quot;method_import_invalid_assignment&amp;quot;.  The following are the unit tests we created:&lt;br /&gt;
&lt;br /&gt;
* method_export&lt;br /&gt;
* method_get_metareview_response_maps&lt;br /&gt;
* method_get_team_response_for_round&lt;br /&gt;
* method_final_versions_from_reviewer&lt;br /&gt;
* method_import&lt;br /&gt;
* method_import_invalid_reviewee&lt;br /&gt;
* method_import_invalid_reviewer&lt;br /&gt;
* method_import_invalid_assignment&lt;br /&gt;
* method_delete&lt;br /&gt;
* method_delete_no _force&lt;br /&gt;
* method_show_feedback&lt;br /&gt;
* method_get_title&lt;br /&gt;
* method_export_fields&lt;br /&gt;
* method_questionnaire&lt;br /&gt;
* method_add_reviewer&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== How to Run Unit Tests ===&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up [[ http://152.46.16.195:5902/ | Expertiza]] and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= External Links =&lt;br /&gt;
&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
# [http://152.46.16.195:5902/ Expertiza Deployed Site]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98513</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98513"/>
		<updated>2015-11-06T22:58:40Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Refactoring of metareview_response_maps method */ added places where we need to make changes in other files&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.  Prior to refactoring, all null checks were performed within the import method.   After refactoring, the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that any existing functionality did not break. &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Before refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def self.import(row, session, id)&lt;br /&gt;
    if row.length &amp;lt; 2&lt;br /&gt;
      raise ArgumentError, &amp;quot;Not enough items&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    assignment = Assignment.find(id)&lt;br /&gt;
    if assignment.nil?&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    index = 1&lt;br /&gt;
    while index &amp;lt; row.length&lt;br /&gt;
      user = User.find_by_name(row[index].to_s.strip)&lt;br /&gt;
      if user.nil?&lt;br /&gt;
        raise ImportError, &amp;quot;The user account for the reviewer \&amp;quot;#{row[index]}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: user.id, parent_id:  assignment.id).first&lt;br /&gt;
      if reviewer == nil&lt;br /&gt;
        raise ImportError, &amp;quot;The reviewer \&amp;quot;#{row[index]}\&amp;quot; is not a participant in this assignment. &amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if assignment.team_assignment&lt;br /&gt;
        reviewee = AssignmentTeam.where(name: row[0].to_s.strip, parent_id:  assignment.id).first&lt;br /&gt;
        if reviewee == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The author \&amp;quot;#{row[0].to_s.strip}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        existing = ReviewResponseMap.where(reviewee_id: reviewee.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
        if existing.nil?&lt;br /&gt;
          ReviewResponseMap.create(:reviewer_id =&amp;gt; reviewer.id, :reviewee_id =&amp;gt; reviewee.id, :reviewed_object_id =&amp;gt; assignment.id)&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        puser = User.find_by_name(row[0].to_s.strip)&lt;br /&gt;
        if user == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The user account for the reviewee \&amp;quot;#{row[0]}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        reviewee = AssignmentParticipant.where(user_id: puser.id, parent_id:  assignment.id).first&lt;br /&gt;
        if reviewee == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The author \&amp;quot;#{row[0].to_s.strip}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        team_id = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
        existing = ReviewResponseMap.where(reviewee_id: team_id, reviewer_id:  reviewer.id).first&lt;br /&gt;
        if existing.nil?&lt;br /&gt;
          ReviewResponseMap.create(:reviewee_id =&amp;gt; team_id, :reviewer_id =&amp;gt; reviewer.id, :reviewed_object_id =&amp;gt; assignment.id)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      index += 1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality.  This is why it was renamed to get_team_responses_for_round, the new name of the method provides a clearer idea of its purpose. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  We also removed the return statement at the end of the method.  &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Before refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_assessments_round_for(team,round)&lt;br /&gt;
    team_id =team.id&lt;br /&gt;
    responses = Array.new&lt;br /&gt;
    if team_id&lt;br /&gt;
      maps = ResponseMap.where(:reviewee_id =&amp;gt; team_id, :type =&amp;gt; &amp;quot;ReviewResponseMap&amp;quot;)&lt;br /&gt;
      maps.each{ |map|&lt;br /&gt;
        if !map.response.empty? &amp;amp;&amp;amp; !map.response.reject{|r| r.round!=round}.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject{|r| r.round!=round}.last&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      responses.sort! {|a,b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    return responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # return the responses for specified round,&lt;br /&gt;
  # for varying rubric feature -Yang&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:    &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  assessments = ReviewResponseMap.get_assessments_round_for(team,i)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt; &lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 scores[questionnaire_symbol][:assessments] = questionnaire.get_assessments_round_for(self,round)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of metareview_response_maps method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex.  It contained an unneeded private variable and an unnecessary nested loop.  Originally, it added each metareview map individually in the nested loop.  We decided to remove the nested loop and use the concat method for readability and maintainability.  These changes allowed us to remove the private variable &amp;quot;metareview_list&amp;quot; and only maintain the &amp;quot;metareview_response_maps&amp;quot; variable.  We also renamed the metareview_response_maps method to get_metareview_response_maps method to be more descriptive about the intent of the method. &lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Before refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id:self.id)&lt;br /&gt;
    metareview_list=[]&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps = MetareviewResponseMap.where(reviewed_object_id:response.id)&lt;br /&gt;
      metareview_response_maps.each do |metareview_response_map|&lt;br /&gt;
        metareview_list&amp;lt;&amp;lt;metareview_response_map&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    metareview_list&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Returns the response maps for all the metareviews&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps.concat MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The change from this renaming also requires changes in the following files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 models/assignment.rb:361:    response_map_set.sort! { |a, b| a.metareview_response_maps.count &amp;lt;=&amp;gt; b.metareview_response_maps.count }&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 models/assignment.rb:362:    min_metareviews = response_map_set.first.metareview_response_maps.count&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 models/assignment.rb:363:    response_map_set.reject! { |response_map| response_map.metareview_response_maps.count &amp;gt; min_metareviews }&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 models/assignment.rb:377:    response_map_set.sort! { |a, b| a.metareview_response_maps.count &amp;lt;=&amp;gt; b.metareview_response_maps.count }&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 models/assignment.rb:378:    min_metareviews = response_map_set.first.metareview_response_maps.count&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 models/assignment.rb:379:    response_map_set.sort! { |a, b| a.metareview_response_maps.last.id &amp;lt;=&amp;gt; b.metareview_response_maps.last.id } if min_metareviews &amp;gt; 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 models/assignment_participant.rb:73:    self.response_maps.metareview_response_maps.each do |metaresponse_map|&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 models/response.rb:4:  has_many :metareview_response_maps, :class_name =&amp;gt; 'MetareviewResponseMap', :foreign_key =&amp;gt; 'reviewed_object_id', dependent: :destroy&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of export method ===&lt;br /&gt;
The export method contained mappings.sort! { |a, b| a.reviewee.name &amp;lt;=&amp;gt; b.reviewee.name }.  We could not get past this when running tests, we kept getting a message saying, &amp;quot;sort! was not a method for an ActiveRecord_Relation&amp;quot;.  But, ActiveRecord_Relation does allow the use of sort.  So we changed that line of code to  mappings = mappings.sort { |a, b| a.reviewee.name &amp;lt;=&amp;gt; b.reviewee.name }&lt;br /&gt;
&lt;br /&gt;
Before refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.export(csv, parent_id, options)&lt;br /&gt;
    mappings = where(reviewed_object_id: parent_id)&lt;br /&gt;
    mappings.sort! { |a, b| a.reviewee.name &amp;lt;=&amp;gt; b.reviewee.name }&lt;br /&gt;
    mappings.each {&lt;br /&gt;
      |map|&lt;br /&gt;
      csv &amp;lt;&amp;lt; [&lt;br /&gt;
        map.reviewee.name,&lt;br /&gt;
        map.reviewer.name&lt;br /&gt;
      ]&lt;br /&gt;
    }&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # options parameter used as a signature in other models&lt;br /&gt;
  def self.export(csv, parent_id, options)&lt;br /&gt;
    mappings = where(reviewed_object_id: parent_id)&lt;br /&gt;
    mappings = mappings.sort { |a, b| a.reviewee.name &amp;lt;=&amp;gt; b.reviewee.name }&lt;br /&gt;
    mappings.each do&lt;br /&gt;
    |map|&lt;br /&gt;
      csv &amp;lt;&amp;lt; [map.reviewee.name, map.reviewer.name]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of final_versions_from_reviewer method ===&lt;br /&gt;
The final_versions_from_reviewer method was too long and repetitive.  We removed common functionality from within the if and else statement and put it in a private method final_versions_from_reviewer.  Then we created the get_responses method to find the responses based on the arguments values.  These private methods make the class more readable for other programmers.&lt;br /&gt;
 &lt;br /&gt;
Before refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.final_versions_from_reviewer(reviewer_id)&lt;br /&gt;
    maps = ReviewResponseMap.where(reviewer_id: reviewer_id)&lt;br /&gt;
    assignment = Assignment.find(Participant.find(reviewer_id).parent_id)&lt;br /&gt;
    review_final_versions = Hash.new&lt;br /&gt;
    if !assignment.varying_rubrics_by_round?&lt;br /&gt;
      #same review rubric used in multiple rounds&lt;br /&gt;
      review_final_versions[:review] = Hash.new&lt;br /&gt;
      review_final_versions[:review][:questionnaire_id] = assignment.get_review_questionnaire_id&lt;br /&gt;
      response_ids = Array.new&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        responses = Response.where(map_id:map.id)&lt;br /&gt;
        if !responses.empty?&lt;br /&gt;
          response_ids &amp;lt;&amp;lt; responses.last.id&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      review_final_versions[:review][:response_ids] = response_ids&lt;br /&gt;
    else&lt;br /&gt;
      #vary rubric by round&lt;br /&gt;
      rounds_num = assignment.rounds_of_reviews&lt;br /&gt;
      for round in 1..rounds_num&lt;br /&gt;
        symbol = (&amp;quot;review round&amp;quot;+round.to_s).to_sym&lt;br /&gt;
        review_final_versions[symbol] = Hash.new&lt;br /&gt;
        review_final_versions[symbol][:questionnaire_id] = assignment.get_review_questionnaire_id(round)&lt;br /&gt;
        response_ids = Array.new&lt;br /&gt;
        maps.each do |map|&lt;br /&gt;
          responses = Response.where(map_id:map.id, round:round)&lt;br /&gt;
          if !responses.empty?&lt;br /&gt;
            response_ids &amp;lt;&amp;lt; responses.last.id&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        review_final_versions[symbol][:response_ids] = response_ids&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    review_final_versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # wrap The latest version of responses in each response map,&lt;br /&gt;
  # together with the questionnaire_id will be used to&lt;br /&gt;
  # display the reviewer summary&lt;br /&gt;
  def self.final_versions_from_reviewer(reviewer_id)&lt;br /&gt;
    maps = ReviewResponseMap.where(reviewer_id: reviewer_id)&lt;br /&gt;
    assignment = find_assignment(Participant.find(reviewer_id).parent_id)&lt;br /&gt;
    review_final_versions = {}&lt;br /&gt;
    unless assignment.varying_rubrics_by_round?&lt;br /&gt;
      #same review rubric used in multiple rounds&lt;br /&gt;
      review_final_versions = review_final_version_responses(:review, :questionnaire_id, assignment, maps)&lt;br /&gt;
    else&lt;br /&gt;
      # vary rubric by round&lt;br /&gt;
      rounds_num = assignment.rounds_of_reviews&lt;br /&gt;
      (1..rounds_num).each do |round|&lt;br /&gt;
        symbol = ('review round' + round.to_s).to_sym&lt;br /&gt;
        review_final_versions = review_final_version_responses(symbol, :questionnaire_id, assignment, maps, round)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    review_final_versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Compute list of responses and return it&lt;br /&gt;
  def self.review_final_version_responses(symbol, questionnaire_id, assignment, maps, round = nil)&lt;br /&gt;
    review_final_versions = {}&lt;br /&gt;
    review_final_versions[symbol] = {}&lt;br /&gt;
    review_final_versions[symbol][questionnaire_id] = assignment.get_review_questionnaire_id(round)&lt;br /&gt;
    response_ids = []&lt;br /&gt;
    maps.each do |map|&lt;br /&gt;
      responses =  get_responses(map.id, round)&lt;br /&gt;
      unless responses.empty?&lt;br /&gt;
        response_ids &amp;lt;&amp;lt; responses.last.id&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    review_final_versions[symbol][:response_ids] = response_ids&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  #Get responses by map_id and round (if exists)&lt;br /&gt;
  def self.get_responses(id, round)&lt;br /&gt;
     if round.nil?&lt;br /&gt;
       responses = Response.where(map_id: id)&lt;br /&gt;
     else&lt;br /&gt;
       responses = Response.where(map_id: id, round: round)&lt;br /&gt;
     end	&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of other methods ===&lt;br /&gt;
We removed the return statement from the get_title, export_fields, and show_feedback methods because return statements are unnecessary in Ruby.&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
=== Code Improvements ===&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot internal functionality. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focused on refactoring the existing model, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
The previous unit tests had syntactical and run time errors.  We were not able to get the previous unit tests to run without errors.  Because of this we rewrote all of the unit tests for the &amp;lt;b&amp;gt;ReviewResponseModel&amp;lt;/b&amp;gt;.  It is important to have working unit tests so that when internal changes are made to functions the external output remains the same.&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of Unit Tests===&lt;br /&gt;
&lt;br /&gt;
We added a test_helper file to the main test folder that requires a needed configuration file and needed gems.  We also added 8 fixtures that were needed for data to run the unit tests.  The following fixture files were added:&lt;br /&gt;
&lt;br /&gt;
* assignment_questionnaires.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* questionnaires.yml&lt;br /&gt;
* response_maps.yml&lt;br /&gt;
* responses.yml&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There is at least one unit test for every public method within the &amp;lt;b&amp;gt;ReviewResponseModel&amp;lt;/b&amp;gt;.  The test naming convention used is &amp;quot;method_&amp;lt;name of method that is being tested&amp;gt;&amp;quot;.  For example, the unit test for the export method is &amp;quot;method_export&amp;quot;.  If there are multiple test for one method the name of the test will include the test case after the normal naming convention.  For example, one of the unit tests for the import method checks for an invalid assignment.  The name of this method is &amp;quot;method_import_invalid_assignment&amp;quot;.  The following are the unit tests we created:&lt;br /&gt;
&lt;br /&gt;
* method_export&lt;br /&gt;
* method_get_metareview_response_maps&lt;br /&gt;
* method_get_team_response_for_round&lt;br /&gt;
* method_final_versions_from_reviewer&lt;br /&gt;
* method_import&lt;br /&gt;
* method_import_invalid_reviewee&lt;br /&gt;
* method_import_invalid_reviewer&lt;br /&gt;
* method_import_invalid_assignment&lt;br /&gt;
* method_delete&lt;br /&gt;
* method_delete_no _force&lt;br /&gt;
* method_show_feedback&lt;br /&gt;
* method_get_title&lt;br /&gt;
* method_export_fields&lt;br /&gt;
* method_questionnaire&lt;br /&gt;
* method_add_reviewer&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== How to Run Unit Tests ===&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up [[ http://152.46.16.195:5902/ | Expertiza]] and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= External Links =&lt;br /&gt;
&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
# [http://152.46.16.195:5902/ Expertiza Deployed Site]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98413</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98413"/>
		<updated>2015-11-06T18:14:57Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Refactor metareview_response_maps */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def self.import(row, session, id)&lt;br /&gt;
    if row.length &amp;lt; 2&lt;br /&gt;
      raise ArgumentError, &amp;quot;Not enough items&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    assignment = Assignment.find(id)&lt;br /&gt;
    if assignment.nil?&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    index = 1&lt;br /&gt;
    while index &amp;lt; row.length&lt;br /&gt;
      user = User.find_by_name(row[index].to_s.strip)&lt;br /&gt;
      if user.nil?&lt;br /&gt;
        raise ImportError, &amp;quot;The user account for the reviewer \&amp;quot;#{row[index]}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: user.id, parent_id:  assignment.id).first&lt;br /&gt;
      if reviewer == nil&lt;br /&gt;
        raise ImportError, &amp;quot;The reviewer \&amp;quot;#{row[index]}\&amp;quot; is not a participant in this assignment. &amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if assignment.team_assignment&lt;br /&gt;
        reviewee = AssignmentTeam.where(name: row[0].to_s.strip, parent_id:  assignment.id).first&lt;br /&gt;
        if reviewee == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The author \&amp;quot;#{row[0].to_s.strip}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        existing = ReviewResponseMap.where(reviewee_id: reviewee.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
        if existing.nil?&lt;br /&gt;
          ReviewResponseMap.create(:reviewer_id =&amp;gt; reviewer.id, :reviewee_id =&amp;gt; reviewee.id, :reviewed_object_id =&amp;gt; assignment.id)&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        puser = User.find_by_name(row[0].to_s.strip)&lt;br /&gt;
        if user == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The user account for the reviewee \&amp;quot;#{row[0]}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        reviewee = AssignmentParticipant.where(user_id: puser.id, parent_id:  assignment.id).first&lt;br /&gt;
        if reviewee == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The author \&amp;quot;#{row[0].to_s.strip}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        team_id = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
        existing = ReviewResponseMap.where(reviewee_id: team_id, reviewer_id:  reviewer.id).first&lt;br /&gt;
        if existing.nil?&lt;br /&gt;
          ReviewResponseMap.create(:reviewee_id =&amp;gt; team_id, :reviewer_id =&amp;gt; reviewer.id, :reviewed_object_id =&amp;gt; assignment.id)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      index += 1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_assessments_round_for(team,round)&lt;br /&gt;
    team_id =team.id&lt;br /&gt;
    responses = Array.new&lt;br /&gt;
    if team_id&lt;br /&gt;
      maps = ResponseMap.where(:reviewee_id =&amp;gt; team_id, :type =&amp;gt; &amp;quot;ReviewResponseMap&amp;quot;)&lt;br /&gt;
      maps.each{ |map|&lt;br /&gt;
        if !map.response.empty? &amp;amp;&amp;amp; !map.response.reject{|r| r.round!=round}.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject{|r| r.round!=round}.last&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      responses.sort! {|a,b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    return responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:    &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  assessments = ReviewResponseMap.get_assessments_round_for(team,i)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt; &lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 scores[questionnaire_symbol][:assessments] = questionnaire.get_assessments_round_for(self,round)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and removing additional loop. &lt;br /&gt;
Here, the ''metareview_response_maps'' variable is a collection that doesn't need to be looped (in fact the metareviews are being overwritten each iteration of the loop and not appended to the collection). And we're returning the last value of the collection. The rest of them are just lost. We've removed the redundant iteration so that it just maps to metareviews once and returns the collection at the end of the iteration. The private variable removed is: ''metareview_list'' .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id:self.id)&lt;br /&gt;
    metareview_list=Array.new()&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps = MetareviewResponseMap.where(reviewed_object_id:response.id)&lt;br /&gt;
      metareview_response_maps.each do |metareview_response_map|&lt;br /&gt;
        metareview_list&amp;lt;&amp;lt;metareview_response_map&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    metareview_list&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
=== Code Improvements ===&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
&lt;br /&gt;
=== Changes to Unit Tests===&lt;br /&gt;
&lt;br /&gt;
=== How to Run Unit Tests ===&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [http://152.46.16.195:5902/ Expertiza Deployed Site]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98408</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98408"/>
		<updated>2015-11-06T18:10:45Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Refactoring of get_assessments_round_for method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def self.import(row, session, id)&lt;br /&gt;
    if row.length &amp;lt; 2&lt;br /&gt;
      raise ArgumentError, &amp;quot;Not enough items&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    assignment = Assignment.find(id)&lt;br /&gt;
    if assignment.nil?&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    index = 1&lt;br /&gt;
    while index &amp;lt; row.length&lt;br /&gt;
      user = User.find_by_name(row[index].to_s.strip)&lt;br /&gt;
      if user.nil?&lt;br /&gt;
        raise ImportError, &amp;quot;The user account for the reviewer \&amp;quot;#{row[index]}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: user.id, parent_id:  assignment.id).first&lt;br /&gt;
      if reviewer == nil&lt;br /&gt;
        raise ImportError, &amp;quot;The reviewer \&amp;quot;#{row[index]}\&amp;quot; is not a participant in this assignment. &amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if assignment.team_assignment&lt;br /&gt;
        reviewee = AssignmentTeam.where(name: row[0].to_s.strip, parent_id:  assignment.id).first&lt;br /&gt;
        if reviewee == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The author \&amp;quot;#{row[0].to_s.strip}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        existing = ReviewResponseMap.where(reviewee_id: reviewee.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
        if existing.nil?&lt;br /&gt;
          ReviewResponseMap.create(:reviewer_id =&amp;gt; reviewer.id, :reviewee_id =&amp;gt; reviewee.id, :reviewed_object_id =&amp;gt; assignment.id)&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        puser = User.find_by_name(row[0].to_s.strip)&lt;br /&gt;
        if user == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The user account for the reviewee \&amp;quot;#{row[0]}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        reviewee = AssignmentParticipant.where(user_id: puser.id, parent_id:  assignment.id).first&lt;br /&gt;
        if reviewee == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The author \&amp;quot;#{row[0].to_s.strip}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        team_id = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
        existing = ReviewResponseMap.where(reviewee_id: team_id, reviewer_id:  reviewer.id).first&lt;br /&gt;
        if existing.nil?&lt;br /&gt;
          ReviewResponseMap.create(:reviewee_id =&amp;gt; team_id, :reviewer_id =&amp;gt; reviewer.id, :reviewed_object_id =&amp;gt; assignment.id)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      index += 1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_assessments_round_for(team,round)&lt;br /&gt;
    team_id =team.id&lt;br /&gt;
    responses = Array.new&lt;br /&gt;
    if team_id&lt;br /&gt;
      maps = ResponseMap.where(:reviewee_id =&amp;gt; team_id, :type =&amp;gt; &amp;quot;ReviewResponseMap&amp;quot;)&lt;br /&gt;
      maps.each{ |map|&lt;br /&gt;
        if !map.response.empty? &amp;amp;&amp;amp; !map.response.reject{|r| r.round!=round}.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject{|r| r.round!=round}.last&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      responses.sort! {|a,b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    return responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:    &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  assessments = ReviewResponseMap.get_assessments_round_for(team,i)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt; &lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 scores[questionnaire_symbol][:assessments] = questionnaire.get_assessments_round_for(self,round)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id:self.id)&lt;br /&gt;
    metareview_list=Array.new()&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps = MetareviewResponseMap.where(reviewed_object_id:response.id)&lt;br /&gt;
      metareview_response_maps.each do |metareview_response_map|&lt;br /&gt;
        metareview_list&amp;lt;&amp;lt;metareview_response_map&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    metareview_list&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [http://152.46.16.195:5902/ Expertiza Deployed Site]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98406</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98406"/>
		<updated>2015-11-06T18:09:41Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Refactoring of get_assessments_round_for method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def self.import(row, session, id)&lt;br /&gt;
    if row.length &amp;lt; 2&lt;br /&gt;
      raise ArgumentError, &amp;quot;Not enough items&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    assignment = Assignment.find(id)&lt;br /&gt;
    if assignment.nil?&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    index = 1&lt;br /&gt;
    while index &amp;lt; row.length&lt;br /&gt;
      user = User.find_by_name(row[index].to_s.strip)&lt;br /&gt;
      if user.nil?&lt;br /&gt;
        raise ImportError, &amp;quot;The user account for the reviewer \&amp;quot;#{row[index]}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: user.id, parent_id:  assignment.id).first&lt;br /&gt;
      if reviewer == nil&lt;br /&gt;
        raise ImportError, &amp;quot;The reviewer \&amp;quot;#{row[index]}\&amp;quot; is not a participant in this assignment. &amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if assignment.team_assignment&lt;br /&gt;
        reviewee = AssignmentTeam.where(name: row[0].to_s.strip, parent_id:  assignment.id).first&lt;br /&gt;
        if reviewee == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The author \&amp;quot;#{row[0].to_s.strip}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        existing = ReviewResponseMap.where(reviewee_id: reviewee.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
        if existing.nil?&lt;br /&gt;
          ReviewResponseMap.create(:reviewer_id =&amp;gt; reviewer.id, :reviewee_id =&amp;gt; reviewee.id, :reviewed_object_id =&amp;gt; assignment.id)&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        puser = User.find_by_name(row[0].to_s.strip)&lt;br /&gt;
        if user == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The user account for the reviewee \&amp;quot;#{row[0]}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        reviewee = AssignmentParticipant.where(user_id: puser.id, parent_id:  assignment.id).first&lt;br /&gt;
        if reviewee == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The author \&amp;quot;#{row[0].to_s.strip}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        team_id = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
        existing = ReviewResponseMap.where(reviewee_id: team_id, reviewer_id:  reviewer.id).first&lt;br /&gt;
        if existing.nil?&lt;br /&gt;
          ReviewResponseMap.create(:reviewee_id =&amp;gt; team_id, :reviewer_id =&amp;gt; reviewer.id, :reviewed_object_id =&amp;gt; assignment.id)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      index += 1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_assessments_round_for(team,round)&lt;br /&gt;
    team_id =team.id&lt;br /&gt;
    responses = Array.new&lt;br /&gt;
    if team_id&lt;br /&gt;
      maps = ResponseMap.where(:reviewee_id =&amp;gt; team_id, :type =&amp;gt; &amp;quot;ReviewResponseMap&amp;quot;)&lt;br /&gt;
      maps.each{ |map|&lt;br /&gt;
        if !map.response.empty? &amp;amp;&amp;amp; !map.response.reject{|r| r.round!=round}.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject{|r| r.round!=round}.last&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      responses.sort! {|a,b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    return responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:    &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 assessments = ReviewResponseMap.get_assessments_round_for(team,i)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt; &lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
scores[questionnaire_symbol][:assessments] = questionnaire.get_assessments_round_for(self,round)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id:self.id)&lt;br /&gt;
    metareview_list=Array.new()&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps = MetareviewResponseMap.where(reviewed_object_id:response.id)&lt;br /&gt;
      metareview_response_maps.each do |metareview_response_map|&lt;br /&gt;
        metareview_list&amp;lt;&amp;lt;metareview_response_map&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    metareview_list&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id:self.id)&lt;br /&gt;
    metareview_list=Array.new()&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps = MetareviewResponseMap.where(reviewed_object_id:response.id)&lt;br /&gt;
      metareview_response_maps.each do |metareview_response_map|&lt;br /&gt;
        metareview_list&amp;lt;&amp;lt;metareview_response_map&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    metareview_list&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [http://152.46.16.195:5902/ Expertiza Deployed Site]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98402</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98402"/>
		<updated>2015-11-06T18:08:33Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Refactoring of import method */ removed images&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def self.import(row, session, id)&lt;br /&gt;
    if row.length &amp;lt; 2&lt;br /&gt;
      raise ArgumentError, &amp;quot;Not enough items&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    assignment = Assignment.find(id)&lt;br /&gt;
    if assignment.nil?&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    index = 1&lt;br /&gt;
    while index &amp;lt; row.length&lt;br /&gt;
      user = User.find_by_name(row[index].to_s.strip)&lt;br /&gt;
      if user.nil?&lt;br /&gt;
        raise ImportError, &amp;quot;The user account for the reviewer \&amp;quot;#{row[index]}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: user.id, parent_id:  assignment.id).first&lt;br /&gt;
      if reviewer == nil&lt;br /&gt;
        raise ImportError, &amp;quot;The reviewer \&amp;quot;#{row[index]}\&amp;quot; is not a participant in this assignment. &amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if assignment.team_assignment&lt;br /&gt;
        reviewee = AssignmentTeam.where(name: row[0].to_s.strip, parent_id:  assignment.id).first&lt;br /&gt;
        if reviewee == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The author \&amp;quot;#{row[0].to_s.strip}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        existing = ReviewResponseMap.where(reviewee_id: reviewee.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
        if existing.nil?&lt;br /&gt;
          ReviewResponseMap.create(:reviewer_id =&amp;gt; reviewer.id, :reviewee_id =&amp;gt; reviewee.id, :reviewed_object_id =&amp;gt; assignment.id)&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        puser = User.find_by_name(row[0].to_s.strip)&lt;br /&gt;
        if user == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The user account for the reviewee \&amp;quot;#{row[0]}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        reviewee = AssignmentParticipant.where(user_id: puser.id, parent_id:  assignment.id).first&lt;br /&gt;
        if reviewee == nil&lt;br /&gt;
          raise ImportError, &amp;quot;The author \&amp;quot;#{row[0].to_s.strip}\&amp;quot; was not found. &amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        team_id = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
        existing = ReviewResponseMap.where(reviewee_id: team_id, reviewer_id:  reviewer.id).first&lt;br /&gt;
        if existing.nil?&lt;br /&gt;
          ReviewResponseMap.create(:reviewee_id =&amp;gt; team_id, :reviewer_id =&amp;gt; reviewer.id, :reviewed_object_id =&amp;gt; assignment.id)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      index += 1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_assessments_round_for(team,round)&lt;br /&gt;
    team_id =team.id&lt;br /&gt;
    responses = Array.new&lt;br /&gt;
    if team_id&lt;br /&gt;
      maps = ResponseMap.where(:reviewee_id =&amp;gt; team_id, :type =&amp;gt; &amp;quot;ReviewResponseMap&amp;quot;)&lt;br /&gt;
      maps.each{ |map|&lt;br /&gt;
        if !map.response.empty? &amp;amp;&amp;amp; !map.response.reject{|r| r.round!=round}.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject{|r| r.round!=round}.last&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      responses.sort! {|a,b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    return responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/big&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:    &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 assessments = ReviewResponseMap.get_assessments_round_for(team,i)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt; &lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
scores[questionnaire_symbol][:assessments] = questionnaire.get_assessments_round_for(self,round)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id:self.id)&lt;br /&gt;
    metareview_list=Array.new()&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps = MetareviewResponseMap.where(reviewed_object_id:response.id)&lt;br /&gt;
      metareview_response_maps.each do |metareview_response_map|&lt;br /&gt;
        metareview_list&amp;lt;&amp;lt;metareview_response_map&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    metareview_list&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
def metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id:self.id)&lt;br /&gt;
    metareview_list=Array.new()&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps = MetareviewResponseMap.where(reviewed_object_id:response.id)&lt;br /&gt;
      metareview_response_maps.each do |metareview_response_map|&lt;br /&gt;
        metareview_list&amp;lt;&amp;lt;metareview_response_map&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    metareview_list&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [http://152.46.16.195:5902/ Expertiza Deployed Site]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98400</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98400"/>
		<updated>2015-11-06T18:06:50Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Refactoring of get_assessments_round_for method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
  def self.get_assessments_round_for(team,round)&lt;br /&gt;
    team_id =team.id&lt;br /&gt;
    responses = Array.new&lt;br /&gt;
    if team_id&lt;br /&gt;
      maps = ResponseMap.where(:reviewee_id =&amp;gt; team_id, :type =&amp;gt; &amp;quot;ReviewResponseMap&amp;quot;)&lt;br /&gt;
      maps.each{ |map|&lt;br /&gt;
        if !map.response.empty? &amp;amp;&amp;amp; !map.response.reject{|r| r.round!=round}.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject{|r| r.round!=round}.last&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      responses.sort! {|a,b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    return responses&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:    &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 assessments = ReviewResponseMap.get_assessments_round_for(team,i)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt; &lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
scores[questionnaire_symbol][:assessments] = questionnaire.get_assessments_round_for(self,round)&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id:self.id)&lt;br /&gt;
    metareview_list=Array.new()&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps = MetareviewResponseMap.where(reviewed_object_id:response.id)&lt;br /&gt;
      metareview_response_maps.each do |metareview_response_map|&lt;br /&gt;
        metareview_list&amp;lt;&amp;lt;metareview_response_map&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    metareview_list&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
def metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id:self.id)&lt;br /&gt;
    metareview_list=Array.new()&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps = MetareviewResponseMap.where(reviewed_object_id:response.id)&lt;br /&gt;
      metareview_response_maps.each do |metareview_response_map|&lt;br /&gt;
        metareview_list&amp;lt;&amp;lt;metareview_response_map&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    metareview_list&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [http://152.46.16.195:5902/ Expertiza Deployed Site]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98399</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98399"/>
		<updated>2015-11-06T18:01:16Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Refactor metareview_response_maps */ removed image&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
 def metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id:self.id)&lt;br /&gt;
    metareview_list=Array.new()&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps = MetareviewResponseMap.where(reviewed_object_id:response.id)&lt;br /&gt;
      metareview_response_maps.each do |metareview_response_map|&lt;br /&gt;
        metareview_list&amp;lt;&amp;lt;metareview_response_map&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    metareview_list&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
def metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id:self.id)&lt;br /&gt;
    metareview_list=Array.new()&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps = MetareviewResponseMap.where(reviewed_object_id:response.id)&lt;br /&gt;
      metareview_response_maps.each do |metareview_response_map|&lt;br /&gt;
        metareview_list&amp;lt;&amp;lt;metareview_response_map&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    metareview_list&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [http://152.46.16.195:5902/ Expertiza Deployed Site]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98398</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98398"/>
		<updated>2015-11-06T18:00:23Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Refactor metareview_response_maps */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop. &lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
def metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id:self.id)&lt;br /&gt;
    metareview_list=Array.new()&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps = MetareviewResponseMap.where(reviewed_object_id:response.id)&lt;br /&gt;
      metareview_response_maps.each do |metareview_response_map|&lt;br /&gt;
        metareview_list&amp;lt;&amp;lt;metareview_response_map&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    metareview_list&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [http://152.46.16.195:5902/ Expertiza Deployed Site]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98397</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98397"/>
		<updated>2015-11-06T17:56:33Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [http://152.46.16.195:5902/ Expertiza Deployed Site]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98396</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98396"/>
		<updated>2015-11-06T17:56:03Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [http://152.46.16.195:5902/ Expertiza Site Link]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98395</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98395"/>
		<updated>2015-11-06T17:54:27Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [152.46.16.195:5902 Expertiza Site Link]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98394</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98394"/>
		<updated>2015-11-06T17:53:14Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98393</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98393"/>
		<updated>2015-11-06T17:52:49Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Refactoring of import method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	CodeClimate reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;7. [https://codeclimate.com/ Code Climate]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98391</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98391"/>
		<updated>2015-11-06T17:52:17Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Refactoring of import method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	CodeClimate &amp;lt;ref&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;7. [https://codeclimate.com/ Code Climate]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98389</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98389"/>
		<updated>2015-11-06T17:51:44Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Refactoring of import method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	CodeClimate &amp;lt;ref&amp;gt;Code Climate&amp;lt;/ref&amp;gt; reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;7. [https://codeclimate.com/ Code Climate]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98387</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98387"/>
		<updated>2015-11-06T17:48:02Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref name=&amp;quot;Code Climate&amp;quot;&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	[[ https://codeclimate.com/ |Code Climate]] reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;7. [https://codeclimate.com/ Code Climate]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98386</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98386"/>
		<updated>2015-11-06T17:46:19Z</updated>

		<summary type="html">&lt;p&gt;Aankara: Added reference&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate&amp;lt;ref&amp;gt;https://codeclimate.com&amp;lt;/ref&amp;gt; shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	[[ https://codeclimate.com/ |Code Climate]] reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;7. [https://codeclimate.com/ Code Climate]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98382</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98382"/>
		<updated>2015-11-06T17:36:20Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Improvements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# [[ https://codeclimate.com/ |Code Climate]] shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	[[ https://codeclimate.com/ |Code Climate]] reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. We used CodeClimate of the master branch code as a reference. We took the suggestions we got from CodeClimate and improved our code based on that.&lt;br /&gt;
We also made some of the methods shorter by removing redundant functionality and adding private methods to methods with a lot of functions. We also added private methods in places where we saw repeated patterns to make the code ''DRYer''.&lt;br /&gt;
At the end of our refactoring, we managed to improve the rating on CodeClimate from a '''C''' to a '''B''' . Further improvements meant reducing the size of the entire class which required a much more significant refactoring in multiple files and folders. We focussed on refactoring the existing mode, '''ReviewResponseMap'''.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;7. [https://codeclimate.com/ Code Climate]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98378</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98378"/>
		<updated>2015-11-06T17:28:40Z</updated>

		<summary type="html">&lt;p&gt;Aankara: Added Improvements section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# [[ https://codeclimate.com/ |Code Climate]] shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	[[ https://codeclimate.com/ |Code Climate]] reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Improvements =&lt;br /&gt;
&lt;br /&gt;
This refactoring was to improve readability and follow as many good ''Rubyist'' coding practices as possible without breaking the functionality of existing code. &lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;7. [https://codeclimate.com/ Code Climate]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98376</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98376"/>
		<updated>2015-11-06T17:26:11Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Refactoring of import method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# [[ https://codeclimate.com/ |Code Climate]] shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	[[ https://codeclimate.com/ |Code Climate]] reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation. The size of the import method was reduced by doing this and counts for better readability of the code. Also, this method is a very important one and care was taken so that it wouldn't break any existing functionality. Changes were reflected in CodeClimate (link expired as it was a trial version).&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;7. [https://codeclimate.com/ Code Climate]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98375</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98375"/>
		<updated>2015-11-06T17:21:09Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Manual Test Case */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# [[ https://codeclimate.com/ |Code Climate]] shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	[[ https://codeclimate.com/ |Code Climate]] reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation:&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
''NOTE: Since this was a refactoring of the code and methods, the existing functionality was supposed to remain the same and not break for the changes we've made.''&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;7. [https://codeclimate.com/ Code Climate]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98372</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=98372"/>
		<updated>2015-11-06T17:14:00Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Manual Test Case */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# [[ https://codeclimate.com/ |Code Climate]] shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Design Patterns =&lt;br /&gt;
&lt;br /&gt;
As part of our project, we refactored the model to follow the Single Responsibility and Don't Repeat Yourself (DRY) Principles.  Both of the principles focus on reducing code repetition and increasing the cohesion of the individual methods in the class.  The Single Responsibility Principle states that each class and method should have sole responsibility over one single part of the functionality of the system&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Single_responsibility_principle&amp;lt;/ref&amp;gt;.  The DRY principle states that whenever the same types of logic and functionality are being performed in a class the duplicated logic should be extracted into a new method that can be called in place of the repeated lines of code &amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&amp;lt;/ref&amp;gt;.  A prime example of a method that initially violated these principles was the import method, which in addition to performing the core import processes also performed a number of checks that would be more properly extracted into private methods.&lt;br /&gt;
&lt;br /&gt;
=Code Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of import method ===&lt;br /&gt;
&lt;br /&gt;
	[[ https://codeclimate.com/ |Code Climate]] reports showed the import method to be overly complex, with a number of checks being included within the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation:&lt;br /&gt;
 &lt;br /&gt;
  &amp;lt;big&amp;gt;&amp;lt;nowiki&amp;gt;#Imports new reponse maps if they do not already exist&lt;br /&gt;
  def self.import(row, _session, id)&lt;br /&gt;
      if row.length &amp;lt; 2&lt;br /&gt;
          raise ArgumentError, 'Not enough items'&lt;br /&gt;
      end&lt;br /&gt;
      assignment = find_assignment(id)&lt;br /&gt;
      index = 1&lt;br /&gt;
      reviewee_name = row[0]&lt;br /&gt;
      while index &amp;lt; row.length&lt;br /&gt;
          reviewee_id = nil&lt;br /&gt;
          reviewer_name = row[index]&lt;br /&gt;
          reviewer = get_assignment_participant(reviewer_name,  assignment.id, &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
          participant_nil?(reviewer, reviewer_name , &amp;quot;reviewer&amp;quot;)&lt;br /&gt;
         &lt;br /&gt;
         #Find reviewee if assignment is a team assignment&lt;br /&gt;
         if assignment.team_assignment&lt;br /&gt;
             reviewee = AssignmentTeam.where(name: reviewee_name .to_s.strip, parent_id: assignment.id).first&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id = reviewee.id&lt;br /&gt;
         #Find reviewee if assignment is not a team assignment&lt;br /&gt;
         else&lt;br /&gt;
	     reviewee = get_assignment_participant(reviewee_name, assignment.id, &amp;quot;reviewee&amp;quot;)&lt;br /&gt;
             participant_nil?(reviewee, reviewee_name, &amp;quot;author&amp;quot;)&lt;br /&gt;
             reviewee_id  = TeamsUser.team_id(reviewee.parent_id, reviewee.user_id)&lt;br /&gt;
         end&lt;br /&gt;
         create_response_map(reviewer, reviewee_id,  assignment)&lt;br /&gt;
         index += 1&lt;br /&gt;
      end&lt;br /&gt;
  end&amp;lt;/nowiki&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  # Check for if assignment value is null&lt;br /&gt;
  def self.find_assignment(id)&lt;br /&gt;
      begin&lt;br /&gt;
          assignment = Assignment.find(id)&lt;br /&gt;
      rescue ActiveRecord::RecordNotFound&lt;br /&gt;
          raise ImportError, &amp;quot;The assignment with id \&amp;quot;#{id}\&amp;quot; was not found.&amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if participant is null&lt;br /&gt;
  def self.participant_nil?(participant, user_name, participant_type) &lt;br /&gt;
      error_message = nil&lt;br /&gt;
      if participant_type == &amp;quot;author&amp;quot;&lt;br /&gt;
          error_message = &amp;quot;The author \&amp;quot;#{user_name.to_s.strip}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
          error_message =  &amp;quot;The reviewer \&amp;quot;#{user_name}\&amp;quot; is not a participant in this assignment.&amp;lt;a href='/users/new'&amp;gt;Register&amp;lt;/a&amp;gt; this user as a participant?&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      check_nil?(participant, error_message)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Check for if user is null&lt;br /&gt;
  def self.user_nil?(user, user_name, user_type)&lt;br /&gt;
      check_nil?( user, &amp;quot;The user account for the \&amp;quot;#{user_type}\&amp;quot; \&amp;quot;#{user_name}\&amp;quot; was not found.&amp;lt;a href='/users/new'&amp;gt;Create&amp;lt;/a&amp;gt; this user?&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 #Throws import error for nil objects&lt;br /&gt;
  def self.check_nil?(object, error_message)&lt;br /&gt;
      if object.nil?&lt;br /&gt;
          raise ImportError, error_message&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring of get_assessments_round_for method ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def self.get_team_responses_for_round(team, round)&lt;br /&gt;
    responses = []&lt;br /&gt;
    if team.id&lt;br /&gt;
      maps = ResponseMap.where(reviewee_id: team.id, type: 'ReviewResponseMap')&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        unless map.response.empty? &amp;amp;&amp;amp; map.response.reject { |r| r.round != round }.empty?&lt;br /&gt;
          responses &amp;lt;&amp;lt; map.response.reject { |r| r.round != round }.last&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      responses.sort! { |a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Refactor metareview_response_maps ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;code&amp;gt;&lt;br /&gt;
  def get_metareview_response_maps&lt;br /&gt;
    responses = Response.where(map_id: id)&lt;br /&gt;
    metareview_response_maps = []&lt;br /&gt;
    responses.each do |response|&lt;br /&gt;
      metareview_response_maps &amp;lt;&amp;lt; MetareviewResponseMap.where(reviewed_object_id: response.id)&lt;br /&gt;
    end&lt;br /&gt;
    metareview_response_maps&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Addition of code comments ===&lt;br /&gt;
&lt;br /&gt;
We added comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first method.  The where().first method occurs in the import, get_assignment_participant, and create_response_map methods. It is not always appropriate to use the find_by method, as documented in this github post: https://github.com/bbatsov/rubocop/issues/1938 .  In instances where ordering by id is the desired behavior, where().first will order by default, but in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
= Unit Tests =&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# Run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
#* If you run into a mysql log in error go into config/database.yml and edit the mysql credentials for the test section so that it matches the local environment's mysql configuration&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
= Manual Test Case =&lt;br /&gt;
&lt;br /&gt;
In order to test the changes made to the ReviewResponseMap, bring up Expertiza and log in as an administrator.  Once logged in, proceed with the following steps:&lt;br /&gt;
&lt;br /&gt;
# Go to '''impersonate user''' when logged in as ''instructor6'' and type in ''student559'' (or) just log in as ''student559''. All passwords are ''password'' .&lt;br /&gt;
# Pick any assignment to view.&lt;br /&gt;
# Navigate to '''Other's work'''.&lt;br /&gt;
# Check the different reviews and metareviews. Whether they are being displayed correctly or not.&lt;br /&gt;
# Go to Edit or Give feedback and submit a feedback.&lt;br /&gt;
# Go back and check if the feedback given is displayed correctly or not.&lt;br /&gt;
# Check if author's feedback is correct or not.&lt;br /&gt;
# Go to the '''Temp''' assignment and see if the page is being displayed correctly or not (since there is no assignment submission content or reviews for that).&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;3. [https://github.com/expertiza/expertiza Expertiza Main Repo] &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;4. [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;5. [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;6. [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;7. [https://codeclimate.com/ Code Climate]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=97426</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=97426"/>
		<updated>2015-10-31T01:20:24Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Addition of code comments and unit tests */ Added how to run Unit Tests&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Refactoring of import method ==&lt;br /&gt;
&lt;br /&gt;
	Code Climate reports showed the import method to be overly complex, with a number of checks being included in the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation:&lt;br /&gt;
 &lt;br /&gt;
[[File:AfterRefactor1.PNG]]&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
[[File:AfterRefactor4.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:AfterRefactor5.PNG]]&lt;br /&gt;
&lt;br /&gt;
== Refactoring of get_assessments_round_for method ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
[[File:AfterRefactor3.PNG]]&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
== Refactor metareview_response_maps ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
 [[File:AfterRefactor2.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Addition of code comments and unit tests ==&lt;br /&gt;
&lt;br /&gt;
In addition to the refactoring performed to DRY up the ReviewResponseMap.rb methods we added missing tests for the existing methods and restructured the pre-existing tests to use fixtures.  The following fixture files were added during the process:&lt;br /&gt;
&lt;br /&gt;
* assignment_questionnaires.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* questionnaired.yml&lt;br /&gt;
* response_maps.yml&lt;br /&gt;
* responses.yml&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml&lt;br /&gt;
&lt;br /&gt;
=== Unit Tests ===&lt;br /&gt;
To run the unit tests, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Download the master branch of the repo.&lt;br /&gt;
# Setup the Databases for the test environment (we have used Zhewei's scrubbed expertiza DB )&lt;br /&gt;
#* Run the &amp;quot; rake db:create RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Run the &amp;quot; rake db:reset RAILS_ENV=test &amp;quot; command&lt;br /&gt;
#* Scrub the DB using &amp;quot; mysql -u root expertiza_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
#* Run the &amp;quot; rake db:migrate &amp;quot;&lt;br /&gt;
# run &amp;quot; rake test test/unit/review_response_map_test.rb &amp;quot; in the &amp;quot;expertiza/&amp;quot; directory.&lt;br /&gt;
# Check if tests passed or failed.&lt;br /&gt;
&lt;br /&gt;
We also added method comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first. However it is not always appropriate to use the find_by method, as documented in this github post: &lt;br /&gt;
&lt;br /&gt;
https://github.com/bbatsov/rubocop/issues/1938&lt;br /&gt;
&lt;br /&gt;
In instances where ordering by id is the desired behavior, where().first will do by default, whereas in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Main Repo]&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&lt;br /&gt;
# [https://codeclimate.com/ CodeClimate]&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=97423</id>
		<title>CSC/ECE 517 Fall 2015/ossE1558BGJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/ossE1558BGJ&amp;diff=97423"/>
		<updated>2015-10-31T01:15:22Z</updated>

		<summary type="html">&lt;p&gt;Aankara: /* Problem Statement */ Corrected file name&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the modifications and improvements made to the Expertiza project’s source code as part of an Expertiza based Open Source Software project.  Expertiza is a web based application which allows students to submit and peer-review classmates’ work, including written articles and development projects. The specific changes made during the course of this project were to the ReviewResponseMap.rb file, with additional changes made to other related files in support of refactoring ReviewResponseMap.rb.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
ReviewResponseMap is the model class used to manage the relationship between contributors, reviewers, and assignments.  The intent of the changes were to refactor the code for better readability and adherence to Ruby coding standards and best practices.  Primarily these changes involved the refactoring of overly complex methods, renaming methods for better readability, and the addition of missing unit tests.&lt;br /&gt;
&lt;br /&gt;
Project Requirements:&lt;br /&gt;
&lt;br /&gt;
# Code Climate shows import method is complex, because of lots of checks. This method can be fixed by adding private methods for raising import error.&lt;br /&gt;
# Get_assessments_round_for method can be renamed to get_team_responses_for_round. Team_id private variable is not needed.&lt;br /&gt;
# metareview_response_maps rename, refactoring can be done. No need to do second iteration.&lt;br /&gt;
# write missing unit tests for existing methods.&lt;br /&gt;
&lt;br /&gt;
= Changes =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Refactoring of import method ==&lt;br /&gt;
&lt;br /&gt;
	Code Climate reports showed the import method to be overly complex, with a number of checks being included in the import method itself.  The resolution for this problem was to refactor the import method, creating private methods to perform the null checks and throw import errors.&lt;br /&gt;
&lt;br /&gt;
Prior to refactoring, all null checks were performed in line:&lt;br /&gt;
&lt;br /&gt;
 [[File:BeforeRefactoring1.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring the import method adheres to the single responsibility principle, performing only key import tasks while making calls to private methods for any necessary validation:&lt;br /&gt;
 &lt;br /&gt;
[[File:AfterRefactor1.PNG]]&lt;br /&gt;
&lt;br /&gt;
Private methods added:&lt;br /&gt;
&lt;br /&gt;
[[File:AfterRefactor4.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:AfterRefactor5.PNG]]&lt;br /&gt;
&lt;br /&gt;
== Refactoring of get_assessments_round_for method ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The get_assessments_round_for method’s name failed to provide a clear idea of the method’s purpose and functionality. Additionally, there was a private variable, team_id, introduced in the method that was unnecessary and could be replaced by using the id property of the team parameter directly.  &lt;br /&gt;
&lt;br /&gt;
[[File:BeforeRefactoring2.PNG]]&lt;br /&gt;
&lt;br /&gt;
Following the refactoring, the name of the method provides a clearer idea of its purpose:&lt;br /&gt;
&lt;br /&gt;
[[File:AfterRefactor3.PNG]]&lt;br /&gt;
 &lt;br /&gt;
The change in method name also required changes to the following files that referenced it:&lt;br /&gt;
&lt;br /&gt;
/app/models/assignment.rb:436:     &lt;br /&gt;
 &lt;br /&gt;
[[File:AssignmentCng.png]]&lt;br /&gt;
&lt;br /&gt;
./app/models/assignment_participant.rb:268:&lt;br /&gt;
&lt;br /&gt;
[[File:AssignmentCng2.png]]&lt;br /&gt;
&lt;br /&gt;
== Refactor metareview_response_maps ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The metareview_response_maps method was unnecessarily complex, introducing unneeded private variables and an additional iteration inside the main loop.&lt;br /&gt;
&lt;br /&gt;
  [[File:BeforeRefactoring3.PNG]]&lt;br /&gt;
&lt;br /&gt;
After refactoring:&lt;br /&gt;
&lt;br /&gt;
 [[File:AfterRefactor2.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Addition of code comments and unit tests ==&lt;br /&gt;
&lt;br /&gt;
In addition to the refactoring performed to DRY up the ReviewResponseMap.rb methods we added missing tests for the existing methods and restructured the pre-existing tests to use fixtures.  The following fixture files were added during the process:&lt;br /&gt;
&lt;br /&gt;
* assignment_questionnaires.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* questionnaired.yml&lt;br /&gt;
* response_maps.yml&lt;br /&gt;
* responses.yml&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml&lt;br /&gt;
&lt;br /&gt;
To run the unit tests, ADD INSTRUCTIONS HERE&lt;br /&gt;
&lt;br /&gt;
We also added method comments to all of the methods in the ReviewResponseMap.rb file and corrected instances where CodeClimate Identified opportunities for code improvement.  One issue flagged by CodeClimate that we did not change was to use the find_by method instead of where().first. However it is not always appropriate to use the find_by method, as documented in this github post: &lt;br /&gt;
&lt;br /&gt;
https://github.com/bbatsov/rubocop/issues/1938&lt;br /&gt;
&lt;br /&gt;
In instances where ordering by id is the desired behavior, where().first will do by default, whereas in Rails 4+ find_by does not honor that default behavior.  For this reason we left the instances of where().first unchanged.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
# [https://github.com/expertiza/expertiza Expertiza Main Repo]&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/blob/develop/app/models/review_response_map.rb Refactored ReviewResponseMap.rb]&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/tree/develop/test/fixtures Test Fixtures]&lt;br /&gt;
# [https://github.com/adeeshag/expertiza/blob/develop/test/unit/review_response_map_test.rb Unit Tests]&lt;br /&gt;
# [https://codeclimate.com/ CodeClimate]&lt;/div&gt;</summary>
		<author><name>Aankara</name></author>
	</entry>
</feed>