CSC/ECE 517 Fall 2021 - E2130. Refactor submitted content controller.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 16: Line 16:


==Problems and Solutions ==
==Problems and Solutions ==
* '''Problem 1''': Remove the comment  “# hence use team count for the check”.
1. '''Problem 1''': Remove the comment  “# hence use team count for the check”.
::The current code no longer checks for the team count to see if a participant belongs to a team. Comment on line #19 removed.
::The current code no longer checks for the team count to see if a participant belongs to a team. Comment on line #19 removed.
2. '''Problem 2''': Change the method name view to something more informative of the method.
::The original code uses the generic 'view' method name to display a view corresponding to a case when submissions cannot be accepted, for instance in the case when a deadline is passed.
<pre>
def view
    @participant = AssignmentParticipant.find(params[:id])
    return unless current_user_id?(@participant.user_id)
    @assignment = @participant.assignment
    # @can_submit is the flag indicating if the user can submit or not in current stage
    @can_submit = false
    @stage = @assignment.get_current_stage(SignedUpTeam.topic_id(@participant.parent_id, @participant.user_id))
    redirect_to action: 'edit', id: params[:id], view: true
  end
</pre>
* '''Solution''': We found changing the name to disable_submission to be more apt in this case
<pre>
def disable_submission
    @participant = AssignmentParticipant.find(params[:id])
    return unless current_user_id?(@participant.user_id)
    @assignment = @participant.assignment
    # @can_submit is the flag indicating if the user can submit or not in current stage
    @can_submit = false
    @stage = @assignment.get_current_stage(SignedUpTeam.topic_id(@participant.parent_id, @participant.user_id))
    redirect_to action: 'edit', id: params[:id], view: true
  end
</pre>





Revision as of 23:20, 20 October 2021

E2130: Refactor 'submitted_content_controller'

This page provides detailed explanation of the Submitted Content Controller which is a part of the Expertiza project. The aim of the project is to refactor the 'submitted_content_controller', which contains the methods to submit assignment related information such as submit & remove hyperlinks, files and other relevant information that could be part of the assignment. It also handles views based on the user roles and permissions they have. The project involved refactoring some parts of the controller to incorporate the OODD principles so that the readability of code could be improved.

About Expertiza

The Expertiza platform employs a divide-and-conquer strategy for creating reusable learning objects via active-learning exercises built entirely on Ruby on Rails framework. Students get to choose from a list of tasks to complete either individually or in teams. They then prepare their work and submit it to a peer-review mechanism. On submission, other students can assess their peers work and provide feedback. Expertiza encourages students to collaborate in order to improve the learning experiences from one another. It aids their learning by making them translate what is taught in the lectures and apply those concepts to a real-world issue.

Problem Statement

submitted_content_controller had some problems that violate essential rails design principles which needed to be rectified. Issues included some methods being too long which needed to be broken down, a few methods needed better naming and a few that were no longer needed.

Broadly, the following issues were addressed as a part of refactoring this controller:

  • Renaming methods to more appropriate and functionality specific names.
  • The existing code was reused to perform either the same function or re-purposed to do a similar function adhering to standards and improving overall quality of the code.
  • Introduction of modular code in order to make each module easier to understand, test and refactor independently of others.

Problems and Solutions

1. Problem 1: Remove the comment “# hence use team count for the check”.

The current code no longer checks for the team count to see if a participant belongs to a team. Comment on line #19 removed.


2. Problem 2: Change the method name view to something more informative of the method.

The original code uses the generic 'view' method name to display a view corresponding to a case when submissions cannot be accepted, for instance in the case when a deadline is passed.
 def view
    @participant = AssignmentParticipant.find(params[:id])
    return unless current_user_id?(@participant.user_id)
    @assignment = @participant.assignment
    # @can_submit is the flag indicating if the user can submit or not in current stage
    @can_submit = false
    @stage = @assignment.get_current_stage(SignedUpTeam.topic_id(@participant.parent_id, @participant.user_id))
    redirect_to action: 'edit', id: params[:id], view: true
  end
  • Solution: We found changing the name to disable_submission to be more apt in this case
 def disable_submission
    @participant = AssignmentParticipant.find(params[:id])
    return unless current_user_id?(@participant.user_id)
    @assignment = @participant.assignment
    # @can_submit is the flag indicating if the user can submit or not in current stage
    @can_submit = false
    @stage = @assignment.get_current_stage(SignedUpTeam.topic_id(@participant.parent_id, @participant.user_id))
    redirect_to action: 'edit', id: params[:id], view: true
  end


Testing Requirements

1. git clone https://github.com/Neelkanth7/expertiza

2. Change directory to expertiza. Run "bundle install" and rails db:migrate.

3. Start the rails server.

4. Run the following command in a new terminal of the expertiza directory:

   i.  rspec spec/controllers/submitted_content_controller_spec.rb

References

  • Github link to the project.
  • Link to the project description.