CSC/ECE 517 Spring 2015/oss E1504 IMV: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 25: Line 25:
'''What needs to be done:'''
'''What needs to be done:'''
<ul>
<ul>
   <li>The search methods in bookmarks model are being used used on a very granular level. This led to redundancy in bookmarks search methods. These methods include <i>search_alltags_allusers, search_fortags_allusers, search_fortags_forusers, search_alltags_forusers</i>. Hence duplicates in these methods are to be singled out. As we know, in ruby, the method name should specify the pseudo use of itself. Here, <i>add_new_bookmark </i> misleads as this is one of the CRUB method and the naming convention is not quite right. It has to be renamed to create method. Again the case of duplicates arrive. Now in the methods <i> add_topic_bookmark, add_this_bookmark, add_bookmark </i>. The difference between <i> add_topic_bookmark and add_this_bookmark </i> is that the former takes an extra input i.e. topicid. Hence these two can be moved into one method. The third method is an unnecessary repetition of the former two methods' functionality. The method name <i> edit_this_bookmark </i> should be renamed to <i> edit</i> along with updating all the dependencies corresponding to <i> edit_this_bookmark </i>.Lastly, <i> add_bmapping and add_bmapping_signuptopic </i> have to be moved to appropriate class i.e. bmapping class. This involves checking their dependencies and updating their function calls accordingly.
   <li>The search methods in bookmarks model are being used used on a very granular level. This led to redundancy in bookmarks search methods. These methods include <i>search_alltags_allusers, search_fortags_allusers, search_fortags_forusers, search_alltags_forusers</i>. Hence duplicates in these methods are to be singled out. </li>
</li>
  <li>Following the CRUD declaration in Ruby on Rails, where the method name should specify the pseudo use of itself,methods such as <i>add_new_bookmark</i> and <i>edit_this_bookmark</i> have violate this naming convention. Therefore, we need to change the names of these two methods to <i>create</i> and <i>edit</i>, respectively. Upon changing the names, all the dependencies need to be updated, as well.</li>
  <li>Refactor <i>add_topic_bookmark</i> and <i>add_this_bookmark</i> by removing the repetitive code. These two methods differ only in 2 lines of code, which make it reasonable to merge them together into a single method that provides functionality of both individual methods.</li>
  <li>Fix the bug in <i>add_bookmark</i> method where only bookmarks without <i>topic_id</i> can be properly created. We add the functionality to this method to allow it to also create bookmarks with provided <i>topic_id</i>.
  <li>Methods <i>add_bmapping</i> and <i>add_bmapping_signuptopic</i> need to be moved to their appropriate model (Bmapping model) rather than reside in Bookmarks model. Completing this task involves checking the dependencies and updating the function calls for these methods, accordingly.</li>
</ul>
</ul>



Revision as of 15:18, 23 March 2015

E1504. Refactoring the Bookmark Model

This page provides a description of the Expertiza based OSS project. This team project successfully refactored the Bookmark Model by removing the duplicate code, combining the methods, improving the search function, moving Bmapping model methods to their respective class, covering dependencies associated with changed segments and adding a User Interface for using bookmarks.

Introduction to Expertiza

Expertiza is a large project developed as a combined effort of students and faculty using the Ruby on Rails framework. The main advantage of using Expertiza, in an educational environment, is for the instructor to introduce peer reviewing among the students. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.

Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.


Problem Statement

Classes involved:

bookmark.rb
bmapping.rb
bookmarks_controller.rb
auth_controller.rb
auth_helper.rb

What they do: The bookmark model and controller work together to create and maintain user specific bookmarks, which can be added to different topics. Moreover, the user that created a bookmark can use his privilege to edit it at a later point in time. As a functionality added for convenience, any user can search bookmarks by either users who created them or their bookmark tags.

What needs to be done:

  • The search methods in bookmarks model are being used used on a very granular level. This led to redundancy in bookmarks search methods. These methods include search_alltags_allusers, search_fortags_allusers, search_fortags_forusers, search_alltags_forusers. Hence duplicates in these methods are to be singled out.
  • Following the CRUD declaration in Ruby on Rails, where the method name should specify the pseudo use of itself,methods such as add_new_bookmark and edit_this_bookmark have violate this naming convention. Therefore, we need to change the names of these two methods to create and edit, respectively. Upon changing the names, all the dependencies need to be updated, as well.
  • Refactor add_topic_bookmark and add_this_bookmark by removing the repetitive code. These two methods differ only in 2 lines of code, which make it reasonable to merge them together into a single method that provides functionality of both individual methods.
  • Fix the bug in add_bookmark method where only bookmarks without topic_id can be properly created. We add the functionality to this method to allow it to also create bookmarks with provided topic_id.
  • Methods add_bmapping and add_bmapping_signuptopic need to be moved to their appropriate model (Bmapping model) rather than reside in Bookmarks model. Completing this task involves checking the dependencies and updating the function calls for these methods, accordingly.

Changes Made

Bookmark Model

Method Name Changes Made Reason For Change
add_this_bookmark Added functionality of add_topic_bookmark To implement code reusability and remove repetitive code.
add_topic_bookmark Merged the functionality into add_this_bookmarks and deleted add_topic_bookmark To implement code reusability and remove repetitive code.
add_bookmark Added a line that checks whether topic_id has been provided in the request It allows creation of new Bmapping if no topic_id was given and removes the bug of searching for bookmark with nil topic_id later on
search_alltags_allusers -------------- ---------
search_alltags_foruser -------------- ---------
search_fortags_allusers -------------- ---------
search_fortags_foruser -------------- ---------
add_new_bookmark Changed the method name to "create" It is a much more meaningful and simpler name for a method that creates a new bookmark
edit_this_bookmark Changed the name to "edit" It is a much more appropriate name for a method that edits the bookmark it was called on
add_bmapping Moved to class 'Bmapping' This method helps in creating new bmapping. Hence it makes more sense if it belongs to bmapping class itself.
add_bmapping_signuptopic Moved to class 'Bmapping' This method helps in adding a signup topic to a newly created bmapping. Hence it makes more sense if it belongs to bmapping class itself.

Bookmark Controller

Method Name Changes Made Reason For Change
create ---------------- -----------
update ----------------- --------
edit -------------- ---------

destroy

----------------- ---------
--------------- ----------
---------- ----------

Views

Method Name Changes Made Reason For Change
bookmarks/_result.html.erb ---------------- -----------
bookmarks/search_bookmarks.html.erb ----------------- --------
bookmarks/view_bookmarks.html.erb -------------- ---------
bookmarks/_searchmine.html.erb ----------------- ---------
bookmarks/add_bookmark_form.html.erb ----------------- ---------
bookmarks/edit_bookmark_form.html.erb ----------------- ---------
bookmarks/managing_bookmarks.html.erb ----------------- ---------
layouts/application.html.erb ----------------- ---------

Re-factored Code Cases

Case 1 : Refactoring add_this_bookmark and add_topic_bookmark

The consistency of these two methods shows plenty of repetitive code. In order to effectively refactor these methods and reuse the code they both need, our team merged the two methods together by enabling add_this_bookmark method to handle creation of a bookmark when a topic id is provided (main functionality of add_topic_bookmark method). Once we implemented this change on add_this_bookmark method, we deleted add_topic_bookmark method as it became obsolete. Therefore, we retained the same functionality while reducing the method by 7 repetitive lines of code.

Before Changes

  def self.add_topic_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topicid)
    # Check if the bookmark exists and add / edit based on that
    bookmark_exists = check_bookmark_exists(b_url)
    bmapping_exists = check_bmapping_exists(b_url,session_user)
    if (!bookmark_exists || !bmapping_exists)
      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)
    elsif (bmapping_exists)
      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)
    end
  end

  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)
    bookmark_exists = check_bookmark_exists(b_url)
    bmapping_exists = check_bmapping_exists(b_url,session_user)
    if (!bookmark_exists || !bmapping_exists)
      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user)
    elsif (bmapping_exists)
      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)
    end
  end

After Changes

  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topic_id)
    bookmark_exists = check_bookmark_exists(b_url)
    bmapping_exists = check_bmapping_exists(b_url,session_user)
    if (!bookmark_exists || !bmapping_exists)
      if(topic_id) # something has been passed for topic_id
        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)
      else
        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user, nil)
      end
    elsif (bmapping_exists)
      Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)
    end
  end

Case 2 :

Steps to verify changes manually

User2 Role

Automated Tests

Unit test

Integration (Cucumber) tests

See Also

References