CSC/ECE 517 Fall 2023 - E2366. Reimplement assignment model and assignment controller

From Expertiza_Wiki
Jump to navigation Jump to search

Expertiza

Expertiza is a Ruby on Rails based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.

Problem Statement

A reimplementation was required for assignment model and assignment controller. The following tasks were required for the reimplementation :

  1. Creating necessary associations between assignment model and other models such as course, participants, instructor.
  2. Reimplementation for the following methods in assignment model and necessary controller actions and routes :
    • add_participant  : Allows a user with an appropriate role to add a participant to an assignment
    • remove_participant  : Allows a user with an appropriate role to remove a participant from an assignment.
    • assign_courses_to_assignment  : Associates the assignments with a given course.
    • remove_assignment_from_course : Dissociates an assignment from a course.
    • copy_assignment  : Creates a copy of an assignment
    • delete  : CRUD operation for deleting the assignment and necessary dependencies.
    • Writing rspec and rswag test case for assignment model and controller respectively.


Tasks Completed

Migrations - Before starting with the implementation, we created necessary migrations for fixing up the schema. The fields course_id and instructor_id were added to the Assignment Model as attributes instead of being added as foreign key references. Hence necessary migrations were created for removing these fields and adding them as references to the Assignment model.

The following migration files were added : 20231104070639_remove_instructor_id_from_assignments.rb 20231104071922_add_instructor_to_assignments.rb 20231105193016_remove_course_id_from_assignments.rb 20231105193219_add_course_to_assignments.rb

Models -

Assignment_Participant A new model - Assignment_Participant was added as it was missing from the current implementation. This model was required for implementing the add_participant method.

Assignment.rb -

  1. We followed the single responsibility principle where all the methods relevant to assignment instances were implemented in the Assignment model.
  2. The method ‘set_handle’ required as a sub-method for add_participant method was moved to assignment_participant.rb as it is used for setting the handle for a participant instance.
  3. A separate method for deleting the assignment was also not needed in the new implementation as it is already being fulfilled by the CRUD operation in the assignment controller.
  4. The implementation for assign_course_to_assignment seemed incorrect as it was only setting @course variable with the course having course_id. We added the correct method to the new implementation where course_id was assigned to the assignment.


Documentation for methods that were re-implemented:

  • add_participant
    • HTTP Method: POST
    • Endpoint: api/v1/{assignment_id}/add_participant/{user_id}
    • Input: assignment_id, user_id
    • Output: Response code and JSON of assignment participant
    • Description: It allows super admins, admins, instructors, and teaching assistants to add a particular participant (student) from the given assignment.
  • remove_participant
    • HTTP Method: DELETE
    • Endpoint: api/v1/{assignment_id}/remove_participant/{user_id}
    • Input: assignment_id, user_id
    • Output: Response code
    • Description: It allows super admins, admins, instructors, and teaching assistants to remove a particular participant (student) from the given assignment.
  • remove_assignment_from_course
    • HTTP Method: PATCH
    • Endpoint: api/v1/{assignment_id}/remove_assignment_from_course
    • Input: assignment_id
    • Output: Response code and JSON of updated assignment
    • Description: It makes the course_id of the given assignment null (removes the assignment from its course).
  • assign_courses_to_assignment
    • HTTP Method: PATCH
    • Endpoint: api/v1/{assignment_id}/assign_courses_to_assignment/{course_id}
    • Input: assignment_id, course_id
    • Output: Response code and JSON of updated assignment
    • Description: It assigns the given course_id to the given assignment.
  • destroy(delete_assignment)
    • HTTP Method: DELETE
    • Endpoint:api/v1/assignment/{assignment_id}
    • Input: assignment_id
    • Output: Response code
    • Description: It deletes the specified assignment.
  • copy_assignment
    • HTTP Method: POST
    • Endpoint: api/v1/{assignment_id}/copy_assignment
    • Input: assignment_id
    • Output: Response code and JSON of copied assignment.
    • Description: It copies the assignment and stores the copy with the name “Copy of” + the original assignment name.

Controller - Assignment_Controller.rb For the new methods added in the assignment model, we added corresponding actions in the assignment controller with the same name and routes in config.rb as mentioned in above documentation.


Files added / modified

  • reimplementation-back-end/blob/main/app/models/course.rb
  • reimplementation-back-end/blob/main/app/models/assignment.rb
  • reimplementation-back-end/blob/main/app/models/assignment_participant.rb
  • reimplementation-back-end/blob/main/app/controllers/api/v1/assignments_controller.rb
  • reimplementation-back-end/blob/main/config/routes.rb
  • reimplementation-back-end/blob/main/spec/models/assignment_spec.rb
  • reimplementation-back-end/blob/main/spec/factories/factories.rb
  • reimplementation-back-end/blob/main/db/schema.rb

Test Plan

This testing plan outlines 10 test cases to validate the functionality of the Assignment Model.

  • Adding a Participant

Steps: Create a user and assignment, call add_participant, check for an increase in Assignment Participants count, and verify correct association
Outcome: Pass if a user is added as a participant.

  • Error When Adding Non-Existing Participant

Steps: Create an assignment, call add_participant with a non-existing user ID, expect a RuntimeError, and check the AssignmentParticipants count remains unchanged.
Outcome: Pass if an error is raised and no participant is added when the user does not exist.

  • Error When Adding Duplicate Participant

Steps: Create a user and assignment, add the user as a participant, try to add the same user again, expect a RuntimeError, and check no duplicate participant is added.
Outcome: Pass if an error is raised and no duplicate participant is added.

  • Removing a Participant

Steps: Create an assignment and user, add the user as a participant, call remove_participant, check for a decrease in AssignmentParticipants count, and ensure the participant is removed.
Outcome: Pass if a participant is successfully removed.

  • Trying to Remove a Non-Participant

Steps: Create an assignment and user, attempt to remove a non-participant, and ensure the AssignmentParticipants count remains unchanged.
Outcome: Pass if no participant is removed when trying to remove a non-participant.

  • Successful Assignment of Course

Steps: Create a new assignment and a course, call .assign_courses_to_assignment, and check if the assignment's course_id is set correctly.
Outcome: Pass if the course is successfully assigned to the assignment.

  • Error on Reassignment

Steps: Create a new assignment and a course, set the assignment's course_id to the course's ID, try to assign the same course again, and expect an error with a specific message.
Outcome: Pass if an error is raised when trying to reassign the same course.

  • Removing Assignment from Course

Steps: Create an assignment and course, assign the course to the assignment, call remove_assignment_from_course, and verify the course_id is set to nil and the modified assignment is returned.
Outcome: Pass if the course is successfully removed, and the modified assignment is returned.

  • Error on removing course when course_id is nil

Steps: Create a new assignment and a course, try removing a course from an assignment when course_id is already nil.
Outcome: Pass if an error is raised when trying to remove a course when course_id is nil.


  • Copying an Assignment

Steps: Create an assignment, call copy_assignment, and verify the copied assignment has a new name and retains other properties.
Outcome: Pass if a copy of the assignment with a new name is successfully created.


Here is a video of successfully running the test cases: [1]

Manual Testing Using POSTMAN

Postman was used for manually testing the added method in assignment.rb and their respective controllers actions and routes. Before testing any of these methods using Postman, a request to /login needs to be sent with user_name an password fields which sends a authentication token. This token needs to be added in Postman’s ‘Authorization’ tab as ‘Bearer token’ before any further requests can be made.


  • add_participant - POSTMAN

  • new participant created - rails console

  • remove_participant - POSTMAN

  • remove_assignment_from_course - POSTMAN

  • assign_courses_to_assignment - POSTMAN

  • destroy(delete_assignment) - POSTMAN

  • Copy_assignment- POSTMAN

  • Original Assignment - rails console

  • Copied Assignment - rails console


Team

Mentor
  • Ameya Vaichalkar
Members
  • Bhavya Harchandani <bharcha@ncsu.edu>
  • Akshat Saxena<asaxen24@ncsu.edu>
  • Mitali Sethi <msethi@ncsu.edu>

Pull Request

References