<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sbalasu7</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sbalasu7"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Sbalasu7"/>
	<updated>2026-06-03T12:17:45Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1583_Fix_the_CSS_used_for_Menu_Item&amp;diff=100165</id>
		<title>CSC/ECE 517 Fall 2015 E1583 Fix the CSS used for Menu Item</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1583_Fix_the_CSS_used_for_Menu_Item&amp;diff=100165"/>
		<updated>2015-12-05T00:57:07Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
&lt;br /&gt;
This project aims to fix the problem of the Expertiza Menu layout for smaller devices such as mobiles and tablets. There are many problems currently existing for devices with smaller screen size such as,&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The Menu layout takes almost whole screen space, which is not suitable from user experience point of view. &amp;lt;br/&amp;gt;&lt;br /&gt;
* The submenu items cannot be selected smoothly. &amp;lt;br/&amp;gt;&lt;br /&gt;
* User can neither see the content nor scroll it down properly when the menu is open, as it stays behind the menu.&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above mentioned issues can be seen in the screenshot below.&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Screen_Shot_2015-11-08_at_10.33.15_PM.png‎]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Planned Changes ==&lt;br /&gt;
&lt;br /&gt;
The aforementioned issues will be addressed as explained below: &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Reduce the height of the Menu items. As seen in the screenshot above, there is a lot of space between two menu items. Reducing the space in between will reduce the total screen space consumed by the Menu.&amp;lt;br/&amp;gt;&lt;br /&gt;
* Show submenu items on the right side of respective menu item, so that they don't overlap with other menu items (Right now, they are shown below the main menu item).&amp;lt;br/&amp;gt;&lt;br /&gt;
* Show the Menu selection button on the left side instead of right side.&amp;lt;br/&amp;gt;&lt;br /&gt;
* Start the content below the Menu when Menu is in expanded mode.&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below is the screenshot of the proposed CSS changes which will be reflected as below. &amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:WikiImage.png]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: This is for reduced screen sizes, and not for normal desktop size. Normal desktop layout will remain the same.&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
As seen in the screenshot, &amp;lt;br/&amp;gt;&lt;br /&gt;
* Menu item height is reduced and now it is not taking all the screen space.&amp;lt;br/&amp;gt;&lt;br /&gt;
* Submenu items are displayed on the right side of the main menu item.&amp;lt;br/&amp;gt;&lt;br /&gt;
* Content is displayed below the Menu, and it is not behind the Menu. It can be easily scrolled down/viewed even with Menu open.&amp;lt;br/&amp;gt;&lt;br /&gt;
* Menu button is on the left side instead of right.&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
We are using the browser extension &amp;quot;Responsive Web Design Tester&amp;quot;. This extension allows to test a web page for variety of devices with different screen sizes, such as (but not limited to), iPad, iPadMini, iPhone, Nexus, HTC-One etc. &amp;lt;br/&amp;gt;&lt;br /&gt;
With the help of this tool, we will be easily able to test that our changes are working fine for different screen sizes.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
Responsive Web Design Tool - Settings&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Screen_Shot_2015-11-08_at_10.21.31_PM.png]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Responsive Web Design Tool - Devices list&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File: Screen_Shot_2015-11-08_at_10.22.05_PM.png]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
The files listed below need to be changed to make proposed changes.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* /config/vendor/assets/components/bootstrap/less/navbar.less&amp;lt;br/&amp;gt;&lt;br /&gt;
The navbar-collapse less style needs to be modified here to enable seamless use and to handle overflows in case there is too much content for the user's view port on mobile devices.&lt;br /&gt;
* /app/assets/stylesheets/navbar.scss&lt;br /&gt;
The height difference between different menu options needs to be changed by modifying the number of pixels in the height attribute of the style in the following code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ul.nav li.first-level {&lt;br /&gt;
  font-size: 100%;&lt;br /&gt;
  height: 66px;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* /app/views/shared/_navigation.html.erb &amp;lt;br/&amp;gt;&lt;br /&gt;
The icon for the menu selection currently is placed on the right and the positioning of this now needs to be moved to the far left. This shall be done by moving the 'icon-bar' around.&lt;br /&gt;
* /app/assets/stylesheets/layout.scss&lt;br /&gt;
This file will contain the changes where we intend to make the position of the content relative to the header. This will ensure that even upon re-sizing the window the content will start below the header and would not be covered underneath the header.&lt;br /&gt;
&lt;br /&gt;
=== Sub-Menu Overlapping Main-Menu Problem ===&lt;br /&gt;
&lt;br /&gt;
On hovering over the menu items on the navigation bar shows the sub-menu. But, the sub-menu position on the screen hides the Main menu. In order to resolve the problem, we have shifted the sub-menu to the right from its actual position such that the main-menu is visible.&lt;br /&gt;
&lt;br /&gt;
app/assets/stylesheets/navbar.scss&lt;br /&gt;
  .dropdown-menu.pull-left{&lt;br /&gt;
     top: 25%;&lt;br /&gt;
     left: 15%;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
== Plan of Work ==&lt;br /&gt;
&lt;br /&gt;
Following milestones have been identified to ensure the delivery of the project 1 week prior to the final deadline.&amp;lt;br/&amp;gt;&lt;br /&gt;
* Reducing Height of Menu items and pushing submenu to right side of main Menu item. - 15th November, 2015 &amp;lt;br/&amp;gt;&lt;br /&gt;
* Pushing the content below the menu - 22nd November, 2015 &amp;lt;br/&amp;gt;&lt;br /&gt;
* Changing position of menu button to left side, and changing transition from left to right. - 29th November, 2015 &amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98731</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98731"/>
		<updated>2015-11-07T04:53:14Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Running the Project Locally */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&lt;br /&gt;
 bundle install&lt;br /&gt;
 rake db:create:all&lt;br /&gt;
 rake db:migrate&lt;br /&gt;
 rails s&lt;br /&gt;
&lt;br /&gt;
==Testing using Selenium IDE==&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here].&lt;br /&gt;
&lt;br /&gt;
===Testing Instructions===&lt;br /&gt;
Follow the instructions below to test the application using selenium IDE&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Install Selenium IDE plugin for Firefox.&lt;br /&gt;
&amp;lt;li&amp;gt; Login to Expertiza using username: instructor6 &amp;amp; password: password.&lt;br /&gt;
&amp;lt;li&amp;gt; Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&amp;lt;li&amp;gt; Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file&lt;br /&gt;
&amp;lt;li&amp;gt; Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page response&lt;br /&gt;
&amp;lt;li&amp;gt; Run the script from Selenium IDE using 'Play current test case' icon.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To add a new assignment or topic and to remove an assignment or topic, we need to change the script every time to avoid duplicate record IDs. When we run the same script more than once, the test case will fail. Thus, we haven't provided test case for those scenarios.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98729</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98729"/>
		<updated>2015-11-07T04:52:39Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing using Selenium IDE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing using Selenium IDE==&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here].&lt;br /&gt;
&lt;br /&gt;
===Testing Instructions===&lt;br /&gt;
Follow the instructions below to test the application using selenium IDE&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Install Selenium IDE plugin for Firefox.&lt;br /&gt;
&amp;lt;li&amp;gt; Login to Expertiza using username: instructor6 &amp;amp; password: password.&lt;br /&gt;
&amp;lt;li&amp;gt; Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&amp;lt;li&amp;gt; Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file&lt;br /&gt;
&amp;lt;li&amp;gt; Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page response&lt;br /&gt;
&amp;lt;li&amp;gt; Run the script from Selenium IDE using 'Play current test case' icon.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To add a new assignment or topic and to remove an assignment or topic, we need to change the script every time to avoid duplicate record IDs. When we run the same script more than once, the test case will fail. Thus, we haven't provided test case for those scenarios.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1583_Fix_the_CSS_used_for_Menu_Item&amp;diff=98551</id>
		<title>CSC/ECE 517 Fall 2015 E1583 Fix the CSS used for Menu Item</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1583_Fix_the_CSS_used_for_Menu_Item&amp;diff=98551"/>
		<updated>2015-11-07T00:14:26Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Purpose ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist}}&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1583_Fix_the_CSS_used_for_Menu_Item&amp;diff=98550</id>
		<title>CSC/ECE 517 Fall 2015 E1583 Fix the CSS used for Menu Item</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1583_Fix_the_CSS_used_for_Menu_Item&amp;diff=98550"/>
		<updated>2015-11-07T00:14:09Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Purpose ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Testing ===&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist}}&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1583_Fix_the_CSS_used_for_Menu_Item&amp;diff=98549</id>
		<title>CSC/ECE 517 Fall 2015 E1583 Fix the CSS used for Menu Item</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1583_Fix_the_CSS_used_for_Menu_Item&amp;diff=98549"/>
		<updated>2015-11-07T00:13:53Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist}}&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015&amp;diff=98548</id>
		<title>CSC/ECE 517 Fall 2015</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015&amp;diff=98548"/>
		<updated>2015-11-07T00:07:41Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Final Project Design Document */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/sample_page]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/ossE1558BGJ]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss/M1502/AAAASS]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss/M1503/IntegrateXMLParser]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/ossE1568BZHXJS]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/ossE1572VGA]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/oss_E1573_sap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1559 rrz]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1570 avr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1556 CHM]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss M1504 JJD]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1562 APS]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss M1501 GSN]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss M1501 GSN]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1550 KMM]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1551 RGS]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1555 GMR]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1552 NFR]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1565 AAJ]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1561 WZL]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1553 AAJ]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1554 AAR]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1569 JNR]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1560 PSV]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss M1505 MSV]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1557 GXM]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1566 ARB]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1567 APT]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1574 BKS]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/ossA1550RAN]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1571]]&lt;br /&gt;
&lt;br /&gt;
==Final Project Design Document==&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1577 MayYellowRoverJump]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1586 AnonymousChatBetweenAuthorAndReviewer]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1582 Create integration tests for the instructor interface using capybara and rspec]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1576 Refactoring submitted content (hyperlinks and files)]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1590 Integration testing for Team creation]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1585 Use Ajax for Add Participants, Add TA ,Edit Questionnaires Screens]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1581 Integration testing for student interface]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1583 Fix the CSS used for Menu Item]]&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1583_Fix_the_CSS_used_for_Menu_Item&amp;diff=98547</id>
		<title>CSC/ECE 517 Fall 2015 E1583 Fix the CSS used for Menu Item</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1583_Fix_the_CSS_used_for_Menu_Item&amp;diff=98547"/>
		<updated>2015-11-07T00:06:48Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: Created page with &amp;quot;==Introduction==&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98505</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98505"/>
		<updated>2015-11-06T22:38:39Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing Instructions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here].&lt;br /&gt;
&lt;br /&gt;
===Testing Instructions===&lt;br /&gt;
Follow the instructions below to test the application using selenium IDE&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Install Selenium IDE plugin for Firefox.&lt;br /&gt;
&amp;lt;li&amp;gt; Login to Expertiza using username: instructor6 &amp;amp; password: password.&lt;br /&gt;
&amp;lt;li&amp;gt; Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&amp;lt;li&amp;gt; Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file&lt;br /&gt;
&amp;lt;li&amp;gt; Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page response&lt;br /&gt;
&amp;lt;li&amp;gt; Run the script from Selenium IDE using 'Play current test case' icon.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To add a new assignment or topic and to remove an assignment or topic, we need to change the script every time to avoid duplicate record IDs. When we run the same script more than once, the test case will fail. Thus, we haven't provided test case for those scenarios.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98502</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98502"/>
		<updated>2015-11-06T22:37:45Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing Instructions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here].&lt;br /&gt;
&lt;br /&gt;
===Testing Instructions===&lt;br /&gt;
Follow the instructions below to test the application using selenium IDE&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Install Selenium IDE plugin for Firefox.&lt;br /&gt;
&amp;lt;li&amp;gt; Login to Expertiza using username: instructor6 &amp;amp; password: password.&lt;br /&gt;
&amp;lt;li&amp;gt; Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&amp;lt;li&amp;gt; Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file&lt;br /&gt;
&amp;lt;li&amp;gt; Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page response&lt;br /&gt;
&amp;lt;li&amp;gt; Run the script from Selenium IDE using 'Play current test case' icon.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  To add a new assignment or topic and to remove an assignment or topic, we need to change the script every time to avoid duplicate record IDs. When we run the same script more than once, the test case will fail. Thus, we haven't provided test case for those scenarios.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98501</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98501"/>
		<updated>2015-11-06T22:37:15Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing Instructions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here].&lt;br /&gt;
&lt;br /&gt;
===Testing Instructions===&lt;br /&gt;
Follow the instructions below to test the application using selenium IDE&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Install Selenium IDE plugin for Firefox.&lt;br /&gt;
&amp;lt;li&amp;gt; Login to Expertiza using username: instructor6 &amp;amp; password: password.&lt;br /&gt;
&amp;lt;li&amp;gt; Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&amp;lt;li&amp;gt; Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file&lt;br /&gt;
&amp;lt;li&amp;gt; Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page response&lt;br /&gt;
&amp;lt;li&amp;gt; Run the script from Selenium IDE using 'Play current test case' icon&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To add a new assignment or topic and to remove an assignment or topic, we need to change the script every time to avoid duplicate record IDs. When we run the same script more than once, the test case will fail. Thus, we haven't provided test case for those scenarios.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98500</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98500"/>
		<updated>2015-11-06T22:37:06Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing using Selenium IDE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here].&lt;br /&gt;
&lt;br /&gt;
===Testing Instructions===&lt;br /&gt;
Follow the instructions below to test the application using selenium IDE&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Install Selenium IDE plugin for Firefox.&lt;br /&gt;
&amp;lt;li&amp;gt; Login to Expertiza using username: instructor6 &amp;amp; password: password.&lt;br /&gt;
&amp;lt;li&amp;gt; Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&amp;lt;li&amp;gt; Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file&lt;br /&gt;
&amp;lt;li&amp;gt; Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page response&lt;br /&gt;
&amp;lt;li&amp;gt; Run the script from Selenium IDE using 'Play current test case' icon&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98499</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98499"/>
		<updated>2015-11-06T22:36:30Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing using Selenium IDE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]. &lt;br /&gt;
To add a new assignment or topic and to remove an assignment or topic, we need to change the script every time to avoid duplicate record IDs. When we run the same script more than once, the test case will fail. Thus, we haven't provided test case for those scenarios.&lt;br /&gt;
&lt;br /&gt;
===Testing Instructions===&lt;br /&gt;
Follow the instructions below to test the application using selenium IDE&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Install Selenium IDE plugin for Firefox.&lt;br /&gt;
&amp;lt;li&amp;gt; Login to Expertiza using username: instructor6 &amp;amp; password: password.&lt;br /&gt;
&amp;lt;li&amp;gt; Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&amp;lt;li&amp;gt; Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file&lt;br /&gt;
&amp;lt;li&amp;gt; Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page response&lt;br /&gt;
&amp;lt;li&amp;gt; Run the script from Selenium IDE using 'Play current test case' icon&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98498</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98498"/>
		<updated>2015-11-06T22:36:14Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing using Selenium IDE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
To add a new assignment or topic and to remove an assignment or topic, we need to change the script every time to avoid duplicate record IDs. When we run the same script more than once, the test case will fail. Thus, we haven't provided test case for those scenarios.&lt;br /&gt;
&lt;br /&gt;
===Testing Instructions===&lt;br /&gt;
Follow the instructions below to test the application using selenium IDE&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Install Selenium IDE plugin for Firefox.&lt;br /&gt;
&amp;lt;li&amp;gt; Login to Expertiza using username: instructor6 &amp;amp; password: password.&lt;br /&gt;
&amp;lt;li&amp;gt; Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&amp;lt;li&amp;gt; Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file&lt;br /&gt;
&amp;lt;li&amp;gt; Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page response&lt;br /&gt;
&amp;lt;li&amp;gt; Run the script from Selenium IDE using 'Play current test case' icon&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98480</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98480"/>
		<updated>2015-11-06T21:48:19Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&lt;br /&gt;
===Testing Instructions===&lt;br /&gt;
Follow the instructions below to test the application using selenium IDE&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Install Selenium IDE plugin for Firefox.&lt;br /&gt;
&amp;lt;li&amp;gt; Login to Expertiza using username: instructor6 &amp;amp; password: password.&lt;br /&gt;
&amp;lt;li&amp;gt; Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&amp;lt;li&amp;gt; Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file&lt;br /&gt;
&amp;lt;li&amp;gt; Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page response&lt;br /&gt;
&amp;lt;li&amp;gt; Run the script from Selenium IDE using 'Play current test case' icon&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98479</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98479"/>
		<updated>2015-11-06T21:47:53Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing Instructions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&lt;br /&gt;
===Testing Instructions===&lt;br /&gt;
Follow the instructions below to test the application using selenium IDE&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Install Selenium IDE plugin for Firefox.&lt;br /&gt;
&amp;lt;li&amp;gt; Login to Expertiza using username: instructor6 &amp;amp; password: password.&lt;br /&gt;
&amp;lt;li&amp;gt; Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&amp;lt;li&amp;gt; Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file&lt;br /&gt;
&amp;lt;li&amp;gt; Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page response&lt;br /&gt;
&amp;lt;li&amp;gt; Run the script from Selenium IDE using 'Play current test case' icon&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98473</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98473"/>
		<updated>2015-11-06T21:44:56Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing Instructions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&lt;br /&gt;
===Testing Instructions===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Install Selenium IDE plugin for Firefox.&lt;br /&gt;
&amp;lt;li&amp;gt;2 Login to Expertiza using username: instructor6 &amp;amp; password: password.&lt;br /&gt;
&amp;lt;li&amp;gt; Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page loading.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Run the script from Selenium IDE using 'Play current test case' icon.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98471</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98471"/>
		<updated>2015-11-06T21:44:22Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing Instructions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&lt;br /&gt;
===Testing Instructions===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Install Selenium IDE plugin for Firefox.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;2 Login to Expertiza using username: instructor6 &amp;amp; password: password.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page loading.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Run the script from Selenium IDE using 'Play current test case' icon.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98470</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98470"/>
		<updated>2015-11-06T21:44:00Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing Instructions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&lt;br /&gt;
===Testing Instructions===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;1. Install Selenium IDE plugin for Firefox.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;2. Login to Expertiza using username: instructor6 &amp;amp; password: password.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;3. Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;4. Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;5. Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page loading.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;6. Run the script from Selenium IDE using 'Play current test case' icon.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98469</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98469"/>
		<updated>2015-11-06T21:43:10Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing from UI Instructions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&lt;br /&gt;
===Testing Instructions===&lt;br /&gt;
&lt;br /&gt;
1. Install Selenium IDE plugin for Firefox.&lt;br /&gt;
2. Login to Expertiza using username: instructor6 &amp;amp; password: password.&lt;br /&gt;
3. Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
4. Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file.&lt;br /&gt;
5. Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page loading.&lt;br /&gt;
6. Run the script from Selenium IDE using 'Play current test case' icon.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98467</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98467"/>
		<updated>2015-11-06T21:42:34Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing using Selenium IDE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&lt;br /&gt;
==Testing from UI Instructions==&lt;br /&gt;
&lt;br /&gt;
1. Install Selenium IDE plugin for Firefox.&lt;br /&gt;
2. Login to Expertiza using username: instructor6 &amp;amp; password: password.&lt;br /&gt;
3. Download the test scripts from [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
4. Open the test script from Selenium IDE. File -&amp;gt; open -&amp;gt; select test script html file.&lt;br /&gt;
5. Set the testing speed to slow on the speed slidebar, otherwise test may fail due to slow page loading.&lt;br /&gt;
6. Run the script from Selenium IDE using 'Play current test case' icon.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98460</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98460"/>
		<updated>2015-11-06T21:32:05Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing using Selenium IDE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98459</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98459"/>
		<updated>2015-11-06T21:31:42Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing using Selenium IDE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ Selenium IDE]&amp;lt;reference name=selenium&amp;gt;{{cite web|title=Selenium IDE Patch|url=http://www.seleniumhq.org/projects/ide/ Selenium IDE}}&amp;lt;/reference&amp;gt; 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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. Test scripts can be found [https://drive.google.com/drive/u/2/folders/0B490tipwiqqMVnVjc0FjcDdIZ2c here]&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98455</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98455"/>
		<updated>2015-11-06T20:51:56Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing using Selenium IDE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ Selenium IDE]&amp;lt;reference name=selenium&amp;gt;{{cite web|title=Selenium IDE Patch|url=http://www.seleniumhq.org/projects/ide/ Selenium IDE}}&amp;lt;/reference&amp;gt; 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98454</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98454"/>
		<updated>2015-11-06T20:51:27Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ Selenium IDE]&amp;lt;ref name=selenium&amp;gt;{{cite web|title=Selenium IDE Patch|url=http://www.seleniumhq.org/projects/ide/ Selenium IDE}}&amp;lt;/ref&amp;gt; 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98453</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98453"/>
		<updated>2015-11-06T20:51:08Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ Selenium IDE]&amp;lt;ref name=selenium&amp;gt;{{cite web|title=Selenium IDE Patch|url=http://www.seleniumhq.org/projects/ide/ Selenium IDE}}&amp;lt;/ref&amp;gt; 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98452</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98452"/>
		<updated>2015-11-06T20:50:56Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ Selenium IDE]&amp;lt;ref name=selenium&amp;gt;{{cite web|title=Selenium IDE Patch|url=http://www.seleniumhq.org/projects/ide/ Selenium IDE}}&amp;lt;/ref&amp;gt; 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;reflist/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98451</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98451"/>
		<updated>2015-11-06T20:50:17Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Testing using Selenium IDE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ Selenium IDE]&amp;lt;ref name=selenium&amp;gt;{{cite web|title=Selenium IDE Patch|url=http://www.seleniumhq.org/projects/ide/ Selenium IDE}}&amp;lt;/ref&amp;gt; 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. The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98450</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98450"/>
		<updated>2015-11-06T20:46:02Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Change to new redirect method rather using controller and action explicitly. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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 follows&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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.&amp;lt;ref&amp;gt;{{cite web|title=Selenium IDE|url=http://www.seleniumhq.org/projects/ide/|accessdate=31 October 2015}}&amp;lt;/ref&amp;gt; The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98449</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98449"/>
		<updated>2015-11-06T20:45:19Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Change to new redirect method rather using controller and action explicitly. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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&lt;br /&gt;
&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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.&amp;lt;ref&amp;gt;{{cite web|title=Selenium IDE|url=http://www.seleniumhq.org/projects/ide/|accessdate=31 October 2015}}&amp;lt;/ref&amp;gt; The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98448</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98448"/>
		<updated>2015-11-06T20:45:03Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* remove_assignment_from_course  moved to model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&lt;br /&gt;
  def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
 def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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.&amp;lt;ref&amp;gt;{{cite web|title=Selenium IDE|url=http://www.seleniumhq.org/projects/ide/|accessdate=31 October 2015}}&amp;lt;/ref&amp;gt; The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98447</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98447"/>
		<updated>2015-11-06T20:44:30Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* associate_assignment_with_course moved to model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
  def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&lt;br /&gt;
  def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Inside model,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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.&amp;lt;ref&amp;gt;{{cite web|title=Selenium IDE|url=http://www.seleniumhq.org/projects/ide/|accessdate=31 October 2015}}&amp;lt;/ref&amp;gt; The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98446</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98446"/>
		<updated>2015-11-06T20:44:03Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Refactoring Update function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&lt;br /&gt;
   session[:user]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt; def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Inside model,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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.&amp;lt;ref&amp;gt;{{cite web|title=Selenium IDE|url=http://www.seleniumhq.org/projects/ide/|accessdate=31 October 2015}}&amp;lt;/ref&amp;gt; The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98445</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98445"/>
		<updated>2015-11-06T20:43:26Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Refactoring Edit function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
   &lt;br /&gt;
   @due_date_all.each do |dd| &lt;br /&gt;
   if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
    ....&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&lt;br /&gt;
   def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
 session[:user]&lt;br /&gt;
&amp;lt;/Source&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&amp;lt;/Source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt; def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Inside model,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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.&amp;lt;ref&amp;gt;{{cite web|title=Selenium IDE|url=http://www.seleniumhq.org/projects/ide/|accessdate=31 October 2015}}&amp;lt;/ref&amp;gt; The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015&amp;diff=98444</id>
		<title>CSC/ECE 517 Fall 2015</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015&amp;diff=98444"/>
		<updated>2015-11-06T20:37:55Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: /* Writing Assignment 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/sample_page]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/ossE1558BGJ]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss/M1502/AAAASS]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss/M1503/IntegrateXMLParser]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/ossE1568BZHXJS]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/ossE1572VGA]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/oss_E1573_sap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1559 rrz]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1570 avr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1556 CHM]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss M1504 JJD]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1562 APS]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss M1501 GSN]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss M1501 GSN]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1550 KMM]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1551 RGS]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1555 GMR]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1552 NFR]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1565 AAJ]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1561 WZL]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1553 AAJ]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1554 AAR]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1569 JNR]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1560 PSV]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss M1505 MSV]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1557 GXM]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1566 ARB]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1567 APT]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1574 BKS]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/ossA1550RAN]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1571]]&lt;br /&gt;
&lt;br /&gt;
==Final Project Design Document==&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1577 MayYellowRoverJump]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1586 AnonymousChatBetweenAuthorAndReviewer]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1582 Create integration tests for the instructor interface using capybara and rspec]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1576 Refactoring submitted content (hyperlinks and files)]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1590 Integration testing for Team creation]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1585 Use Ajax for Add Participants, Add TA ,Edit Questionnaires Screens]]&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98443</id>
		<title>CSC/ECE 517 Fall 2015/oss E1571</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1571&amp;diff=98443"/>
		<updated>2015-11-06T20:33:18Z</updated>

		<summary type="html">&lt;p&gt;Sbalasu7: OSS Project - E1571 Moving wiki to valid page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Tasks Identified===&lt;br /&gt;
* Refactor edit and update method&lt;br /&gt;
* Remove irrelevant comments from the create action.&lt;br /&gt;
* associate_assignment_with_course and remove_assignment_from_course logic should be moved to model.&lt;br /&gt;
* Change to new redirect method rather using controller and action explicitly.&lt;br /&gt;
* Refactor the update_due_dates from AssignmentForm. using the DRY principle&lt;br /&gt;
* Refactor code to follow ruby style guide and Rails4 syntax.&lt;br /&gt;
&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Edit function ====&lt;br /&gt;
Edit function contains many manipulations that need be refactored into separate functions.&lt;br /&gt;
The following block contains manipulations such as checking if due_date name or description is not defined.  &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Ruby&amp;quot;&amp;gt;&lt;br /&gt;
@due_date_all.each do |dd| &lt;br /&gt;
if((!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?))&lt;br /&gt;
       @due_date_nameurl_notempty = true&lt;br /&gt;
       @due_date_nameurl_notempty_checkbox = true&lt;br /&gt;
     end&lt;br /&gt;
 ....&lt;br /&gt;
end&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This part of the code is moved into a separate function.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Ruby&amp;quot;&amp;gt;&lt;br /&gt;
def is_due_date_nameurl_notempty(dd)&lt;br /&gt;
    (!dd.deadline_name.nil?&amp;amp;&amp;amp;!dd.deadline_name.empty?)||(!dd.description_url.nil?&amp;amp;&amp;amp;!dd.description_url.empty?)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are lots of redundant code in the following snippet.And, constants are hard coded inside the code rather than defining constants. &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Ruby&amp;quot;&amp;gt;&lt;br /&gt;
 if dd.deadline_type_id==5&lt;br /&gt;
        @metareview_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @metareview_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==6&lt;br /&gt;
        @drop_topic_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @drop_topic_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==7&lt;br /&gt;
        @signup_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @signup_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
      if dd.deadline_type_id==8&lt;br /&gt;
        @team_formation_allowed = true&lt;br /&gt;
      end&lt;br /&gt;
      if @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp; @team_formation_allowed&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Redundant code is removed and made it more efficient and understandable. &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Ruby&amp;quot;&amp;gt;&lt;br /&gt;
      @metareview_allowed = is_meta_review_allowed?(dd);&lt;br /&gt;
      @drop_topic_allowed = is_drop_topic_allowed?(dd);&lt;br /&gt;
      @signup_allowed = is_signup_allowed?(dd);&lt;br /&gt;
      @team_formation_allowed = is_team_formation_allowed?(dd);&lt;br /&gt;
&lt;br /&gt;
      if dd.due_at.present?&lt;br /&gt;
        dd.due_at = dd.due_at.to_s.in_time_zone(current_user.timezonepref)&lt;br /&gt;
      end&lt;br /&gt;
      if  @due_date_nameurl_notempty &amp;amp;&amp;amp; @due_date_nameurl_notempty_checkbox &amp;amp;&amp;amp;&lt;br /&gt;
          (@metareview_allowed || @drop_topic_allowed || @signup_allowed || @team_formation_allowed)&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hard coded constants are removed and necessary constants are defined in the deadline_helper.rb helper file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Ruby&amp;quot;&amp;gt;&lt;br /&gt;
  DEADLINE_TYPE_METAREVIEW = 5&lt;br /&gt;
  DEADLINE_TYPE_DROP_TOPIC = 6&lt;br /&gt;
  DEADLINE_TYPE_SIGN_UP = 7&lt;br /&gt;
  DEADLINE_TYPE_TEAM_FORMATION = 8&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And, manipulations such as checking if metareview, drop_topic,singn_up and team_formation are allowed need to be refactored into separate functions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Ruby&amp;quot;&amp;gt;&lt;br /&gt;
  def is_meta_review_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id== DeadlineHelper::DEADLINE_TYPE_METAREVIEW&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_drop_topic_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_DROP_TOPIC&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_signup_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_SIGN_UP&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def is_team_formation_allowed?(dd)&lt;br /&gt;
    status = false&lt;br /&gt;
    if dd.deadline_type_id==DeadlineHelper::DEADLINE_TYPE_TEAM_FORMATION&lt;br /&gt;
      status = true&lt;br /&gt;
    end&lt;br /&gt;
    status&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following snippet constructs a string that need to be shown to the user when rubrics are not set by the instructor.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Ruby&amp;quot;&amp;gt;&lt;br /&gt;
 if !empty_rubrics_list.empty? and request.original_fullpath == &amp;quot;/assignments/#{@assignment_form.assignment.id}/edit&amp;quot;&lt;br /&gt;
      empty_rubrics = &amp;quot;&amp;lt;b&amp;gt;[&amp;quot;&lt;br /&gt;
      empty_rubrics_list.each do |item|&lt;br /&gt;
        empty_rubrics += item[0...-13] + &amp;quot;, &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      empty_rubrics = empty_rubrics[0...-2]&lt;br /&gt;
      empty_rubrics += &amp;quot;] &amp;lt;/b&amp;gt;&amp;quot;&lt;br /&gt;
      flash.now[:error] = &amp;quot;You did not specify all necessary rubrics: &amp;quot; +empty_rubrics+&amp;quot; of assignment &amp;lt;b&amp;gt;#{@assignment_form.assignment.name}&amp;lt;/b&amp;gt; before saving the assignment. You can assign rubrics &amp;lt;a id='go_to_tabs2' style='color: blue;'&amp;gt;here&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Ruby&amp;quot;&amp;gt;&lt;br /&gt;
 def needed_rubrics(empty_rubrics_list)&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Refactoring out into separate functions makes the code more readable and understandable.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring Update function ====&lt;br /&gt;
&lt;br /&gt;
Update function of the Assignment controller helps in updating the resources after editing it. &lt;br /&gt;
The following code retrieves the data of the user logged in.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
 session[:user]&lt;br /&gt;
&amp;lt;/Source&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Explicit URL creation using controller name and controller action is refactored in such a way that helper functions create the URL when required.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
 redirect_to :action =&amp;gt; 'edit', :id =&amp;gt; @assignment.id  # Incorrect&lt;br /&gt;
 redirect_to edit_assignment_path @assignment.id    # Correct&lt;br /&gt;
&amp;lt;/Source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Remove irrelevant comments from the create action ====&lt;br /&gt;
The Create action has a few comments which are irrelevant and make the method bulky. These could be safely removed from the code.&lt;br /&gt;
&lt;br /&gt;
==== associate_assignment_with_course moved to model ====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Inside controller action, &lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt; def associate_assignment_with_course&lt;br /&gt;
    @assignment = Assignment.find(params[:id])&lt;br /&gt;
    @courses = Assignment.set_courses_to_assignment(current_user)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside model,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def self.set_courses_to_assignment(user)&lt;br /&gt;
    @courses=Course.where(instructor_id: user.id).order(:name)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== remove_assignment_from_course  moved to model ====&lt;br /&gt;
All the current logic here, except for the &amp;quot;save&amp;quot; and &amp;quot;redirect_to&amp;quot; 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.&lt;br /&gt;
Inside controller action,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def remove_assignment_from_course&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    Assignment.remove_assignment_from_course(assignment)&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Inside model,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def self.remove_assignment_from_course(assignment)&lt;br /&gt;
    oldpath = assignment.path rescue nil&lt;br /&gt;
    assignment.course_id = nil&lt;br /&gt;
    assignment.save&lt;br /&gt;
    newpath = assignment.path rescue nil&lt;br /&gt;
    FileHelper.update_file_location(oldpath, newpath)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Change to new redirect method rather using controller and action explicitly. ====&lt;br /&gt;
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&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
  def toggle_access&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    assignment.private = !assignment.private&lt;br /&gt;
    assignment.save&lt;br /&gt;
    redirect_to list_tree_display_index_path&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactor the update_due_dates from AssignmentForm using the DRY principle ====&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Impact Analysis ====&lt;br /&gt;
* Tested using [http://www.seleniumhq.org/projects/ide/ Selenium IDE], the associated objects , assignment and course before and after the change. Testing confirms that the objects and their interactions have not changed.&lt;br /&gt;
* Addition of new methods do not coincide with the performance of currently existent methods.&lt;br /&gt;
* Removal of existing code does not lead to reduced/loss of functionality.&lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/application_controller.rb&lt;br /&gt;
* models/Assignment.rb&lt;br /&gt;
* models/User.rb&lt;br /&gt;
* views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
The project could be run locally by cloning the Github repository [https://github.com/codemonkey19/expertiza expertiza] and then running the following commands sequentially.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;unix&amp;quot;&amp;gt;&lt;br /&gt;
bundle install&lt;br /&gt;
rake db:create:all&lt;br /&gt;
rake db:migrate&lt;br /&gt;
rails s&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing using Selenium IDE===&lt;br /&gt;
[http://www.seleniumhq.org/projects/ide/ 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.&amp;lt;ref&amp;gt;{{cite web|title=Selenium IDE|url=http://www.seleniumhq.org/projects/ide/|accessdate=31 October 2015}}&amp;lt;/ref&amp;gt; The UI automation helps in testing quickly yet rigorously. Major test cases identified are following&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Loading assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Creating assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Editing assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Updating due dates for assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Associating assignments to a course&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Deleting assignments&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
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.&lt;br /&gt;
* There exists lot of redundant code which code be refactored into methods.&lt;br /&gt;
* Unused variables and deprecated methods could be ridden off from the code base.&lt;br /&gt;
* The test cases are written only for the methods that came under the scope of this project. But there is room for implementing test cases for the other actions too.&lt;br /&gt;
* In an MVC framework, most of the business logic should be within the Model. Work needs to be done on this front to make it more close to this convention of Rails.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sbalasu7</name></author>
	</entry>
</feed>