CSC/ECE 517 Fall 2017/E1750 Refactor review mapping controller.rb

From Expertiza_Wiki
Jump to navigation Jump to search

About Expertiza

Expertiza is an open source project base on Ruby on Rails framework. It allows students interact with each other through different assignment. It provide service as bidding on project topics, reviewing your teammate for different categories, and submitting assignments online. Expertiza also allows instructors to create assignment with different rubric and creating different topics for assignments that student can bid on.

Test Plan

Test-Driven Development(TDD)

A software development process begin by writes an (initially failing) automated test case that defines a desired improvement or a new function, and generate the minimum amount of code to pass that test. It help the developer to focus on a smaller portions of functionality at a time. Also the refactoring process is safe since it happens after the test is written. Test can also serve as a documentation to a developer.

Project Goal

review_mapping_controller.rb handles peer review response, and author-feedback response which is a complex file. It contains long methods that would be hard to understand. This project focused on breaking down some of the method in a form that would be easier to read/understand. Before starting the refracting task, failing test cases needs to be completed for the corresponding method in the review mapping controller. After completing the refactoring certain method if the review mapping controller then failing test should have a new status of pass.

Steps to Follow

  • Complete pending tests in review_mapping_controller_spec.rb, and write integration tests for newly-created methods.
  • Refactor response_report method
 * focused on breaking down the method into simpler method and simplifying the method 
  • Use find_by instead of dynamic method
  • Use sort_by(&:name) instead of sort { |a, b| a.name <=> b.name }

List of Changes

Files modified

1. review_mapping_controller.rb

  • Refactor methods

2.review_mapping_controller_spec.rb

  • Finished corresponding test for exiting method as well as created new test for newly added method.

Test Finished

Testing on assign_metareviewer_dynamically method which assigns a assignment to the corresponding student. The describe the controller method this test focus on, and that result would be expected from this test.

describe '#assign_metareviewer_dynamically' do
   it 'redirects to student_review#list page' do
     expect(Assignment).to receive(:find).and_return(assignment)
     expect(AssignmentParticipant).to receive(:where).and_return([participant])
     expect(assignment).to receive(:assign_metareviewer_dynamically)
     get :assign_metareviewer_dynamically
     expect(response).to redirect_to ('/student_review/list?id=' +participant.id.to_s)
   end
 end


describe '#add_reviewer and #get_reviewer' do
   context 'when team_user does not exist' do
     it 'shows an error message and redirects to review_mapping#list_mappings page' do
       expect(User).to receive_message_chain("where.first.id").with(any_args).and_return(user.id)
       expect(TeamsUser).to receive(:exists?).with(any_args).and_return(true)
       #expect(flash[:error]).to match "You cannot assign this student to review his/her own artifact"
       post :add_reviewer, :contributor_id => '1', :id =>'1', :topic_id =>'2', user: {name: '2'}
       expect(flash[:error]) =~ /you cannot assign this student to review his.*her own artifact/i
       expect(response).to redirect_to action: 'list_mappings', id: assignment.id
     end
   end
   context 'when team_user exists and get_reviewer method returns a reviewer' do
     it 'creates a whole bunch of objects and redirects to review_mapping#list_mappings page' do
       expect(User).to receive_message_chain("where.first.id").with(any_args).and_return(user.id)
       expect(TeamsUser).to receive(:exists?).with(any_args).and_return(false)
       expect(SignUpSheet).to receive(:signup_team).with(any_args)
       expect(User).to receive(:from_params).with(any_args).and_return(user)
       expect(AssignmentParticipant).to receive_message_chain("where.first").with(any_args).and_return(participant)
       expect(ReviewResponseMap).to receive(:create).with(any_args)
       post :add_reviewer, :contributor_id => '1', :id =>'1', :topic_id =>'2', user: {name: '2'}
       expect(response).to redirect_to action: 'list_mappings', id: assignment.id, msg: 
     end
   end
 end

Conclusion