CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps

From Expertiza_Wiki
Jump to navigation Jump to search

Description about project

This page is a description of Expertiza final project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:

  • In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed. The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.

The breakdown of the ResponseMap model can be found here. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:

  • review_response_map.rb <--------- 92.5% coverage
  • metareview_response_map.rb <------ 81.48% coverage
  • teammate_review_response_map.rb <- 94.74% coverage
  • response_map.rb <----------------- 96.45% coverage

This project aimed to get all the response maps to at least a 80% level of coverage for every Response Map file by writing unit tests for each uncovered method listed in the next section.

Team

  • Connor Smith (cpsmith6)
  • Abir Majumder (aamajumd)
  • Quinn Dibble (qdibble)
  • Alex Carruth (agcarrut)

Test Files Involved

There are 4 test files involved in this project:

  • review_response_map_spec.rb
  • metareview_response_map_spec.rb
  • teammate_review_response_map_spec.rb
  • response_map_spec.rb

of these files, only review_response_map_spec.rb currently exists; the rest will be added.

Methods Tested Per File

review_response_map_spec.rb

review_response_map.rb was originally 92.5% covered, therefore no extra tests were written.

metareview_response_map_spec.rb

The functions for metareview_response_map.rb that will be tested are:

get_all_versions

This returns a sorted array of all the different versions of what is being reviewed in this response map. This means for a test, we will need to create a reviewer, a reviewee, several types of reviews of different versions to be sorted correctly.

function: get_all_versions

# return all the versions available for a response map.
  # a person who is doing meta review has to be able to see all the versions of review.
  def get_all_versions
    if self.review_mapping.response
      @sorted_array = []
      @prev = Response.all
      @prev.each do |element|
        @sorted_array << element if element.map_id == self.review_mapping.map_id
      end
      @sorted = @sorted_array.sort {|m1, m2| m1.version_num || if m2.version_num
                                                                  m1.version_num <=> m2.version_num
                                                                else
                                                                  m1.version_num ? -1 : 1
                                                                end }
      # return all the lists in ascending order.
      @sorted
    end
  end

test: get_all_versions

      it 'finds version numbers' do
        allow(Response).to receive(:find).and_return(response)
        allow(MetareviewResponseMap).to receive(:where).and_return([metareview_response_map])
        expect(metareview_response_map.get_all_versions).to eq([])
      end

contributor

Returns the team associated with the ReviewResponseMap that is to be metareviewed. We will need to create a ReviewResponseMap that has a team associated with it. Then we must create MetareviewResponseMap that points to a created ReviewResponseMap via the reviewed_object_id attribute. We will test if it indeed returns the team associated with ReviewResponseMap.

function: contributor

# First, find the "ReviewResponseMap" to be metareviewed;
  # Second, find the team in the "ReviewResponseMap" record.
  def contributor
    team_review_map = ReviewResponseMap.find(self.reviewed_object_id)
    AssignmentTeam.find(team_review_map.reviewee_id)
  end

test: contributor

      it 'finds the contributor of the metareview' do
        allow(Response).to receive(:find).and_return(response)
        allow(MetareviewResponseMap).to receive(:where).and_return([metareview_response_map])
        allow(AssignmentTeam).to receive(:find).with(1).and_return(team)
        expect(metareview_response_map.contributor).to eq(team)
      end

questionnaire

Returns all questionnaires associated to the assignment of this MetareviewResponseMap that is of type 'MetareviewQuestionnaire'. We will need to create a valid MetareviewResponseMap including at least one MetareviewQuestionnaire that can be returned. Currently the implementation of this method makes it impossible to test, so no test has been written.

function: questionnaire

def questionnaire
    self.assignment.questionnaires.find_by(type: 'MetareviewQuestionnaire')
end

get_title

Returns string "Metareview". We test if this string is the same as typed out.

function: get_title

def get_title
    "Metareview"
end

test: get_title

      it 'finds title' do
        allow(Response).to receive(:find).and_return(response)
        allow(MetareviewResponseMap).to receive(:where).and_return([metareview_response_map])
        expect(metareview_response_map.get_title).to eq("Metareview")
      end

exports

This function takes 3 parameters: csv (the csv file that will contain the exported metareview information), parent_id (the assignment ID containing the requested metareviews), and _options. The function sends all the information about the metareviews to a csv file. We test that the information is properly exported to the csv file.

function: export

  def self.export(csv, parent_id, _options)
    mappings = Assignment.find(parent_id).metareview_mappings
    mappings = mappings.sort_by {|a| [a.review_mapping.reviewee.name, a.reviewee.name, a.reviewer.name] }
    mappings.each do |map|
      csv << [
        map.review_mapping.reviewee.name,
        map.reviewee.name,
        map.reviewer.name
      ]
    end
  end

test: export

      it '#export' do
        csv = []
        parent_id = 1
        options = nil
        allow(Response).to receive(:find).and_return(response)
        allow(MetareviewResponseMap).to receive(:find_by).and_return(metareview_response_map)
        allow(Assignment).to receive(:find).and_return(assignment)
        allow(Assignment).to receive(:metareview_mappings).and_return(metareview_response_map)
        expect(MetareviewResponseMap.export(csv, parent_id, options)).to eq([metareview_response_map])
      end

export_fields

Takes a parameter called "_options" that returns the three field columns associated with metareviews to be exported for use by other controllers. We test to see that these three columns are properly returned.
function: export_fields

  def self.export_fields(_options)
    fields = ["contributor", "reviewed by", "metareviewed by"]
    fields
  end

test: export_fields

      it 'finds fields' do
        allow(Response).to receive(:find).and_return(response)
        allow(MetareviewResponseMap).to receive(:where).and_return([metareview_response_map])
        expect(MetareviewResponseMap.export_fields(nil)).to eq(["contributor", "reviewed by", "metareviewed by"])
      end

import

This function takes 3 parameters: row_hash (represents the hash of the metareview data we want to import), session, and id (representing the id of the assignment we want to import metareview data for). The function imports the data from the hash map, and if the information is input correctly, the data is extracted from the hash and creates a metareview for the requested assignment, otherwise it flashes an error saying the data was input incorrectly. We will test to make sure the imported data is properly converted into a metareview. The last error check of the function ("No review mapping was found for contributor, #{contributor.name}, and reviewee, #{row_hash[:reviewer].to_s}." if reviewmapping.nil?) is impossible to reach in the function. This is because if the conditions to raise this error are met, a prior line in the code would have raised an error and exited first. Because this line is impossible to reach, it is impossible to test and the testing for it is commented out.
function: import

  def self.import(row_hash, session, id)
    raise ArgumentError.new("Not enough items. The string should contain: Author, Reviewer, ReviewOfReviewer1 <, ..., ReviewerOfReviewerN>") if row_hash.length < 3
    row_hash[:metareviewers].each do |row|
      # ACS Make All contributors as teams
      contributor = AssignmentTeam.where(name: row_hash[:reviewee].to_s, parent_id:  id).first
      raise ImportError, "Contributor, " + row_hash[:reviewee].to_s + ", was not found."  if contributor.nil?
      ruser = User.find_by_name(row_hash[:reviewer].to_s.strip)
      reviewee = AssignmentParticipant.where(user_id: ruser.id, parent_id:  id).first
      raise ImportError, "Reviewee,  #{row_hash[:reviewer].to_s}, for contributor, #{contributor.name}, was not found." if reviewee.nil?
      muser = User.find_by_name(row.to_s.strip)
      puts muser.name
      reviewer = AssignmentParticipant.where(user_id: muser.id, parent_id:  id)
      raise ImportError, "Metareviewer,  #{row.to_s}, for contributor, #{contributor.name}, and reviewee, #{row_hash[:reviewer].to_s }, was not found." if reviewer.nil?
      # ACS Removed the if condition(and corressponding else) which differentiate assignments as team and individual assignments
      # to treat all assignments as team assignments
      reviewmapping = ReviewResponseMap.where(reviewee_id: contributor.id, reviewer_id:  reviewee.id)
      # puts reviewee.id
      puts reviewer.id
      raise ImportError, "No review mapping was found for contributor, #{contributor.name}, and reviewee, #{row_hash[:reviewer].to_s}." if reviewmapping.nil?
      existing_mappings = MetareviewResponseMap.where(reviewee_id: reviewee.id, reviewer_id: reviewer.id, reviewed_object_id: reviewmapping.map_id)
      # if no mappings have already been imported for this combination
      # create it.
      MetareviewResponseMap.create(reviewer_id: reviewer.id, reviewee_id: reviewee.id, reviewed_object_id: reviewmapping.map_id) if existing_mappings.empty?
    end
  end

test: import

   it '#import' do
        row_hash = {reviewee: "name", metareviewers: ["name1"]}
        session = nil
        assignment_id = 1
        # when reviewee user = nil
        allow(User).to receive(:find_by).and_return(nil)
        expect { MetareviewResponseMap.import(row_hash, session, 1) }.to raise_error(ArgumentError, "Not enough items. The string should contain: Author, Reviewer, ReviewOfReviewer1 <, ..., ReviewerOfReviewerN>")
        # when reviewee user doesn't exist
        row_hash = {reviewee: "name", metareviewers: ["name1"], reviewer: "name1"}
        allow(User).to receive(:find_by).with(name: "name1").and_return(student)
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 1).and_return(nil)
        expect { MetareviewResponseMap.import(row_hash, session, 1) }.to raise_error(ImportError, "Contributor, " + row_hash[:reviewee].to_s + ", was not found.")
        # when a metareview response map is created
        allow(User).to receive(:find_by).with(name: "name2").and_return(student2)
        allow(AssignmentParticipant).to receive(:where).with(user_id: 3, parent_id: 1).and_return([participant])
        allow(AssignmentTeam).to receive(:where).with(name: "name", parent_id: 1).and_return([team])
        allow(AssignmentParticipant).to receive(:where).with(user_id: 1, parent_id: 1).and_return([student])
        row_hash = {reviewee: "name", metareviewers: ["name1"], reviewer: "name2"}
        expect { MetareviewResponseMap.import(row_hash, session, 1).to eq(metareview_response_map) }
        ## when reviewer user doesn't exist
        allow(User).to receive(:find_by).with(name: "name2").and_return(student2)
        allow(AssignmentParticipant).to receive(:where).with(user_id: 3, parent_id: 1).and_return([participant])
        allow(AssignmentTeam).to receive(:where).with(name: "name", parent_id: 1).and_return([team])
        allow(AssignmentParticipant).to receive(:where).with(user_id: 1, parent_id: 1).and_return(nil)
        row_hash = {reviewee: "name", metareviewers: ["name1"], reviewer: "name2"}
        expect { MetareviewResponseMap.import(row_hash, session, 1) }.to raise_error(ImportError, "Metareviewer,  name1, for contributor, team no name, and reviewee, name2, was not found.")
        # # when a review response map is created
        # allow(User).to receive(:find_by).with(name: "name2").and_return(student2)
        # allow(AssignmentParticipant).to receive(:where).with(user_id: 3, parent_id: 1).and_return([participant])
        # allow(AssignmentTeam).to receive(:where).with(name: "name", parent_id: 1).and_return([team])
        # allow(AssignmentParticipant).to receive(:where).with(user_id: 1, parent_id: 1).and_return([student])
        # allow(ReviewResponseMap).to receive(:find_or_create_by)
        #                                 .with(reviewed_object_id: 1, reviewer_id: 2, reviewee_id: 1, calibrate_to: false)
        #                                 .and_return(nil)
        # expect { MetareviewResponseMap.import(row_hash, session, 1) }.to raise_error(ImportError, "No review mapping was found for contributor, , and reviewee, #{row_hash[:reviewer].to_s}.")

      end

email

This function takes 3 parameters: defn, _participant (the user who will be receiving the email), and assignment (the assignment associated with the metareview). The function sends an email to the participant when they have a new metareview to complete. We test to make sure the email is sent to the correct participant.
function: email

  def email(defn, _participant, assignment)
    defn[:body][:type] = "Metareview"
    reviewee_user = Participant.find(reviewee_id)
    defn[:body][:obj_name] = assignment.name
    defn[:body][:first_name] = User.find(reviewee_user.user_id).fullname
    defn[:to] = User.find(reviewee_user.user_id).email
    Mailer.sync_message(defn).deliver
  end

test: email

 it '#email' do
        reviewer_id = 1
        allow(Participant).to receive(:find).with(1).and_return(participant)
        allow(Assignment).to receive(:find).with(1).and_return(assignment)
        allow(AssignmentTeam).to receive(:find).with(1).and_return(team)
        allow(AssignmentTeam).to receive(:users).and_return(student)
        allow(User).to receive(:find).with(1).and_return(student)
        review_response_map.reviewee_id = 1
        defn = {body: {type: "Metareview", obj_name: "Test Assgt", first_name: "no one", partial_name: "new_submission"}, to: "expertiza@mailinator.com"}
        expect { metareview_response_map.email(defn, participant, Assignment.find(Participant.find(reviewer_id).parent_id)) }
            .to change { ActionMailer::Base.deliveries.count }.by 1
      end

teammate_review_response_map_spec.rb

The functions for teammate_review_response_map.rb that will be tested are:

questionnaire

This function searches for a TeammateReviewQuestionnaire object and returns it. The implementation of this method is inconsistent with the implementation of the questionnaire method in other classes, and uses find_by which always returns nil; because of this the questionnaire method is impossible to test, so the test that has been written is commented out.
A band-aid solution is to modify questionnaire such that find_by is replaced with where!, and in that case the test can be uncommented and it passes.
function: questionnaire

  def questionnaire
    self.assignment.questionnaires.find_by(type: 'TeammateReviewQuestionnaire')
  end

commented test: questionnaire (for use when questionnaire is fixed)

  # describe '#questionnaire' do
  #   # This method is little more than a wrapper for assignment.review_questionnaire_id()
  #
  #   context 'when corresponding active record for assignment_questionnaire is found' do
  #     before(:each) do
  #       allow(AssignmentQuestionnaire).to receive(:where).with(assignment_id: assignment.id).and_return(
  #           [assignment_teammate_questionnaire1, assignment_teammate_questionnaire2])
  #       allow(Questionnaire).to receive(:find).with(1).and_return(assignment_teammate_questionnaire1)
  #     end
  #
  #     it 'returns correct questionnaire found by used_in_round and topic_id if both used_in_round and topic_id are given' do
  #       allow(AssignmentQuestionnaire).to receive(:where).with(assignment_id: assignment1.id, used_in_round: 1, topic_id: 1).and_return(
  #           [assignment_teammate_questionnaire1])
  #       allow(Questionnaire).to receive(:find_by!).with(type: 'TeammateReviewQuestionnaire').and_return([teammate_questionnaire1])
  #       #allow(Questionnaire).to receive(:where!).and_return([teammate_questionnaire1])
  #       assignment1.questionnaires = [teammate_questionnaire1, teammate_questionnaire2]
  #       expect(teammate_review_response_map1.questionnaire()).to eq(teammate_questionnaire1)
  #     end
  #
  #   end
  # end

get_title

This function returns the string "Teammate Review". We test if this string is the same as typed out.

function: get title

  def get_title
    "Teammate Review"
  end

test: get_title

  
   describe '#get_title' do
    context 'when get_title is called' do
      it '#get_title' do
        expect(teammate_review_response_map1.get_title).to eq("Teammate Review")
      end
    end
  end

teammate_response_report

This function returns the teammate response report given the reviewer ID. We test that the function returns the corresponding teammate response report given a reviewer ID.
function: teammate_response_report

  def self.teammate_response_report(id)
    TeammateReviewResponseMap.select("DISTINCT reviewer_id").where("reviewed_object_id = ?", id)
  end

test: teammate_response_report

  describe '#teammate_response_report' do
    context 'return an assignment given an id' do
      it '#teammate_response_report' do
        allow(TeammateReviewResponseMap).to receive_message_chain(:select, :where).and_return(assignment1);
        expect(TeammateReviewResponseMap.teammate_response_report(2)).to eq(assignment1);
      end
    end
  end

email

This function sends a notification email to a student who has been reviewed by their teammate. The function sends an email to the participant when they have a new teammate review to complete. We test to make sure the email is sent to the correct participant.
function: email

  # Send Teammate Review Emails
  # Refactored from email method in response.rb
  def email(defn, participant, assignment)
    defn[:body][:type] = "Teammate Review"
    participant = AssignmentParticipant.find(reviewee_id)
    topic_id = SignedUpTeam.topic_id(participant.parent_id, participant.user_id)
    defn[:body][:obj_name] = assignment.name
    user = User.find(participant.user_id)
    defn[:body][:first_name] = user.fullname
    defn[:to] = user.email
    Mailer.sync_message(defn).deliver
  end

test: email

  describe '#email' do
    context 'when an email notification is sent' do
      it '#email' do
        reviewer_id = 1
        allow(AssignmentParticipant).to receive(:find).with(2).and_return(participant)
        allow(Assignment).to receive(:find).with(1).and_return(assignment)
        allow(AssignmentTeam).to receive(:find).with(1).and_return(team)
        allow(AssignmentTeam).to receive(:users).and_return(student)
        allow(User).to receive(:find).with(1).and_return(student)
        review_response_map.reviewee_id = 1
        defn = {body: {type: "TeammateReview", obj_name: "Test Assgt", first_name: "no one", partial_name: "new_submission"}, to: "expertiza@mailinator.com"}
        expect { teammate_review_response_map1.email(defn, participant, Assignment.find(Participant.find(reviewer_id).parent_id)) }
            .to change { ActionMailer::Base.deliveries.count }.by 1
      end
    end
  end

response_map_spec.rb

The functions for response_map.rb that will be tested are:

self.assessments_for(team)

Gets all submitted Review Responses or all regular Responses for a team, sorts the responses by version, and returns the latest Responses. We test that it is able to get only assessments for submitted responses and assessments for other types of response maps.

function: assessments_for

  # return latest versions of the responses
  def self.assessments_for(team)
    responses = []
    # stime = Time.now
    if team
      @array_sort = []
      @sort_to = []
      maps = where(reviewee_id: team.id)
      maps.each do |map|
        next if map.response.empty?
        @all_resp = Response.where(map_id: map.map_id).last
        if map.type.eql?('ReviewResponseMap')
          # If its ReviewResponseMap then only consider those response which are submitted.
          @array_sort << @all_resp if @all_resp.is_submitted
        else
          @array_sort << @all_resp
        end
        # sort all versions in descending order and get the latest one.
        # @sort_to=@array_sort.sort { |m1, m2| (m1.version_num and m2.version_num) ? m2.version_num <=> m1.version_num : (m1.version_num ? -1 : 1) }
        @sort_to = @array_sort.sort # { |m1, m2| (m1.updated_at and m2.updated_at) ? m2.updated_at <=> m1.updated_at : (m1.version_num ? -1 : 1) }
        responses << @sort_to[0] unless @sort_to[0].nil?
        @array_sort.clear
        @sort_to.clear
      end
      responses = responses.sort {|a, b| a.map.reviewer.fullname <=> b.map.reviewer.fullname }
    end
    responses
  end

test: assessments_for

  describe 'self.assessments_for' do
    context 'Getting assessments for Review Response map' do
      it 'returns only submitted responses' do
        allow(Team).to receive(:find).and_return(team)
        allow(ResponseMap).to receive(:where).with(reviewee_id: team.id).and_return([review_response_map, review_response_map1])
        allow(Response).to receive(:where).with(map_id: 1).and_return([response])
        allow(Response).to receive(:where).with(map_id: 2).and_return([response1])
        responses = ResponseMap.assessments_for(team)
	expect(responses).to eq([response])
      end
    end

    context 'Getting assessments for other Response maps' do
      it 'returns all responses' do
        allow(Team).to receive(:find).and_return(team1)
        allow(ResponseMap).to receive(:where).with(reviewee_id: participant2.id).and_return([teammate_review_response_map, teammate_review_response_map1])
        allow(Response).to receive(:where).with(map_id: 3).and_return([response2])
        allow(Response).to receive(:where).with(map_id: 4).and_return([response3])
        responses = ResponseMap.assessments_for(participant2)
	expect(responses).to eq([response2, response3])
      end
    end

  end

self.reviewer_assessments_for(team, reviewer)

Gets the Responses for a team reviewed by a specific reviewer and returns the latest response. We test that it returns the results with the latest version number.
function: reviewer_assessments_for

  # return latest versions of the response given by reviewer
  def self.reviewer_assessments_for(team, reviewer)
    # get_reviewer may return an AssignmentParticipant or an AssignmentTeam
    map = where(reviewee_id: team.id, reviewer_id: reviewer.get_reviewer.id)
    Response.where(map_id: map).sort {|m1, m2| self.comparator(m1, m2) }[0]
  end

test: reviewer_assessments_for

  describe 'self.reviewer_assessments_for' do
    context 'Returning latest version of responses by reviewer' do
      it 'returns the second response' do
        allow(ResponseMap).to receive(:where).with(reviewee_id: team2.id, reviewer_id: participant2.id ).and_return([review_response_map2])
        allow(Response).to receive(:where).with(map_id: review_response_map2.id).and_return([response4, response5])
        responses = ResponseMap.reviewer_assessments_for(team2, participant2)
	expect(responses).to eq(response5)
      end
      it 'returns the response with the version number' do
        response4.version_num = 2
        allow(ResponseMap).to receive(:where).with(reviewee_id: team2.id, reviewer_id: participant2.id ).and_return([review_response_map2])
        allow(Response).to receive(:where).with(map_id: review_response_map2.id).and_return([response4, response5])
        responses = ResponseMap.reviewer_assessments_for(team2, participant2)
	expect(responses).to eq(response4)
      end
      it 'returns the response with the highest version number' do
        response4.version_num = 3
        response5.version_num = 2
        allow(ResponseMap).to receive(:where).with(reviewee_id: team2.id, reviewer_id: participant2.id ).and_return([review_response_map2])
        allow(Response).to receive(:where).with(map_id: review_response_map2.id).and_return([response4, response5])
        responses = ResponseMap.reviewer_assessments_for(team2, participant2)
	expect(responses).to eq(response4)
      end
    end

  end

metareviewed_by?

Returns whether the Response Map has been metareviewed. We test that it returns true when itself (the response map) has been metareviewed.
function: metareviewed_by?

  # Evaluates whether this response_map was metareviewed by metareviewer
  # @param[in] metareviewer AssignmentParticipant object
  def metareviewed_by?(metareviewer)
    MetareviewResponseMap.where(reviewee_id: self.reviewer.id, reviewer_id: metareviewer.id, reviewed_object_id: self.id).count > 0
  end

test: metareviewed_by?

  describe 'metareviewed_by?' do
    context 'Returning whether it is metareviewed' do
      it 'returns true' do
        allow(MetareviewResponseMap).to receive(:where).with(reviewee_id: team.id, reviewer_id: participant1.id, reviewed_object_id: review_response_map.id).and_return([metareview_response_map])
        expect(review_response_map.metareviewed_by?(participant1)).to eq(true)
      end
    end

  end

assign_metareviewer

This function is in charge of assigning a metareviewer to this review (i.e. a reviewer to review the review). We test that it assigns a metareviewer to a review.
function: assign_metareviewer

  # Assigns a metareviewer to this review (response)
  # @param[in] metareviewer AssignmentParticipant object
  def assign_metareviewer(metareviewer)
    MetareviewResponseMap.create(reviewed_object_id: self.id,
                                 reviewer_id: metareviewer.id, reviewee_id: reviewer.id)
  end

test: assign_metareviwer

  describe 'assign_metareviewer' do
    context 'Assigns a metareviewer to a review' do
      it 'creates a metareview response map' do
        metareview_response_map_temp = create(:meta_review_response_map, reviewed_object_id: review_response_map1.id, reviewer_id: participant2.id, reviewee_id: participant1.id)
        allow(MetareviewResponseMap).to receive(:create).with(reviewed_object_id: review_response_map1.id, reviewer_id: participant2.id, reviewee_id: participant1.id).and_return(\
          metareview_response_map_temp)
        expect(review_response_map1.assign_metareviewer(participant2)).to eq(metareview_response_map_temp)
      end
    end

  end

find_team_member

This function returns the team that the reviewer is part of. We test that it finds the corresponding team for a metareview response map and a regular response map.
function: find_team_member

  def find_team_member
    # ACS Have metareviews done for all teams
    if self.type.to_s == "MetareviewResponseMap"
        review_mapping = ResponseMap.find_by(id: map.reviewed_object_id)
        team = AssignmentTeam.find_by(id: review_mapping.reviewee_id)
    else
        team = AssignmentTeam.find(self.reviewee_id)
    end
  end

test: find_team_member

  describe 'find_team_member' do
    context 'Finds the team of a reviewee' do
      it 'finds the team for a metareview response map' do
        allow(ResponseMap).to receive(:find_by).with(id: metareview_response_map.reviewed_object_id).and_return(metareview_response_map)
        allow(AssignmentTeam).to receive(:find_by).with(id: review_response_map.reviewee_id).and_return(team)
        expect(metareview_response_map.find_team_member).to eq(team)
      end
      it 'finds the team for a regular response map' do
        allow(AssignmentTeam).to receive(:find).with(review_response_map.reviewee_id).and_return(team)
        expect(review_response_map.find_team_member).to eq(team)
      end
    end

  end

Running Tests

In the home directory of expertiza, run the following command.

  rspec spec/models/metareview_response_map_spec.rb spec/models/teammate_review_response_map_spec.rb spec/models/response_map_spec.rb spec/models/review_response_map_spec.rb

This should generate a coverage report with the same coverage figures as ours.