CSC/ECE 517 Fall 2021 - E2121. Refactor suggestion controller.rb

From Expertiza_Wiki
Jump to navigation Jump to search

This page provides a description of the Expertiza based OSS project.



About Expertiza

Expertiza is an open source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.

Problem Statement

The following tasks were accomplished in this project:

  • Used more Ruby-like String concepts.
  • Refactored create_new_team to assignment_team.rb.
  • Refactored notification to simplify control logic.
  • Refactored approve_suggestion to indicate that notification is being sent.
  • Added RSPEC testcases for testing changes done in Suggestion Controller.

About Suggestion Controller

TBD

Problems and Solutions

  • Problem 1: Use more Ruby-like String concepts.
The original code uses '==' and '!=' to compare a string with null, which is not Ruby-like.
if @suggestion.save
  flash[:success] = 'Thank you for your suggestion!' if @suggestion.unityID != ''
  flash[:success] = 'You have submitted an anonymous suggestion. It will not show in the suggested topic table below.' if @suggestion.unityID == ''
end
  • Solution: The approach we have taken is as follows: using empty? instead.
if @suggestion.save
  flash[:success] = 'Thank you for your suggestion!' unless @suggestion.unityID.empty?
  flash[:success] = 'You have submitted an anonymous suggestion. It will not show in the suggested topic table below.' if @suggestion.unityID.empty?
end
  • Problem 2: Refactor create_new_team to assignment_team.rb.
The create_new_team function is not similiar to other functions in suggestion_controller.rb, we should move it to assignment_team.rb.
  # This is the code area.
  • Solution: The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.
  # This is the code area.
  • Problem 3: The paginate method can be moved to a helper class.
VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.
  # This is the code area.
  • Solution: The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.
  # This is the code area.

Automated Testing using RSPEC

The current version of expertiza did not have any test for VersionsController. Using the test driven development(TDD) approach, we have added an exhaustive set of RSPEC tests for VersionsController, to test all the modifications we have done to the code of the controller class. The tests use double and stub features of rspec-rails gem, to fake the log in by different users - Administrator, Instructor, Student etc. The tests can be executed "rpec spec" command as shown below.

user-expertiza $rspec spec
.
.
.
Finished in 5.39 seconds (files took 25.33 seconds to load)
66 examples, 0 failures

Randomized with seed 19254
.
.

Testing from UI

Following are a few testcases with respectto our code changes that can be tried from UI: 1. To go to versions index page, type in the following url after logging in:

  http://152.46.16.81:3000/versions

2. After logging in as student/instructor or admin : Try accessing the new, create, edit, update actions. These actions are not allowed to any of the users.

  http://152.46.16.81:3000/versions/new
  This calls the new action. In the current production version of expertiza, it is unhandled and application gives a default 404 page.

3. Another feature that can be tested from UI is Pagination. Try searching for a user's versions and see if the results are paginated or not. Search here:

  http://152.46.16.81:3000/versions/search

4. Visit the same URL as step 3, you should see only the students under that instructor in the users dropdown.

References

  1. Expertiza on GitHub
  2. GitHub Project Repository Fork
  3. The live Expertiza website
  4. VCL link (will expire in 3 weeks)
  5. Expertiza project documentation wiki
  6. Rspec Documentation
  7. Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin