CSC/ECE 517 Fall 2015/oss E1567 APT

From Expertiza_Wiki
Jump to navigation Jump to search

Introduction to Expertiza

The Expertiza project is a web application to create reusable learning objects through peer review. It supports various features such as team projects, and the submission of various documents including URLs and wiki pages. It is being extensively used across various universities for select courses. The page describes the various changes and modifications done to improve the source code of the application. The changes were accompanied by unit/functional test cases written in RSPEC to affirm no breakage in code.

Project Description

Users Controller is one of the controllers in the Expertiza Rails Application. It is used for the basic CRUD operations - creating new users, updating the details for an existing users or deleting an existing user in the system. It is also used to determine the role of particular user in the system. The role could be one of the following - Administrator, Instructor, Student, Teaching Assistant, Super-Administrator or Unregistered User. The associated model class for interacting with the user table is the User model. It is also used for to verify the various access privileges for each user, import or export users.

Classes Involved

  • users_controller.rb
  • user.rb
  • user_spec.rb

Modifications/Refactoring

Users_controller

The User_controller file was subject to code modifications and refactoring. The objective was to implement DRY code principles and reducing code complexity. The following were the suggested changes according to the Design document.

1. Initially, various functions were calling the same redirect method to redirect to the same controller. This was inimical to the code reusage principle. Following the DRY code principle, instead of calling the same link, with the action and controller as arguments, a method(redirect_to_home) was created and called from the 3 different methods namely show, index and key.

2. Initially, the create method in Users_contoller was being used to send emails to new users by passing strings as arguments to the mailer template. The strings were harcoded as arguments, this was modified so that varaibles were passed as parameters to the mailer template. This helped remove hardcoded code while maintaining the functionality.
3. Initially, in the destroy method, queries were being executed directly from the controller method, which doesn't follow Ruby on Rails code ethics. So the queries were moved to a new method destroy_user in User Model file and the method was called from within the delete method in controller.

user.rb

  • Initially, the code had a very long method called get_users_list. It has now been broken down into several simpler methods namely, fetch_users_for_super_admin, , , , ,
  • The functionality for deleting a user was not working. A method has been added to delete the users.


  • The search_users method had a complicated if-else ladder. The method has now been optimized using a case statement & a call to a new method named fetch_results that returns the list of users based on role, user_id, letter, search_by parameters.

About rspec

Test Cases

Test Case 1

Test Case 2

Test Case 3