CSC/ECE 517 Fall 2020 - E2073. Refactor course controller.rb

From Expertiza_Wiki
Revision as of 01:43, 13 October 2020 by Jhnguye4 (talk | contribs)
Jump to navigation Jump to search

Introduction

Expertiza is an open source web application in Ruby on Rails. Its purpose is to allow teachers and students an environment to enhance learning. For teachers, they can use this platform to create, edit, or grade assignments. Students are able to view assignments that teachers have posted, create teams for projects, and review other peers assignments. By having one platform for students and teachers to engage, students are able to stay on top of their tasks and teachers can monitor how well their students are learning the material.

Problem

Background of Course Controller

Courses are an essential part of Expertiza as students and teachers can be grouped together by a course. The course_controller has many important functionalities such as creating, modifying, and deleting courses. It also has other functionalities such as adding, removing, or viewing TA's. When the course_controller is called to create or modify a course, the course's name, institution ID, directory path, or info can be updated. Our task for this assignment is to refactor some of the code in the course_controller file.

Motivation

Why do we want to refactor course_controller? Refactoring is the process of restructuring existing code without changing its behavior. It is important to refactor to keep your code readable, understandable, and clean so that future developers can understand your code when they want to implement or change existing code. For the course_controller, we wanted to refactor it to courses_controller since the current convention of rails requires that controllers be plural. We also wanted to improve readability by removing redundant code in two functions and also fixing a warning message to be more understandable. Lastly we removed a function in course_controller that belonged in a model and not a controller.

Issues that Need to be Fixed

The following tasks were accomplished in this project:
1)The class should be named courses_controller.rb, to follow the current Rails convention that controllers should be named in the plural.
2)Edit the warning message in the copy function
3)Remove duplicate code in the create and update functions
4)Remove create_course_node function as it does not belong in a controller and move it to course_node.rb

Refactors

Issue 1

Issue: The class should be named courses_controller.rb, to follow the current Rails convention that controllers should be named in the plural.
Solution: By changing the name of the class from course_controller.rb to courses_controller.rb, we needed to go through all the files where Course was called and change it to Courses.









Issue 2

Issue: Edit the warning message in the copy function
Solution: When a student submits a file it should be stored at the path that the teacher specifies. If a teacher specifies a path that already has a filed stored then we need to warn the student that the path is already in use and where they should go if they do not want to overwrite the current file.

Issue 3

Issue: Remove duplicate code in the create and update functions
Solution: In the first and second images below, we have removed the redundant code in the create and update functions. We replaced the redundant code with a function called set_courses_fields which we defined in the third image.





Issue 4

Issue: Remove create_course_node function as it does not belong in a controller and move it to course_node.rb
Solution: For the first image, we have removed the course_node function from the courses_controller.rb file. The second image we are in the models folder for course_node.rb and we have moved course_node from course_controller.rb into this file.




Testing

Test Plan

RSpec

UI Testing

Expertiza with E2073

In order to manually test some of the functionalities after refactoring course_controller:

  • Login as instructor. (Username: instructor6, Password: password)

Files Modified

config/routes.rb
app/models/course_node.rb
app/models/course_team.rb
app/controllers/course_controller.rb
app/views/course/_add_individual.html.erb
app/views/course/_course.html.erb
app/views/course/_ta.html.erb
app/views/course/add_ta.js.erb
app/views/course/edit.html.erb
app/views/course/new.html.erb
app/views/course/remove_ta.js.erb
app/views/course/view_teaching_assistants.html.erb
spec/controllers/course_controller_spec.rb
spec/features/course_creation_spec.rb
spec/features/instructor_interface_spec.rb

References

  1. Expertiza GitHub
  2. GitHub Project Repository Fork
  3. Setup Expertiza Environment
  4. Rspec Tutorials

Team Information

Project Mentor:
Sahil Papalkar

Project Members:
Nick Garner
Jonathan Nguyen
Surbhi Jha