CSC/ECE 517 Spring 2023 - E2333. Generalize review versioning

From Expertiza_Wiki
Revision as of 23:28, 7 April 2023 by Psangan (talk | contribs) (Created page with "== Team== === Mentor === * Jialin Cui === Team Members === * Aman Waoo * Girish Wangikar * Pranavi Sharma Sanganabhatla == Description and Testing == Our project deals wit...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Team

Mentor

  • Jialin Cui

Team Members

  • Aman Waoo
  • Girish Wangikar
  • Pranavi Sharma Sanganabhatla

Description and Testing

Our project deals with refactoring the answer.rb file. The code is responsible for doing the following tasks:

  • To design and implement an answsers_by_response method that returns answers in each response.
  • Get the answer model fully tested.

Files Involved

  • answer.rb
  • answer_spec.rb

Running Tests

To successfully run answer_spec on the local machine, please run the below rspec command.

  rspec spec/answer_spec.rb


Project Description

The objective of the project is to refactor the following Ruby on Rails model classes in the existing project:- Answer Model on Expertiza.The model is designed to represent answers to questions in Expertiza. So, whenever anyone fills out a rubric, each “question” that is answered creates a new Answer object.

The task is to refactor the existing code present in the model file and implement them in a new repository. Since the project is implemented from scratch, there are various aspects of the project that have to be implemented and therefore unit test cases are implemented to test the implementation.


  • answers_by_question_for_reviewee_in_round:
 1. This method joins the responses, answers, response_maps, and questions table. 
 2. Then it applies a where clause to filter the results based on the given assignment_id, reviewee_id, q_id, and round parameters. 
 3. It retrieves answers and comments columns from the combined table. 


Code Snippet:

   scope :by_question_for_reviewee_in_round, -> (assignment_id, reviewee_id, q_id, round) do
      joins(response: {map: :reviewer})
      .joins(:question)
      .where("review_maps.reviewed_object_id = ? AND
              review_maps.reviewee_id = ? AND
              answers.question_id = ? AND
              responses.round = ?", assignment_id, reviewee_id, q_id, round)
      .select(:answer, :comments)
  end


  • answers_by_question:
 1. This method joins the questions, answers, responses, and response_maps table. 
 2. Then it applies a where clause to filter the results based on the given q_id and assignment_id. 
 3. It retrieves the distinct answers and comments columns from the combined table. 

Code Snippet:

   scope :by_question, -> (assignment_id, q_id) do
       joins(response: {map: :reviewer})
       .joins(:question)
       .where("review_maps.reviewed_object_id = ? AND
             answers.question_id = ?", assignment_id, q_id)
       .select(:answer, :comments)
       .distinct
   end


  • answers_by_question:
 1. This method joins the responses, answers, response_maps, and questions table.  
 2. Then it applies a where clause to filter the results based on the given assignment_id, reviewee_id and q_id.  
 3. It retrieves answers and comments columns from the combined table.


Code Snippet:

   scope :by_question, -> (assignment_id, q_id) do
       joins(response: {map: :reviewer})
       .joins(:question)
       .where("review_maps.reviewed_object_id = ? AND
             answers.question_id = ?", assignment_id, q_id)
       .select(:answer, :comments)
       .distinct
   end

Test Plan

We have implemented test cases using RSpec for different validation checks for answer.rb.

Code Snippet:

 require '/Users/aw/Documents/Course Study Material/OODD/Program 3/spec/rails_helper.rb'
 require '/Users/aw/Documents/Course Study Material/OODD/Program 3/spec/spec_helper.rb'
 RSpec.describe Answer, type: :model do
   describe ".by_question_for_reviewee_in_round" do
     let(:assignment) { create(:assignment) }
     let(:reviewer) { create(:user) }
     let(:reviewee) { create(:user) }
     let(:round) { 1 }
     let(:question) { create(:question, assignment: assignment) }
     let(:response_map) { create(:review_map, reviewed_object: assignment, reviewer: reviewer, reviewee: reviewee) }
     let(:response) { create(:response, map: response_map, round: round) }
     let!(:answer) { create(:answer, question: question, response: response) }
     it "returns the answer and comments for the specified question, reviewee, assignment, and round" do
       expect(Answer.by_question_for_reviewee_in_round(assignment.id, reviewee.id, question.id, round))
         .to match_array([{answer: answer.answer, comments: answer.comments}])
    end
  end
 describe ".by_question" do
   let(:assignment) { create(:assignment) }
   let(:reviewer) { create(:user) }
   let(:question) { create(:question, assignment: assignment) }
   let(:response_map) { create(:review_map, reviewed_object: assignment, reviewer: reviewer) }
   let(:response) { create(:response, map: response_map) }
   let!(:answer) { create(:answer, question: question, response: response) }
   it "returns the answer and comments for the specified question and assignment" do
     expect(Answer.by_question(assignment.id, question.id))
       .to match_array([{answer: answer.answer, comments: answer.comments}])
   end
 end
 describe ".by_question_for_reviewee" do
   let(:assignment) { create(:assignment) }
   let(:reviewer) { create(:user) }
   let(:reviewee) { create(:user) }
   let(:question) { create(:question, assignment: assignment) }
   let(:response_map) { create(:review_map, reviewed_object: assignment, reviewer: reviewer, reviewee: reviewee) }
   let(:response) { create(:response, map: response_map) }
   let!(:answer) { create(:answer, question: question, response: response) }
   it "returns the answer and comments for the specified question, reviewee, and assignment" do
     expect(Answer.by_question_for_reviewee(assignment.id, reviewee.id, question.id))
       .to match_array([{answer: answer.answer, comments: answer.comments}])
   end
 end
 describe ".by_response" do
   let(:response) { create(:response) }
   let!(:answer) { create(:answer, response: response) }
   it "returns the answer for the specified response" do
     expect(Answer.by_response(response.id)).to eq([answer.answer])
   end
 end
end

Test Execution

We divided the work among the teammates and started tackling the problems. We stubbed the data using the factory and mocked the method calls which were being done internally to get the desired output from the methods that were calling other methods internally.


Conclusion

We have refactored the code in the answer.rb file to return answers in each response. We have tested the model fully and attaching the video of the passed test cases in the submission.