From Expertiza_Wiki
Revision as of 14:18, 2 December 2022 by Aramasw (talk | contribs)
Jump to navigation Jump to search

Problem Description

Expertiza can automatically deduct points if a student is late in performing some action (e.g., submitting or reviewing). This is implemented by defining a new “late policy” and applying it to the assignment. Late policies are managed on the Due dates tab of assignment creation (or editing). The goal of this project is to eliminate issues associated with the "Back" link on "New Late Policy" page by making necessary changes and adding new test cases which cover all scenarios.

Project Scope

Issues with the Current Implementation

The following issues have been raised in the current implementation:

  • Issue 1 - Under the “Due Date” tab when click on the "New late policy" link an error message shows up.

  • Issue 2 - When creating a late policy, the “back” link does not take the user back to editing the assignment.

  • Issue 3 - After creating a late policy, the “back” link does not take the user back to editing the assignment.

Solution and Files Refactored

  • Issue 1

1. app/controllers/assignments_controller.rb
The assignments were identified using assignment.name which we thought was potentially causing issues. To make it more consistent, we modified find_by to use the assignment.id instead of assignment.name. On analyzing issue 1, we found that the error message appeared when validation checks for assignment_form model failed for one particular assignment named "Program 2". This particular assignment failed the validation of having the sum of rubric metric being either 0 or 100. Based on our understanding, this data was probably inserted prior to the above mentioned validation checks in app/model/assignments_form.rb file.
Previous Code:

  def assignment_form_save_handler
    exist_assignment = Assignment.find_by(name: @assignment_form.assignment.name)
    assignment_form_params[:assignment][:id] = exist_assignment.id.to_s
    fix_assignment_missing_path
    update_assignment_form(exist_assignment)
    aid = Assignment.find_by(name: @assignment_form.assignment.name).id
    ExpertizaLogger.info "Assignment created: #{@assignment_form.as_json}"
    redirect_to edit_assignment_path aid
    undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ")
  end

Modified Code:

 def assignment_form_save_handler
    exist_assignment = Assignment.find(@assignment_form.assignment.id)
    assignment_form_params[:assignment][:id] = exist_assignment.id.to_s
    fix_assignment_missing_path
    update_assignment_form(exist_assignment)
    assignment_id = Assignment.find(@assignment_form.assignment.id).id
    ExpertizaLogger.info "Assignment created: #{@assignment_form.as_json}"
    redirect_to edit_assignment_path assignment_id
    undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ")
  end
  • Issue 2 and Issue 3

1. app/views/late_policies/new.html.erb
In order to resolve this issue we stored the assignment_id as parameter in the session variable in app/controllers/assignments_controller.rb and then used this assignemnt_id in the Back link of index and new page of late policy to redirect back to edit view for assignment. In app/views/assignments/edit.html.erb we added a JQuery to ensure that if the user comes from the late_policy page, it will redirect them to the Due Dates tab of the edit assignment page.
Previous Code:

<%= link_to 'Back', :controller=> 'assignments', :action => 'edit', :id=>session[:assignment]%>

Modified Code:

<%= link_to 'Back', :controller=> 'assignments', :action => 'edit', :id=>session[:assignment_id]%>

2. app/views/late_policies/index.html.erb
Previous Code:

<%= link_to 'New late policy', :action => 'new'%><br />
<%= link_to 'Back', :controller=> 'assignments', :action => 'edit', :id=>session[:assignment]%>

Modified Code:

<%= link_to 'New late policy', :action => 'new'%><br />
<%= link_to 'Back', :controller=> 'assignments', :action => 'edit', :id=>session[:assignment_id]%>

3. app/views/assignments/edit.html.erb
Previous Code:

  No code

Modified Code:

      // Redirect to Due Date Tab  on Back link from late policy
      jQuery(document).ready(function() {
        var referrer =  document.referrer;
        if(referrer.includes("late_policies")){                     
          $('#DueDates').click();
        }  
}); 

4. app/controllers/assignments_controller.rb
Previous Code:

    def create
             ......
        assignment_form_params[:due_date] = due_array
        @assignment_form.update(assignment_form_params, current_user)
        aid = Assignment.find(@assignment_form.assignment.id).id
        ExpertizaLogger.info "Assignment created: #{@assignment_form.as_json}"
        redirect_to edit_assignment_path aid
        undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ")
        return
# edits an assignment's deadlines and assigned rubrics
  def edit
    user_timezone_specified
    edit_params_setting
    assignment_staggered_deadline?
	.......
    @badges = Badge.all
    @use_bookmark = @assignment.use_bookmark
    @duties = Duty.where(assignment_id: @assignment_form.assignment.id)
  end
 # displays an assignment via ID
  def show
    @assignment = Assignment.find(params[:id])
  end

Modified Code:

    def create
                     ......
        assignment_form_params[:due_date] = due_array
        @assignment_form.update(assignment_form_params, current_user)
        assignment_id = Assignment.find(@assignment_form.assignment.id).id
        ExpertizaLogger.info "Assignment created: #{@assignment_form.as_json}"
        session[:assignment_id] = assignment_id
        redirect_to edit_assignment_path assignment_id
        undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ")
        return
# edits an assignment's deadlines and assigned rubrics
  def edit
    session[:assignment_id] = nil
    user_timezone_specified
    edit_params_setting
    assignment_staggered_deadline?
	......
    @badges = Badge.all
    @use_bookmark = @assignment.use_bookmark
    @duties = Duty.where(assignment_id: @assignment_form.assignment.id)
    @assignment = Assignment.find(params[:id])
    session[:assignment_id] = @assignment.id
  end
# displays an assignment via ID
  def show
    session[:assignment_id] = nil
    @assignment = Assignment.find(params[:id])
    session[:assignment_id] = @assignment.id
  end

Design Principle

Since our goal is to fix existing functionalities we will not be updating the existing design patterns being employed in the code.
Refactoring is a systematic process of improving code without creating new functionality. Thus, a key to the success of our project is ensuring everything that was working before our changes work even after our changes have been added. To ensure this, we will continue to test the system after each issue has been fixed. This will allow us to ensure two things:

  • We are only changing what we set out to change when fixing a particular issue.
  • We are not breaking what was working before we deployed our fix.

Testing

RSpec Unit Tests

We have written RSpec tests for verifying our code for the following use cases:
Case 1:
Scenario: The instructor is about to create a new late policy.
Given: Logged in as an instructor.
When: The instructor tries to create a new late policy by clicking 'New Late Policy' under the 'Due Dates' tab/
Then: The instructor is redirected to the create/edit policy page without any error message displayed.


Case 2:
Scenario: The instructor is creating a new late policy and tries to go back to the previous page.
Given: Logged in as an instructor and in the 'New Late Policy' page
When: The instructor tries to go to the previous page
And: The instructor clicks the “Back” button.
Then: The instructor is redirected to the previous Due Dates page.

Case 3:
Scenario: The instructor has created a new late policy and tries to go back to the previous page.
Given: Logged in as an instructor.
When: The instructor successfully creates a new late policy, being redirected to the “/late_policies” webpage with all information on late policies.
And: The instructor clicks the “Back” button.
Then: The instructor is redirected to the previous create/edit assignment page.

Manual Testing

  • When logging in as an instructor:

1. Edit an assignment by clicking on edit logo under the “Action” column.
2. Under the “Due Date” tab click on the "New late policy" link.
3. In “New late policy” fill in the required details.
4. Clicks “Create” to save the policy, to go to page which shows all late policies.
5. Clicks “Back” to redirect the instructor back to the “Due Date” tab of the assignment which was being edited.
Or
4. Clicking “Back”, should redirect the instructor back to the “Due Date” tab of the assignment which was being edited.

Link to UI Testing Demo https://drive.google.com/file/d/1iYq2_Zf_Q-2UnHh3e4NGkJ742lJFMtzy/view?usp=sharing

Important Links

Github Links

Link to Expertiza repository: https://github.com/expertiza/expertiza
Link to the forked repository: https://github.com/NitishKumar2404/Expertiza
Program 4 code is present in program4 branch: https://github.com/NitishKumar2404/Expertiza/tree/program4
Link to Pull Request: https://github.com/expertiza/expertiza/pull/2482

Team

Mentor

Vinay Deshmukh (vdeshmu@ncsu.edu)

Team Members

Kalgee Anand Kotak (kkotak@ncsu.edu)
Ashrita Ramaswamy (aramasw@ncsu.edu)
Nitish Kumar Murali (nmurali2@ncsu.edu)

Retrieved from ""