Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Introduction  



1.1  Background  





1.2  Motivation  





1.3  Tasks Identified  



1.3.1  Classes  





1.3.2  Refactoring Edit function  





1.3.3  Refactoring Update function  





1.3.4  Remove irrelevant comments from the create action  





1.3.5  associate_assignment_with_course moved to model  





1.3.6  remove_assignment_from_course moved to model  





1.3.7  Change to new redirect method rather using controller and action explicitly.  





1.3.8  Refactor the update_due_dates from AssignmentForm using the DRY principle  







1.4  Changes to the View  



1.4.1  Impact Analysis  







1.5  Affected Classes  







2 Running the Project Locally  



2.1  Testing using Selenium IDE  







3 Future Work  





4 References  














User:Ashwin Bharadwaj Lakshmi Venkataramanan/Expertiza

















User page
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
User contributions
User logs
View user groups
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 

< User:Ashwin Bharadwaj Lakshmi Venkataramanan

Introduction[edit]

Background[edit]

Expertiza provides a dashboard for all the Assignments corresponding to a course and provides absolute control to the Instructors and Teaching Assistant. In addition to Assignments, it encompasses peer reviews where in participants are allowed to provide feedback anonymously about each other's work thereby providing scope for better outcome.

Assignments in Expertiza have their association with many other components like Courses,Reviews,Participants and Scores. The Assignment controller in specific performs various other actions in addition to the CRUD operations applied on its model. These actions sew up the association of an assignment with others like courses etc. There exists an AssignmentForm model which acts as a wrapper for the Assignment and provides further control.

Motivation[edit]

This project in particular intends that the students collaborate with each other and work on making enhancements to the code base by applying the concepts of Rails,RSpec, DRY code,Test driven development etc. This provides an opportunity for students to contribute to an open source project and learn further about software deployment etc.

Currently, the Assignment controller holds methods which are deprecated and also has a few lines code in its Edit and Update methods which could be removed to make the code DRY. In addition to that, it houses a few actions where the code could be refactored to make it DRY and follow the Ruby style guide and Rails 4 syntax.

Tasks Identified[edit]

Classes[edit]

Refactoring Edit function[edit]

Edit function contains many manipulations that need be refactored into separate functions. The following block contains manipulations such as checking if due_date name or description is not defined.

@due_date_all.each do |dd| 
if((!dd.deadline_name.nil?&&!dd.deadline_name.empty?)||(!dd.description_url.nil?&&!dd.description_url.empty?))
       @due_date_nameurl_notempty = true
       @due_date_nameurl_notempty_checkbox = true
     end
 ....
end

This part of the code is moved into a separate function.

def is_due_date_nameurl_notempty(dd)
    (!dd.deadline_name.nil?&&!dd.deadline_name.empty?)||(!dd.description_url.nil?&&!dd.description_url.empty?)
end

There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants.

 if dd.deadline_type_id==5
        @metareview_allowed = true
      end
      if @due_date_nameurl_notempty && @due_date_nameurl_notempty_checkbox && @metareview_allowed
        break
      end
      if dd.deadline_type_id==6
        @drop_topic_allowed = true
      end
      if @due_date_nameurl_notempty && @due_date_nameurl_notempty_checkbox && @drop_topic_allowed
        break
      end
      if dd.deadline_type_id==7
        @signup_allowed = true
      end
      if @due_date_nameurl_notempty && @due_date_nameurl_notempty_checkbox && @signup_allowed
        break
      end
      if dd.deadline_type_id==8
        @team_formation_allowed = true
      end
      if @due_date_nameurl_notempty && @due_date_nameurl_notempty_checkbox && @team_formation_allowed
        break
      end
    end

Redundant code is removed and made it more efficient and understandable.

      @metareview_allowed = is_meta_review_allowed?(dd);
      @drop_topic_allowed = is_drop_topic_allowed?(dd);
      @signup_allowed = is_signup_allowed?(dd);
      @team_formation_allowed = is_team_formation_allowed?(dd);

      if dd.due_at.present?
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)
      end
      if  @due_date_nameurl_notempty && @due_date_nameurl_notempty_checkbox &&
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)
        break
      end

Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.

  DEADLINE_TYPE_METAREVIEW = 5
  DEADLINE_TYPE_DROP_TOPIC = 6
  DEADLINE_TYPE_SIGN_UP = 7
  DEADLINE_TYPE_TEAM_FORMATION = 8

And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.

  def is_meta_review_allowed?(dd)
    status = false
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW
      status = true
    end
    status
  end

  def is_drop_topic_allowed?(dd)
    status = false
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC
      status = true
    end
    status
  end

  def is_signup_allowed?(dd)
    status = false
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP
      status = true
    end
    status
  end

  def is_team_formation_allowed?(dd)
    status = false
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION
      status = true
    end
    status
  end

The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.

 if !empty_rubrics_list.empty? and request.original_fullpath == "/assignments/#{@assignment_form.assignment.id}/edit"
      empty_rubrics = "<b>["
      empty_rubrics_list.each do |item|
        empty_rubrics += item[0...-13] + ", "
      end
      empty_rubrics = empty_rubrics[0...-2]
      empty_rubrics += "] </b>"
      flash.now[:error] = "You did not specify all necessary rubrics: " +empty_rubrics+" of assignment <b>#{@assignment_form.assignment.name}</b> before saving the assignment. You can assign rubrics <a id='go_to_tabs2' style='color: blue;'>here</a>."
    end

Adding code such as above directly into the controller action made the edit function bulkier. The above snippet is also refactored into a separate function.

 def needed_rubrics(empty_rubrics_list)
    ...
  end

Refactoring out into separate functions makes the code more readable and understandable.

Refactoring Update function[edit]

Update function of the Assignment controller helps in updating the resources after editing it. The following code retrieves the data of the user logged in.

 session[:user]

The above statement checks the cookies every time, when we want to retrieve information about current user. As it is inefficient and wrong, we need to use helper functions to retrieve such information.

Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.

 redirect_to :action => 'edit', :id => @assignment.id  # Incorrect
 redirect_to edit_assignment_path @assignment.id    # Correct

Remove irrelevant comments from the create action[edit]

The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.

associate_assignment_with_course moved to model[edit]

This is currently defined as an action in AssignmentsController. The action logic could be moved to Model by passing the current user object to the corresponding method we create in the Model. The method in the model would then return a list of courses which would be used in the View corresponding to this action.

Inside controller action,

 def associate_assignment_with_course
    @assignment = Assignment.find(params[:id])
    @courses = Assignment.set_courses_to_assignment(current_user)
  end

Inside model,

def self.set_courses_to_assignment(user)
    @courses=Course.where(instructor_id: user.id).order(:name)
  end

remove_assignment_from_course moved to model[edit]

All the current logic here, except for the "save" and "redirect_to" calls could be moved to the model. There is a need to create a method in the Model with the same name and then pass an assignment object. All operations can be performed inside this method and then the user can be redirected back to the assignment list page. Inside controller action,

def remove_assignment_from_course
    assignment = Assignment.find(params[:id])
    Assignment.remove_assignment_from_course(assignment)
    redirect_to controller: 'tree_display', action: 'list'
  end

Inside model,

def self.remove_assignment_from_course(assignment)
    oldpath = assignment.path rescue nil
    assignment.course_id = nil
    assignment.save
    newpath = assignment.path rescue nil
    FileHelper.update_file_location(oldpath, newpath)
  end


Change to new redirect method rather using controller and action explicitly.[edit]

According to Ruby style guidelines explicit use of action and controller in redirect calls should be avoided. This helps in easy refactoring in case action names are changed in future. All the redirect calls in assignment controller have been modified to use url path helpers. In controller assignment and action toggle_access, redirect call has been changes as foloows

  def toggle_access
    assignment = Assignment.find(params[:id])
    assignment.private = !assignment.private
    assignment.save
    redirect_to list_tree_display_index_path
  end

Refactor the update_due_dates from AssignmentForm using the DRY principle[edit]

There exist variables which are declared and initialized but are not used in any part of the code. Such variables could be safely removed without impacting the functionality of the action. Conditional statements which check whether due_date object is present can be avoided. The same piece of code is used at various points of code making it redundant and hence can be converted to a method. There exist dead code which tries to remove due_dates not in update or new list from database. There can never be such a case, so the code can be safely removed.

Changes to the View[edit]

Impact Analysis[edit]

Affected Classes[edit]

Changed existent classes

Running the Project Locally[edit]

The project could be run locally by cloning the Github repository expertiza and then running the following commands sequentially.

bundle install
rake db:create:all
rake db:migrate
rails s

Testing using Selenium IDE[edit]

Selenium IDE is implemented as a Firefox extension. It allows user to record edit and debug test cases. It has a recording feature, which records user actions as they are performed and then exports them as a reusable script in one of many programming languages that can be later executed.[1] The UI automation helps in testing quickly yet rigorously. Major test cases identified are following

The test cases were manually run and recorded once. Then the test cases were re run with changed parameters on the deployed version of the application.

Future Work[edit]

The tasks accomplish only a part of the refactoring and as always with any software application there is scope for even more. The following are a few which were identified as part of this project.

References[edit]

  1. ^ "Selenium IDE". Retrieved 31 October 2015.

Retrieved from "https://en.wikipedia.org/w/index.php?title=User:Ashwin_Bharadwaj_Lakshmi_Venkataramanan/Expertiza&oldid=1086816115"

Hidden category: 
Pages with syntax highlighting errors
 



This page was last edited on 8 May 2022, at 14:42 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki