CSC/ECE 517 Fall 2022 - E2279. Further refactoring and improvement of signup sheet controller: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 74: Line 74:


==Controller Re-design==
==Controller Re-design==
We are proposing to add a new topics controller to handle some of the current methods, as in the following diagram:


[[File:SUPCLASS.PNG|300px|Image: 300 pixels]]
[[File:SUPCLASS.PNG|300px|Image: 300 pixels]]

Revision as of 22:59, 20 November 2022

Team

Mentor

  • Ed Gehringer (efg)

Team Members

  • Juan Benavides (jdbenavi)
  • Wei-Chi Chen (wchen37)
  • Swetha Sairamakrishnan (ssairam)

Problem Statement

  • Provide extensive comments for all the code you view/refactor/modify.
  • Ensure that any code changes do not break any functionality. Refactoring method names might cause cascaded updates in other files.
  • Address and test effects of add_signup_topics_staggered
  • Add_signup_topics_staggered was supposed to make sure that the deadlines are set. [Assignment 1042 has staggered deadlines]. However, it was removed in the last version since it did not do anything different from add_signup_topics.
  • Currently in RSpec, it is only implicitly tested in the method create.
  • Refactor participants variable in load_add_signup_topics
  • [In retrospect, the meaning of this is not clear. The @participants variable is used in a way that is very obscure, with code spread across several views, and no comments saying what it is doing. It used to be that participants (individual students) signed up for topics. Now, only teams can sign up for topics. So @participants does not make sense.] [Has this been fixed?]
  • There are nine checks for @assignment.is_intelligent. This method is atrociously named. It simply checks for whether bidding is being used to assign topics.
  • Rename the method. ( not a method?)
  • Figure out some way to remove all or almost all of those checks, which are a gross violation of the Single-Responsibility Principle (as well as cohesion).
  • Also see Code Climate issues. To reduce the size of the file, you could move some methods to sign_up_sheet_helper.rb [Has this been done?.]
  • New topics controller to handle methods related to Topics. *TODO expand on this*

Prior Work section with last years and last projects background

We ( @sswetha08 @weichic-ncsu @juanbenavid ) have performed the following refactoring to fix the issues specified for this refactoring project:
  • Renamed "sign_up" to be "signup" when it is used as adjective or noun for variable/method/controller name.
  • Update method refactored by removing explicit update of every attribute of topic and instead performing this task through update_attributes function provided by rails. Further, update_max_choosers method changed to update_waitlist to support this.
  • Removed add_signup_topics_staggered() and replaced it with add_signup_topics() since it does nothing but call add_signup_topics().
  • Removed load_add_signup_topics() since it does nothing for add_signup_topics().
  • Removed the feature to sign up for a topic as an instructor as there seems to be no way to access this feature from the views.
  • List method was too long and has been refactored.
We have also added two new test cases for the controller:
  • Destroy signup_sheet when there are other topics in the assignment
  • General test case added for rendering list view
  • DRYed out code used to check for certain errors; however, that was done using an array of messages and then selecting one of them using a constant subscript, whereas it would have been better to pass the messages as parameters.
  • The compute_signup_topics method returns results by side-effects (in instance variables); probably this could have been done more cleanly.
  • Most of the changes involve regularizing use of "sign_up" vs. "signup"; this should ideally be done in a separate commit so it would be mergeable without merging the whole project.

About Controller

The sign up sheet controller performs the following functions:

  • Allows an instructor to add/remove topics to an assignment.
  • Allows an instructor to assign/remove students to topics (This has been removed as it is unused/impersonation of student is used instead)
  • Allows a student to see the list of available topics which can be bid on for given OSS assignment.

General Design Goals

  • Magic Tricks of Testing
  • Test incoming command messages by making assertions about direct public side effects.
  • Increase Cohesion and Minimize Coupling
  • DRY out the code wherever possible
  • Improve code clarity by naming methods and variables appropriately
  • Improve code clarity of the controller by moving non-CRUD methods to helper functions wherever applicable

Controller Re-design

We are proposing to add a new topics controller to handle some of the current methods, as in the following diagram:

Image: 300 pixels

Image: 500 pixels

Plan of Work

  • @Participants variable

References to @participants is scattered throughout the project, including some references in signup sheet views. This variable was removed in the signup sheet controller in the previous pull request for the Fall 2022 OSS project, but references in views have not been removed. In the OSS project we noticed that test coverage for some of the methods/views in this controller were incomplete, so we should make sure the removal of this variable does not cause problems. The naming could also use improvement, as only teams are allowed to signup for projects.

There is also naming confusion because the controller has many references to the (singular) participant variable, and it is not clear how the two are supposed to be different. So better comments/naming is important.

   def delete_signup
       participant = AssignmentParticipant.find(params[:id])
       ...
   ...
   def list
       @participant = AssignmentParticipant.find(params[:id].to_i)
       @assignment = @participant.assignment
       ...
  • New Topics Controller

In order to clean up the controller, we plan to move many of the methods to a new topic controller ( see above diagram)

  • Increase Test Coverage

We noticed that in general the controller could use more/better rspec tests as some error pages we encountered while manually testing were not captured by the current rspec


  • Address and test effects of add_signup_topics_staggered
  • Work done
  • RSpec
  • When creating a topic which could be found, test the availability in different values of assignment.staggered_deadline.
    context 'when topic can be found' do
      context 'when assignment.staggered_deadline is True' do
        it 'updates the existing topic and redirects to signup_sheet#add_signup_topics page' do
          ...
        end
      end
      context 'when assignment.staggered_deadline is False' do
        it 'updates the existing topic and redirects to signup_sheet#add_signup_topics page' do
          ...
        end
      end
    end
  • Plan
  • RSpec
  • Test add_signup_topics explicitly with different assignments as the input argument.
  • Mandatory
  • Test the route from app/views/assignments/edit/_topics.html.erb with different assignment_form.


  • Assignment is_intelligent attribute is a source of confusion

There are several checks for @assignment.is_intelligent across the controllers and views. This attribute is atrociously named. It simply checks for whether bidding is being used to assign topics.

Proposed changes include renaming the attribute to bid_for_topics which more accurately captures its purpose. If this attribute were to be renamed, it would involve a lot of changes across the project -

  • The schema for Assignment would have to be updated
       t.boolean "is_intelligent"
  • All creation of Assignment objects across the code and specs would have to be changed
    context 'when current assignment is not intelligent assignment' do
     it 'renders signup_sheet#list page' do
       assignment.is_intelligent = false
       allow(Bid).to receive(:where).with(team_id: 1).and_return([double('Bid', topic_id: 1)])
       request_params = { id: 1 }
       get :list, params: request_params
       expect(response).to render_template(:list)
     end
   end
  • Existing test or sample DB data for Assignments would also have to be updated accordingly.
  • Views including tree_display would also be affected as they contain checks like this -
      (props) =>
       props.is_intelligent
         ? {
             title: 'Intelligent Assignment',
             href: '/lottery/run_intelligent_assignment/' + `${parseInt(props.id) / 2}`,
             src: '/assets/tree_view/run-lottery.png'
           }

Further changes include reducing these number of checks to reduce coupling with other modules.

  • Code Climate Issues

https://codeclimate.com/github/expertiza/expertiza/app/controllers/sign_up_sheet_controller.rb#

Some issues observed on Code Climate for this controller -

  • Class SignUpSheetController has 32 methods (exceeds 20 allowed).
  • Class has too many lines. [393/100]

We plan to move some methods that are not directly involves in CRUD to the helper module: update_waitlist compute_signed_up_topics add_signup_topics, set_values_for_new_topic, set_priority, switch_original_topic_to_approved_suggested_topic

Test Plan

Edge Cases and Pre-Conditions

  1. When dropping topic if submission already done.
  2. When deadline from dropping topic has passed.
  3. Deleting topic when topic cannot be found.
  4. Signup in case when user cannot be found.
  5. Create signup_sheet when sign_up_topic cannot be found.
  6. Destroy signup_sheet when other topics with the same assignment exists.

RSpec

As such no functionality changed in any function, only refactoring done. All the refactoring was carefully verified by running rspec tests. To run the spec file, run:
  • rspec spec/controllers/signup_sheet_controller_spec.rb
We also ran the rspecs for signup_sheet model and helper just to make sure no functionality was broken.
  • rspec spec/helpers/signup_sheet_helper_spec.rb
  • rspec spec/models/signup_sheet_spec.rb

Mandatory

Login as instructor
  1. Hover on Manage Tab
  2. Click on Assignments Tab
  3. Click on Edit Button for "OSS project & documentation" assignment
  4. Select the Topic Tab
  5. Add New Topic or Delete topic using links in the form below


Login as student
  1. Click on OSS project/Writing assignment 2
  2. Click on Signup sheet
  3. The list must be visible, which indicates functionality is as before after refactoring list function.
  • New Tests

Code Modifications

Relevant Links