<?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=Nurahman</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=Nurahman"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Nurahman"/>
	<updated>2026-06-06T03:57:57Z</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_2014/OSS_E1461_knn&amp;diff=91460</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=91460"/>
		<updated>2014-11-06T01:38:58Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
==StudentTeamController==&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Refactoring of Old Code=&lt;br /&gt;
==Using Routing Helpers==&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Pluralize StudentTeamController Class Name==&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Style Changes Based on Current Conventions==&lt;br /&gt;
&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
&lt;br /&gt;
===Non-SQL Style Where Method Calls===&lt;br /&gt;
&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Refactored Where Method Calls===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use good array checking===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(check.length == 0)&lt;br /&gt;
(check[0].name &amp;lt;=&amp;gt; @team.name) == 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They were changed to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
matching_teams.length.zero?&lt;br /&gt;
(matching_teams[0].name &amp;lt;=&amp;gt; team.name).zero?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Use boolean-like objects in conditionals==&lt;br /&gt;
Replace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !first_waitlisted_user.nil?&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if first_waitlisted_user&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Removed Comment out Code==&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Work left to be Done=&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
==Change View to Show==&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
==Do Bookkeeping in Models not in the Controllers==&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
==RSpec Functional Testing==&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
Instructions to Manual Testing:&amp;lt;br&amp;gt;&lt;br /&gt;
1) Open Expertiza Website http://152.46.20.188:3000/ &amp;lt;br&amp;gt;&lt;br /&gt;
2) Login using Username: user2 and Password: password &amp;lt;br&amp;gt;&lt;br /&gt;
3) Click on Assignments on Top Bar &amp;lt;br&amp;gt;&lt;br /&gt;
4) Choose assignment Team Test 2 &amp;lt;br&amp;gt;&lt;br /&gt;
5) Click on Your Team &amp;lt;br&amp;gt;&lt;br /&gt;
6) From this next page, 4 methods can be tested:&amp;lt;br&amp;gt;&lt;br /&gt;
   -Make Advertisement&lt;br /&gt;
   -Remove Advertisement&lt;br /&gt;
   -Edit Teamname, I would request doing undo if you do try to change it&lt;br /&gt;
   -Leave Team, I would request doing undo if you do test this feature &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:studentteamtest.jpg|center|alt= TEST Verification of Methods.]]&lt;br /&gt;
&lt;br /&gt;
==Additional Changes to Name==&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
==Unessisary Member Variables==&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
==Clean up Permissions==&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces `action_allowed?` to happen before any other before actions. This causes any prerequisite or dependent conditions in action_allowed? to have to be set inside `action_allowed?`. However, this method is not called in the case of a Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
As you can see, the view method checks permissions again in this call (outside action_allowed?). In addition, this is not very dry, as the are defined here copies of the actual permissions set in the InitiationsController.&lt;br /&gt;
&lt;br /&gt;
This could be addressed to clean up the beginning of the controller. However, this is a sweeping change across the whole codebase.&lt;br /&gt;
&lt;br /&gt;
==Bug in Create==&lt;br /&gt;
&lt;br /&gt;
There exists a bug in the create call. Currently, Ruby throws:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;comparison of Fixnum with nil failed&amp;lt;/pre&amp;gt;&lt;br /&gt;
on&lt;br /&gt;
&amp;lt;pre&amp;gt;TeamNode.create parent_id: parent.id, node_object_id: team.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This hapens with the unrefactored codebase (Git Rev d2144d13a6fd26203e464a90beaaaceb69506c6f) as well.&lt;br /&gt;
&lt;br /&gt;
==Remove Dynamic Finders==&lt;br /&gt;
Dynamic Finders (find_by_xxx_yyyy) are depreciated in Rails 4. They should be replaced by `where(xxx: ,yyy:).first` or by `find_by` (non-dynamic find_by is not depreciated).&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Style Guide]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/ Expertiza Github Repository]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/431 Pull Request for E1461]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=91374</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=91374"/>
		<updated>2014-11-04T03:24:05Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* RSpec Functional Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
==StudentTeamController==&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Refactoring of Old Code=&lt;br /&gt;
==Using Routing Helpers==&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Pluralize StudentTeamController Class Name==&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Style Changes Based on Current Conventions==&lt;br /&gt;
&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
&lt;br /&gt;
===Non-SQL Style Where Method Calls===&lt;br /&gt;
&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Refactored Where Method Calls===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use good array checking===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(check.length == 0)&lt;br /&gt;
(check[0].name &amp;lt;=&amp;gt; @team.name) == 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They were changed to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
matching_teams.length.zero?&lt;br /&gt;
(matching_teams[0].name &amp;lt;=&amp;gt; team.name).zero?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Use boolean-like objects in conditionals==&lt;br /&gt;
Replace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !first_waitlisted_user.nil?&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if first_waitlisted_user&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Removed Comment out Code==&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Work left to be Done=&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
==Change View to Show==&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
==Do Bookeeping in Models not in the Controllers==&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
==RSpec Functional Testing==&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
Instructions to Manual Testing:&amp;lt;br&amp;gt;&lt;br /&gt;
1) Open Expertiza Website http://152.46.20.188:3000/ &amp;lt;br&amp;gt;&lt;br /&gt;
2) Login using Username: user2 and Password: password &amp;lt;br&amp;gt;&lt;br /&gt;
3) Click on Assignments on Top Bar &amp;lt;br&amp;gt;&lt;br /&gt;
4) Choose assignment Team Test 2 &amp;lt;br&amp;gt;&lt;br /&gt;
5) Click on Your Team &amp;lt;br&amp;gt;&lt;br /&gt;
6) From this next page, 4 methods can be tested:&amp;lt;br&amp;gt;&lt;br /&gt;
   -Make Advertisement&lt;br /&gt;
   -Remove Advertisement&lt;br /&gt;
   -Edit Teamname, I would request doing undo if you do try to change it&lt;br /&gt;
   -Leave Team, I would request doing undo if you do test this feature &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:studentteamtest.jpg|center|alt= TEST Verification of Methods.]]&lt;br /&gt;
&lt;br /&gt;
==Additional Changes to Name==&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
==Unessisary Member Variables==&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
==Clean up Permissions==&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces `action_allowed?` to happen before any other before actions. This causes any prerequisite or dependent conditions in action_allowed? to have to be set inside `action_allowed?`. However, this method is not called in the case of a Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
As you can see, the view method checks permissions again in this call (outside action_allowed?). In addition, this is not very dry, as the are defined here copies of the actual permissions set in the InitiationsController.&lt;br /&gt;
&lt;br /&gt;
This could be addressed to clean up the beginning of the controller. However, this is a sweeping change across the whole codebase.&lt;br /&gt;
&lt;br /&gt;
==Bug in Create==&lt;br /&gt;
&lt;br /&gt;
There exists a bug in the create call. Currently, Ruby throws:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;comparison of Fixnum with nil failed&amp;lt;/pre&amp;gt;&lt;br /&gt;
on&lt;br /&gt;
&amp;lt;pre&amp;gt;TeamNode.create parent_id: parent.id, node_object_id: team.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This hapens with the unrefactored codebase (Git Rev d2144d13a6fd26203e464a90beaaaceb69506c6f) as well.&lt;br /&gt;
&lt;br /&gt;
==Remove Dynamic Finders==&lt;br /&gt;
Dynamic Finders (find_by_xxx_yyyy) are depreciated in Rails 4. They should be replaced by `where(xxx: ,yyy:).first` or by `find_by` (non-dynamic find_by is not depreciated).&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Style Guide]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/ Expertiza Github Repository]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/431 Pull Request for E1461]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=91373</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=91373"/>
		<updated>2014-11-04T03:23:04Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* RSpec Functional Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
==StudentTeamController==&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Refactoring of Old Code=&lt;br /&gt;
==Using Routing Helpers==&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Pluralize StudentTeamController Class Name==&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Style Changes Based on Current Conventions==&lt;br /&gt;
&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
&lt;br /&gt;
===Non-SQL Style Where Method Calls===&lt;br /&gt;
&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Refactored Where Method Calls===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use good array checking===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(check.length == 0)&lt;br /&gt;
(check[0].name &amp;lt;=&amp;gt; @team.name) == 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They were changed to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
matching_teams.length.zero?&lt;br /&gt;
(matching_teams[0].name &amp;lt;=&amp;gt; team.name).zero?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Use boolean-like objects in conditionals==&lt;br /&gt;
Replace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !first_waitlisted_user.nil?&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if first_waitlisted_user&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Removed Comment out Code==&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Work left to be Done=&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
==Change View to Show==&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
==Do Bookeeping in Models not in the Controllers==&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
==RSpec Functional Testing==&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
Instructions to Manual Testing:&lt;br /&gt;
1) Open Expertiza Website http://152.46.20.188:3000/ &lt;br /&gt;
2) Login using Username: user2 and Password: password&lt;br /&gt;
3) Click on Assignments on Top Bar&lt;br /&gt;
4) Choose assignment Team Test 2&lt;br /&gt;
5) Click on Your Team&lt;br /&gt;
6) From this next page, 4 methods can be tested:&lt;br /&gt;
   -Make Advertisement&lt;br /&gt;
   -Remove Advertisement&lt;br /&gt;
   -Edit Teamname, I would request doing undo if you do try to change it&lt;br /&gt;
   -Leave Team, I would request doing undo if you do test this feature &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:studentteamtest.jpg|center|alt= TEST Verification of Methods.]]&lt;br /&gt;
&lt;br /&gt;
==Additional Changes to Name==&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
==Unessisary Member Variables==&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
==Clean up Permissions==&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces `action_allowed?` to happen before any other before actions. This causes any prerequisite or dependent conditions in action_allowed? to have to be set inside `action_allowed?`. However, this method is not called in the case of a Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
As you can see, the view method checks permissions again in this call (outside action_allowed?). In addition, this is not very dry, as the are defined here copies of the actual permissions set in the InitiationsController.&lt;br /&gt;
&lt;br /&gt;
This could be addressed to clean up the beginning of the controller. However, this is a sweeping change across the whole codebase.&lt;br /&gt;
&lt;br /&gt;
==Bug in Create==&lt;br /&gt;
&lt;br /&gt;
There exists a bug in the create call. Currently, Ruby throws:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;comparison of Fixnum with nil failed&amp;lt;/pre&amp;gt;&lt;br /&gt;
on&lt;br /&gt;
&amp;lt;pre&amp;gt;TeamNode.create parent_id: parent.id, node_object_id: team.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This hapens with the unrefactored codebase (Git Rev d2144d13a6fd26203e464a90beaaaceb69506c6f) as well.&lt;br /&gt;
&lt;br /&gt;
==Remove Dynamic Finders==&lt;br /&gt;
Dynamic Finders (find_by_xxx_yyyy) are depreciated in Rails 4. They should be replaced by `where(xxx: ,yyy:).first` or by `find_by` (non-dynamic find_by is not depreciated).&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Style Guide]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/ Expertiza Github Repository]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/431 Pull Request for E1461]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=90731</id>
		<title>CSC/ECE 517 Fall 2014</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=90731"/>
		<updated>2014-10-29T20:01:06Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2014/sample_page]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 22 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 19 mx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 3 zq]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 lf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 wl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a a7 ch]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 rs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 jf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 os]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 15 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 10 hu]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 kv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 21 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 24 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 6 rl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 2 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 16 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 rm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 sj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 23 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 rn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 22 sp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss M1454 rss]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 gn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 13 va]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 kn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 ks]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 7 kz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_6_bn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 10 zz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 16 va]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a F1415 rv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_3_cp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1b 26 sa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_28_cg]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 29 ry]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 30 cs]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_33_jy]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_27_js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1453 syy]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1463 vpd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1465 oak]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1456_kdv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1453_sst]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_E1456_akk]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1455_asa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1458_sst]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1457_ags]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1466_gjf]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1452_jns]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1462_nms]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_S1455_ajp]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_S1454_ccc]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1450_cxm]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1455_skn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_M1450_vda]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1467_rsv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1464_vnn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_M1451_ahs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_E1451_las]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_E1461_knn]]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_snn&amp;diff=90727</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 snn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_snn&amp;diff=90727"/>
		<updated>2014-10-29T19:51:33Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: Created page with &amp;quot;'''Expertiza - Refactoring StudentTeamController'''  __TOC__  =Introduction= Expertiza is an open source web application created by NCSU give a interface for team learning and pe...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
==StudentTeamController==&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Refactoring of Old Code=&lt;br /&gt;
==Using Routing Helpers==&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Pluralize StudentTeamController Class Name==&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Style Changes Based on Current Conventions==&lt;br /&gt;
&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
&lt;br /&gt;
===Non-SQL Style Where Method Calls===&lt;br /&gt;
&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Refactored Where Method Calls===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use good array checking===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(check.length == 0)&lt;br /&gt;
(check[0].name &amp;lt;=&amp;gt; @team.name) == 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They were changed to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
matching_teams.length.zero?&lt;br /&gt;
(matching_teams[0].name &amp;lt;=&amp;gt; team.name).zero?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Use boolean-like objects in conditionals==&lt;br /&gt;
Replace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !first_waitlisted_user.nil?&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if first_waitlisted_user&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Removed Comment out Code==&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Work left to be Done=&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
==Change View to Show==&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
==Do Bookeeping in Models not in the Controllers==&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
==RSpec Functional Testing==&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
[[File:studentteamtest.jpg|center|alt= TEST Verification of Methods.]]&lt;br /&gt;
&lt;br /&gt;
==Additional Changes to Name==&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
==Unessisary Member Variables==&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
==Clean up Permissions==&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces `action_allowed?` to happen before any other before actions. This causes any prerequisite or dependent conditions in action_allowed? to have to be set inside `action_allowed?`. However, this method is not called in the case of a Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
As you can see, the view method checks permissions again in this call (outside action_allowed?). In addition, this is not very dry, as the are defined here copies of the actual permissions set in the InitiationsController.&lt;br /&gt;
&lt;br /&gt;
This could be addressed to clean up the beginning of the controller. However, this is a sweeping change across the whole codebase.&lt;br /&gt;
&lt;br /&gt;
==Bug in Create==&lt;br /&gt;
&lt;br /&gt;
There exists a bug in the create call. Currently, Ruby throws:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;comparison of Fixnum with nil failed&amp;lt;/pre&amp;gt;&lt;br /&gt;
on&lt;br /&gt;
&amp;lt;pre&amp;gt;TeamNode.create parent_id: parent.id, node_object_id: team.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This hapens with the unrefactored codebase (Git Rev d2144d13a6fd26203e464a90beaaaceb69506c6f) as well.&lt;br /&gt;
&lt;br /&gt;
==Remove Dynamic Finders==&lt;br /&gt;
Dynamic Finders (find_by_xxx_yyyy) are depreciated in Rails 4. They should be replaced by `where(xxx: ,yyy:).first` or by `find_by` (non-dynamic find_by is not depreciated).&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Style Guide]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/ Expertiza Github Repository]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/431 Pull Request for E1461]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=90723</id>
		<title>CSC/ECE 517 Fall 2014</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=90723"/>
		<updated>2014-10-29T19:49:54Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2014/sample_page]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 22 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 19 mx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 3 zq]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 lf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 wl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a a7 ch]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 rs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 jf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 os]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 15 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 10 hu]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 kv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 21 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 24 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 6 rl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 2 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 16 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 rm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 sj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 23 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 rn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 22 sp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss M1454 rss]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 gn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 13 va]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 kn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 ks]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 7 kz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_6_bn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 10 zz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 16 va]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a F1415 rv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_3_cp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1b 26 sa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_28_cg]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 29 ry]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 30 cs]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_33_jy]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_27_js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1453 syy]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1463 vpd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1465 oak]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1456_kdv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1453_sst]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_E1456_akk]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1455_asa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1458_sst]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1457_ags]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1466_gjf]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1452_jns]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1462_nms]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_S1455_ajp]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_S1454_ccc]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1450_cxm]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1455_skn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_M1450_vda]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1467_rsv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1464_vnn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_M1451_ahs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_E1451_las]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_E1461_snn]]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=90720</id>
		<title>CSC/ECE 517 Fall 2014</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=90720"/>
		<updated>2014-10-29T19:49:30Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2014/sample_page]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 22 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 19 mx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 3 zq]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 lf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 wl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a a7 ch]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 rs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 jf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 os]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 15 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 10 hu]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 kv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 21 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 24 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 6 rl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 2 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 16 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 rm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 sj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 23 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 rn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 22 sp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss M1454 rss]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 gn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 13 va]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 kn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 ks]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 7 kz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_6_bn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 10 zz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 16 va]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a F1415 rv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_3_cp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1b 26 sa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_28_cg]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 29 ry]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 30 cs]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_33_jy]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_27_js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1453 syy]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1463 vpd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1465 oak]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1456_kdv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1453_sst]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_E1456_akk]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1455_asa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1458_sst]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1457_ags]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1466_gjf]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1452_jns]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1462_nms]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_S1455_ajp]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_S1454_ccc]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1450_cxm]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1455_skn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_M1450_vda]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1467_rsv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1464_vnn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_M1451_ahs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_E1451_las]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_E1461_snn http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1461_knn]]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=90719</id>
		<title>CSC/ECE 517 Fall 2014</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=90719"/>
		<updated>2014-10-29T19:49:08Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2014/sample_page]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 22 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 19 mx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 3 zq]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 lf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 wl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a a7 ch]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 rs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 jf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 os]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 15 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 10 hu]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 kv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 21 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 24 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 6 rl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 2 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 16 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 rm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 sj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 23 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 rn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 22 sp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss M1454 rss]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 gn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 13 va]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 kn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 ks]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 7 kz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_6_bn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 10 zz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 16 va]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a F1415 rv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_3_cp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1b 26 sa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_28_cg]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 29 ry]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 30 cs]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_33_jy]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_27_js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1453 syy]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1463 vpd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1465 oak]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1456_kdv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1453_sst]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_E1456_akk]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1455_asa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1458_sst]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1457_ags]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1466_gjf]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1452_jns]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1462_nms]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_S1455_ajp]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_S1454_ccc]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1450_cxm]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1455_skn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_M1450_vda]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1467_rsv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1464_vnn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_M1451_ahs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_E1451_las]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_E1461_snn http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1461_knn]]*&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=90715</id>
		<title>CSC/ECE 517 Fall 2014</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=90715"/>
		<updated>2014-10-29T19:47:26Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2014/sample_page]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 22 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 19 mx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 3 zq]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 lf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 wl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a a7 ch]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 rs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 jf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 os]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 15 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 10 hu]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 kv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 21 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 24 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 6 rl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 2 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 16 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 rm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 sj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 23 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 rn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 22 sp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss M1454 rss]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 gn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 13 va]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 kn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 ks]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 7 kz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_6_bn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 10 zz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 16 va]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a F1415 rv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_3_cp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1b 26 sa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_28_cg]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 29 ry]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 30 cs]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_33_jy]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_27_js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1453 syy]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1463 vpd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1465 oak]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1456_kdv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1453_sst]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_E1456_akk]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1455_asa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1458_sst]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1457_ags]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1466_gjf]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1452_jns]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1462_nms]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_S1455_ajp]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_S1454_ccc]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1450_cxm]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1455_skn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_M1450_vda]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1467_rsv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1464_vnn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_M1451_ahs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_E1451_las]]&lt;br /&gt;
*[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/OSS_E1461_knn]*&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90289</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90289"/>
		<updated>2014-10-29T02:39:30Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* Use boolean-like objects in conditionals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
==StudentTeamController==&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Refactoring of Old Code=&lt;br /&gt;
==Using Routing Helpers==&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Pluralize StudentTeamController Class Name==&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Style Changes Based on Current Conventions==&lt;br /&gt;
&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
&lt;br /&gt;
===Non-SQL Style Where Method Calls===&lt;br /&gt;
&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Refactored Where Method Calls===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use good array checking===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(check.length == 0)&lt;br /&gt;
(check[0].name &amp;lt;=&amp;gt; @team.name) == 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They were changed to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
matching_teams.length.zero?&lt;br /&gt;
(matching_teams[0].name &amp;lt;=&amp;gt; team.name).zero?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Use boolean-like objects in conditionals==&lt;br /&gt;
Replace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !first_waitlisted_user.nil?&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if first_waitlisted_user&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Removed Comment out Code==&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Work left to be Done=&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
==Change View to Show==&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
==Do Bookeeping in Models not in the Controllers==&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
==RSpec Functional Testing==&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
[[File:studentteamtest.jpg|center|alt= TEST Verification of Methods.]]&lt;br /&gt;
&lt;br /&gt;
==Additional Changes to Name==&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
==Unessisary Member Variables==&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
==Clean up Permissions==&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces `action_allowed?` to happen before any other before actions. This causes any prerequisite or dependent conditions in action_allowed? to have to be set inside `action_allowed?`. However, this method is not called in the case of a Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
As you can see, the view method checks permissions again in this call (outside action_allowed?). In addition, this is not very dry, as the are defined here copies of the actual permissions set in the InitiationsController.&lt;br /&gt;
&lt;br /&gt;
This could be addressed to clean up the beginning of the controller. However, this is a sweeping change across the whole codebase.&lt;br /&gt;
&lt;br /&gt;
==Bug in Create==&lt;br /&gt;
&lt;br /&gt;
There exists a bug in the create call. Currently, Ruby throws:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;comparison of Fixnum with nil failed&amp;lt;/pre&amp;gt;&lt;br /&gt;
on&lt;br /&gt;
&amp;lt;pre&amp;gt;TeamNode.create parent_id: parent.id, node_object_id: team.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This hapens with the unrefactored codebase (Git Rev d2144d13a6fd26203e464a90beaaaceb69506c6f) as well.&lt;br /&gt;
&lt;br /&gt;
==Remove Dynamic Finders==&lt;br /&gt;
Dynamic Finders (find_by_xxx_yyyy) are depreciated in Rails 4. They should be replaced by `where(xxx: ,yyy:).first` or by `find_by` (non-dynamic find_by is not depreciated).&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Style Guide]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/ Expertiza Github Repository]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/431 Pull Request for E1461]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90288</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90288"/>
		<updated>2014-10-29T02:39:18Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* Use good array checking */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
==StudentTeamController==&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Refactoring of Old Code=&lt;br /&gt;
==Using Routing Helpers==&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Pluralize StudentTeamController Class Name==&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Style Changes Based on Current Conventions==&lt;br /&gt;
&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
&lt;br /&gt;
===Non-SQL Style Where Method Calls===&lt;br /&gt;
&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Refactored Where Method Calls===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use good array checking===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(check.length == 0)&lt;br /&gt;
(check[0].name &amp;lt;=&amp;gt; @team.name) == 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They were changed to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
matching_teams.length.zero?&lt;br /&gt;
(matching_teams[0].name &amp;lt;=&amp;gt; team.name).zero?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Use boolean-like objects in conditionals==&lt;br /&gt;
Replace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if !first_waitlisted_user.nil?&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if first_waitlisted_user&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use boolean-like objects in conditionals==&lt;br /&gt;
Replace&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Removed Comment out Code==&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Work left to be Done=&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
==Change View to Show==&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
==Do Bookeeping in Models not in the Controllers==&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
==RSpec Functional Testing==&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
[[File:studentteamtest.jpg|center|alt= TEST Verification of Methods.]]&lt;br /&gt;
&lt;br /&gt;
==Additional Changes to Name==&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
==Unessisary Member Variables==&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
==Clean up Permissions==&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces `action_allowed?` to happen before any other before actions. This causes any prerequisite or dependent conditions in action_allowed? to have to be set inside `action_allowed?`. However, this method is not called in the case of a Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
As you can see, the view method checks permissions again in this call (outside action_allowed?). In addition, this is not very dry, as the are defined here copies of the actual permissions set in the InitiationsController.&lt;br /&gt;
&lt;br /&gt;
This could be addressed to clean up the beginning of the controller. However, this is a sweeping change across the whole codebase.&lt;br /&gt;
&lt;br /&gt;
==Bug in Create==&lt;br /&gt;
&lt;br /&gt;
There exists a bug in the create call. Currently, Ruby throws:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;comparison of Fixnum with nil failed&amp;lt;/pre&amp;gt;&lt;br /&gt;
on&lt;br /&gt;
&amp;lt;pre&amp;gt;TeamNode.create parent_id: parent.id, node_object_id: team.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This hapens with the unrefactored codebase (Git Rev d2144d13a6fd26203e464a90beaaaceb69506c6f) as well.&lt;br /&gt;
&lt;br /&gt;
==Remove Dynamic Finders==&lt;br /&gt;
Dynamic Finders (find_by_xxx_yyyy) are depreciated in Rails 4. They should be replaced by `where(xxx: ,yyy:).first` or by `find_by` (non-dynamic find_by is not depreciated).&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Style Guide]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/ Expertiza Github Repository]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/431 Pull Request for E1461]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90285</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90285"/>
		<updated>2014-10-29T02:37:49Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* Use good array checking */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
==StudentTeamController==&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Refactoring of Old Code=&lt;br /&gt;
==Using Routing Helpers==&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Pluralize StudentTeamController Class Name==&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Style Changes Based on Current Conventions==&lt;br /&gt;
&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
&lt;br /&gt;
===Non-SQL Style Where Method Calls===&lt;br /&gt;
&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Refactored Where Method Calls===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use good array checking===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(check.length == 0)&lt;br /&gt;
(check[0].name &amp;lt;=&amp;gt; @team.name) == 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They were changed to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
matching_teams.length.zero?&lt;br /&gt;
(matching_teams[0].name &amp;lt;=&amp;gt; team.name).zero?&lt;br /&gt;
&lt;br /&gt;
if !first_waitlisted_user.nil?&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if first_waitlisted_user&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Use boolean-like objects in conditionals==&lt;br /&gt;
Replace&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Removed Comment out Code==&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Work left to be Done=&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
==Change View to Show==&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
==Do Bookeeping in Models not in the Controllers==&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
==RSpec Functional Testing==&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
[[File:studentteamtest.jpg|center|alt= TEST Verification of Methods.]]&lt;br /&gt;
&lt;br /&gt;
==Additional Changes to Name==&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
==Unessisary Member Variables==&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
==Clean up Permissions==&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces `action_allowed?` to happen before any other before actions. This causes any prerequisite or dependent conditions in action_allowed? to have to be set inside `action_allowed?`. However, this method is not called in the case of a Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
As you can see, the view method checks permissions again in this call (outside action_allowed?). In addition, this is not very dry, as the are defined here copies of the actual permissions set in the InitiationsController.&lt;br /&gt;
&lt;br /&gt;
This could be addressed to clean up the beginning of the controller. However, this is a sweeping change across the whole codebase.&lt;br /&gt;
&lt;br /&gt;
==Bug in Create==&lt;br /&gt;
&lt;br /&gt;
There exists a bug in the create call. Currently, Ruby throws:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;comparison of Fixnum with nil failed&amp;lt;/pre&amp;gt;&lt;br /&gt;
on&lt;br /&gt;
&amp;lt;pre&amp;gt;TeamNode.create parent_id: parent.id, node_object_id: team.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This hapens with the unrefactored codebase (Git Rev d2144d13a6fd26203e464a90beaaaceb69506c6f) as well.&lt;br /&gt;
&lt;br /&gt;
==Remove Dynamic Finders==&lt;br /&gt;
Dynamic Finders (find_by_xxx_yyyy) are depreciated in Rails 4. They should be replaced by `where(xxx: ,yyy:).first` or by `find_by` (non-dynamic find_by is not depreciated).&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Style Guide]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/ Expertiza Github Repository]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/431 Pull Request for E1461]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90282</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90282"/>
		<updated>2014-10-29T02:36:31Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* Use good array checking */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
==StudentTeamController==&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Refactoring of Old Code=&lt;br /&gt;
==Using Routing Helpers==&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Pluralize StudentTeamController Class Name==&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Style Changes Based on Current Conventions==&lt;br /&gt;
&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
&lt;br /&gt;
===Non-SQL Style Where Method Calls===&lt;br /&gt;
&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Refactored Where Method Calls===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use good array checking===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(check.length == 0)&lt;br /&gt;
(check[0].name &amp;lt;=&amp;gt; @team.name) == 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They were changed to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
matching_teams.length.zero?&lt;br /&gt;
(matching_teams[0].name &amp;lt;=&amp;gt; team.name).zero?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if !first_waitlisted_user.nil?&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if first_waitlisted_user&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==Use boolean-like objects in conditionals==&lt;br /&gt;
Replace&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Removed Comment out Code==&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Work left to be Done=&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
==Change View to Show==&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
==Do Bookeeping in Models not in the Controllers==&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
==RSpec Functional Testing==&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
[[File:studentteamtest.jpg|center|alt= TEST Verification of Methods.]]&lt;br /&gt;
&lt;br /&gt;
==Additional Changes to Name==&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
==Unessisary Member Variables==&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
==Clean up Permissions==&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces `action_allowed?` to happen before any other before actions. This causes any prerequisite or dependent conditions in action_allowed? to have to be set inside `action_allowed?`. However, this method is not called in the case of a Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
As you can see, the view method checks permissions again in this call (outside action_allowed?). In addition, this is not very dry, as the are defined here copies of the actual permissions set in the InitiationsController.&lt;br /&gt;
&lt;br /&gt;
This could be addressed to clean up the beginning of the controller. However, this is a sweeping change across the whole codebase.&lt;br /&gt;
&lt;br /&gt;
==Bug in Create==&lt;br /&gt;
&lt;br /&gt;
There exists a bug in the create call. Currently, Ruby throws:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;comparison of Fixnum with nil failed&amp;lt;/pre&amp;gt;&lt;br /&gt;
on&lt;br /&gt;
&amp;lt;pre&amp;gt;TeamNode.create parent_id: parent.id, node_object_id: team.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This hapens with the unrefactored codebase (Git Rev d2144d13a6fd26203e464a90beaaaceb69506c6f) as well.&lt;br /&gt;
&lt;br /&gt;
==Remove Dynamic Finders==&lt;br /&gt;
Dynamic Finders (find_by_xxx_yyyy) are depreciated in Rails 4. They should be replaced by `where(xxx: ,yyy:).first` or by `find_by` (non-dynamic find_by is not depreciated).&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Style Guide]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/ Expertiza Github Repository]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/431 Pull Request for E1461]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90235</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90235"/>
		<updated>2014-10-29T01:40:07Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* RSpec Functional Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
==StudentTeamController==&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Refactoring of Old Code=&lt;br /&gt;
==Using Routing Helpers==&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Pluralize StudentTeamController Class Name==&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Style Changes Based on Current Conventions==&lt;br /&gt;
&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
&lt;br /&gt;
===Non-SQL Style Where Method Calls===&lt;br /&gt;
&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Refactored Where Method Calls===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use good array checking===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(check.length == 0)&lt;br /&gt;
(check[0].name &amp;lt;=&amp;gt; @team.name) == 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They were changed to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
matching_teams.length.zero?&lt;br /&gt;
(matching_teams[0].name &amp;lt;=&amp;gt; team.name).zero?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if !first_waitlisted_user.nil?&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if first_waitlisted_user&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==Use boolean-like objects in conditionals==&lt;br /&gt;
Replace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Removed Comment out Code==&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Work left to be Done=&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
==Change View to Show==&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
==Do Bookeeping in Models not in the Controllers==&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
==RSpec Functional Testing==&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
[[File:studentteamtest.jpg|center|alt= TEST Verification of Methods.]]&lt;br /&gt;
&lt;br /&gt;
==Additional Changes to Name==&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
==Unessisary Member Variables==&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
==Clean up Permissions==&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces `action_allowed?` to happen before any other before actions. This causes any prerequisite or dependent conditions in action_allowed? to have to be set inside `action_allowed?`. However, this method is not called in the case of a Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
As you can see, the view method checks permissions again in this call (outside action_allowed?). In addition, this is not very dry, as the are defined here copies of the actual permissions set in the InitiationsController.&lt;br /&gt;
&lt;br /&gt;
This could be addressed to clean up the beginning of the controller. However, this is a sweeping change across the whole codebase.&lt;br /&gt;
&lt;br /&gt;
==Bug in Create==&lt;br /&gt;
&lt;br /&gt;
There exists a bug in the create call. Currently, Ruby throws:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;comparison of Fixnum with nil failed&amp;lt;/pre&amp;gt;&lt;br /&gt;
on&lt;br /&gt;
&amp;lt;pre&amp;gt;TeamNode.create parent_id: parent.id, node_object_id: team.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This hapens with the unrefactored codebase (Git Rev d2144d13a6fd26203e464a90beaaaceb69506c6f) as well.&lt;br /&gt;
&lt;br /&gt;
==Remove Dynamic Finders==&lt;br /&gt;
Dynamic Finders (find_by_xxx_yyyy) are depreciated in Rails 4. They should be replaced by `where(xxx: ,yyy:).first` or by `find_by` (non-dynamic find_by is not depreciated).&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Style Guide]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/ Expertiza Github Repository]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/431 Pull Request for E1461]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90234</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90234"/>
		<updated>2014-10-29T01:39:53Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* RSpec Functional Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
==StudentTeamController==&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Refactoring of Old Code=&lt;br /&gt;
==Using Routing Helpers==&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Pluralize StudentTeamController Class Name==&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Style Changes Based on Current Conventions==&lt;br /&gt;
&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
&lt;br /&gt;
===Non-SQL Style Where Method Calls===&lt;br /&gt;
&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Refactored Where Method Calls===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use good array checking===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(check.length == 0)&lt;br /&gt;
(check[0].name &amp;lt;=&amp;gt; @team.name) == 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They were changed to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
matching_teams.length.zero?&lt;br /&gt;
(matching_teams[0].name &amp;lt;=&amp;gt; team.name).zero?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if !first_waitlisted_user.nil?&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if first_waitlisted_user&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==Use boolean-like objects in conditionals==&lt;br /&gt;
Replace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Removed Comment out Code==&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Work left to be Done=&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
==Change View to Show==&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
==Do Bookeeping in Models not in the Controllers==&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
==RSpec Functional Testing==&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
[[File:studentteamtest.jpg|center|thumbnail|alt= TEST Verification of Methods.]]&lt;br /&gt;
&lt;br /&gt;
==Additional Changes to Name==&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
==Unessisary Member Variables==&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
==Clean up Permissions==&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces `action_allowed?` to happen before any other before actions. This causes any prerequisite or dependent conditions in action_allowed? to have to be set inside `action_allowed?`. However, this method is not called in the case of a Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
As you can see, the view method checks permissions again in this call (outside action_allowed?). In addition, this is not very dry, as the are defined here copies of the actual permissions set in the InitiationsController.&lt;br /&gt;
&lt;br /&gt;
This could be addressed to clean up the beginning of the controller. However, this is a sweeping change across the whole codebase.&lt;br /&gt;
&lt;br /&gt;
==Bug in Create==&lt;br /&gt;
&lt;br /&gt;
There exists a bug in the create call. Currently, Ruby throws:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;comparison of Fixnum with nil failed&amp;lt;/pre&amp;gt;&lt;br /&gt;
on&lt;br /&gt;
&amp;lt;pre&amp;gt;TeamNode.create parent_id: parent.id, node_object_id: team.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This hapens with the unrefactored codebase (Git Rev d2144d13a6fd26203e464a90beaaaceb69506c6f) as well.&lt;br /&gt;
&lt;br /&gt;
==Remove Dynamic Finders==&lt;br /&gt;
Dynamic Finders (find_by_xxx_yyyy) are depreciated in Rails 4. They should be replaced by `where(xxx: ,yyy:).first` or by `find_by` (non-dynamic find_by is not depreciated).&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Style Guide]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/ Expertiza Github Repository]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/431 Pull Request for E1461]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90233</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90233"/>
		<updated>2014-10-29T01:38:08Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* RSpec Functional Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
==StudentTeamController==&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Refactoring of Old Code=&lt;br /&gt;
==Using Routing Helpers==&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Pluralize StudentTeamController Class Name==&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Style Changes Based on Current Conventions==&lt;br /&gt;
&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
&lt;br /&gt;
===Non-SQL Style Where Method Calls===&lt;br /&gt;
&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Refactored Where Method Calls===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use good array checking===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(check.length == 0)&lt;br /&gt;
(check[0].name &amp;lt;=&amp;gt; @team.name) == 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They were changed to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
matching_teams.length.zero?&lt;br /&gt;
(matching_teams[0].name &amp;lt;=&amp;gt; team.name).zero?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if !first_waitlisted_user.nil?&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if first_waitlisted_user&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==Use boolean-like objects in conditionals==&lt;br /&gt;
Replace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Removed Comment out Code==&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Work left to be Done=&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
==Change View to Show==&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
==Do Bookeeping in Models not in the Controllers==&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
==RSpec Functional Testing==&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
[[File:studentteamtest.jpg|alt= TEST Verification of Methods.]]&lt;br /&gt;
&lt;br /&gt;
==Additional Changes to Name==&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
==Unessisary Member Variables==&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
==Clean up Permissions==&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces `action_allowed?` to happen before any other before actions. This causes any prerequisite or dependent conditions in action_allowed? to have to be set inside `action_allowed?`. However, this method is not called in the case of a Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
As you can see, the view method checks permissions again in this call (outside action_allowed?). In addition, this is not very dry, as the are defined here copies of the actual permissions set in the InitiationsController.&lt;br /&gt;
&lt;br /&gt;
This could be addressed to clean up the beginning of the controller. However, this is a sweeping change across the whole codebase.&lt;br /&gt;
&lt;br /&gt;
==Bug in Create==&lt;br /&gt;
&lt;br /&gt;
There exists a bug in the create call. Currently, Ruby throws:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;comparison of Fixnum with nil failed&amp;lt;/pre&amp;gt;&lt;br /&gt;
on&lt;br /&gt;
&amp;lt;pre&amp;gt;TeamNode.create parent_id: parent.id, node_object_id: team.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This hapens with the unrefactored codebase (Git Rev d2144d13a6fd26203e464a90beaaaceb69506c6f) as well.&lt;br /&gt;
&lt;br /&gt;
==Remove Dynamic Finders==&lt;br /&gt;
Dynamic Finders (find_by_xxx_yyyy) are depreciated in Rails 4. They should be replaced by `where(xxx: ,yyy:).first` or by `find_by` (non-dynamic find_by is not depreciated).&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Style Guide]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/ Expertiza Github Repository]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/431 Pull Request for E1461]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Studentteamtest.jpg&amp;diff=90232</id>
		<title>File:Studentteamtest.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Studentteamtest.jpg&amp;diff=90232"/>
		<updated>2014-10-29T01:36:54Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: uploaded a new version of &amp;amp;quot;File:Studentteamtest.jpg&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Verification of methods in Student_Teams_Controller&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Studentteamtest.jpg&amp;diff=90231</id>
		<title>File:Studentteamtest.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Studentteamtest.jpg&amp;diff=90231"/>
		<updated>2014-10-29T01:36:28Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: uploaded a new version of &amp;amp;quot;File:Studentteamtest.jpg&amp;amp;quot;: Verification of methods in Student_Teams_Controller&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Verification of methods in Student_Teams_Controller&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Studentteamtest.jpg&amp;diff=90230</id>
		<title>File:Studentteamtest.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Studentteamtest.jpg&amp;diff=90230"/>
		<updated>2014-10-29T01:35:43Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: uploaded a new version of &amp;amp;quot;File:Studentteamtest.jpg&amp;amp;quot;: Verification of methods in Student_Teams_Controller&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Verification of methods in Student_Teams_Controller&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Studentteamtest.jpg&amp;diff=90229</id>
		<title>File:Studentteamtest.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Studentteamtest.jpg&amp;diff=90229"/>
		<updated>2014-10-29T01:34:29Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: uploaded a new version of &amp;amp;quot;File:Studentteamtest.jpg&amp;amp;quot;: Verification of methods in Student_Teams_Controller&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Verification of methods in Student_Teams_Controller&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Studentteamtest.jpg&amp;diff=90228</id>
		<title>File:Studentteamtest.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Studentteamtest.jpg&amp;diff=90228"/>
		<updated>2014-10-29T01:33:44Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: Verification of methods in Student_Teams_Controller&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Verification of methods in Student_Teams_Controller&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90227</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90227"/>
		<updated>2014-10-29T01:31:23Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* RSpec Functional Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
==StudentTeamController==&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Refactoring of Old Code=&lt;br /&gt;
==Using Routing Helpers==&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Pluralize StudentTeamController Class Name==&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Style Changes Based on Current Conventions==&lt;br /&gt;
&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
&lt;br /&gt;
===Non-SQL Style Where Method Calls===&lt;br /&gt;
&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Refactored Where Method Calls===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Use good array checking===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(check.length == 0)&lt;br /&gt;
(check[0].name &amp;lt;=&amp;gt; @team.name) == 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They were changed to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
matching_teams.length.zero?&lt;br /&gt;
(matching_teams[0].name &amp;lt;=&amp;gt; team.name).zero?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if !first_waitlisted_user.nil?&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if first_waitlisted_user&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==Use boolean-like objects in conditionals==&lt;br /&gt;
Replace&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Removed Comment out Code==&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Work left to be Done=&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
==Change View to Show==&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
==Do Bookeeping in Models not in the Controllers==&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
==RSpec Functional Testing==&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
[[File:http://i.imgur.com/c2izUU6.jpg|alt= TEST Verification of Methods.]]&lt;br /&gt;
&lt;br /&gt;
==Additional Changes to Name==&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
==Unessisary Member Variables==&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
==Clean up Permissions==&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces `action_allowed?` to happen before any other before actions. This causes any prerequisite or dependent conditions in action_allowed? to have to be set inside `action_allowed?`. However, this method is not called in the case of a Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
As you can see, the view method checks permissions again in this call (outside action_allowed?). In addition, this is not very dry, as the are defined here copies of the actual permissions set in the InitiationsController.&lt;br /&gt;
&lt;br /&gt;
This could be addressed to clean up the beginning of the controller. However, this is a sweeping change across the whole codebase.&lt;br /&gt;
&lt;br /&gt;
==Bug in Create==&lt;br /&gt;
&lt;br /&gt;
There exists a bug in the create call. Currently, Ruby throws:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;comparison of Fixnum with nil failed&amp;lt;/pre&amp;gt;&lt;br /&gt;
on&lt;br /&gt;
&amp;lt;pre&amp;gt;TeamNode.create parent_id: parent.id, node_object_id: team.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This hapens with the unrefactored codebase (Git Rev d2144d13a6fd26203e464a90beaaaceb69506c6f) as well.&lt;br /&gt;
&lt;br /&gt;
==Remove Dynamic Finders==&lt;br /&gt;
Dynamic Finders (find_by_xxx_yyyy) are depreciated in Rails 4. They should be replaced by `where(xxx: ,yyy:).first` or by `find_by` (non-dynamic find_by is not depreciated).&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Style Guide]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/ Expertiza Github Repository]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/431 Pull Request for E1461]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90190</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90190"/>
		<updated>2014-10-29T00:21:28Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* &amp;quot;Where&amp;quot; Method Calls and Change to More Descriptive Variable Names */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
==StudentTeamController==&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Refactoring of Old Code=&lt;br /&gt;
==Using Routing Helpers==&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Pluralize StudentTeamController Class Name==&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Style Changes Based on Current Conventions==&lt;br /&gt;
===&amp;quot;Where&amp;quot; Method Calls and Change to More Descriptive Variable Names===&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Where Method Calls &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Some more name and styling changes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(check.length == 0)&lt;br /&gt;
(check[0].name &amp;lt;=&amp;gt; @team.name) == 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
They were changed to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
matching_teams.length.zero?&lt;br /&gt;
(matching_teams[0].name &amp;lt;=&amp;gt; team.name).zero?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Removed Comment out Code==&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Work left to be Done=&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
==Change View to Show==&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
==Do Bookeeping in Models not in the Controllers==&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
==Testing==&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
==Additional Changes to Name==&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
==Unessisary Member Variables==&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
==Clean up Permissions==&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces &amp;lt;pre&amp;gt;action_allowed?&amp;lt;/pre&amp;gt; to happen before any other before actions. This causes any prerequisite or dependent conditions in action_allowed? to have to be set inside &amp;lt;pre&amp;gt;action_allowed?&amp;lt;/pre&amp;gt;. However, this method is not called in the case of a Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
Permissions are checked AGAIN in this call (outside action_allowed?) and are defined here independent of the actual permissions set in the InitiationsController.&lt;br /&gt;
&lt;br /&gt;
This could be addressed to clean up the beginning of the controller. However, this is a sweeping change across the whole codebase.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90189</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90189"/>
		<updated>2014-10-29T00:19:39Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* &amp;quot;Where&amp;quot; Method Calls and Change to More Descriptive Variable Names */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
==StudentTeamController==&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Refactoring of Old Code=&lt;br /&gt;
==Using Routing Helpers==&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Pluralize StudentTeamController Class Name==&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Style Changes Based on Current Conventions==&lt;br /&gt;
===&amp;quot;Where&amp;quot; Method Calls and Change to More Descriptive Variable Names===&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
(check.length == 0)&lt;br /&gt;
(check[0].name &amp;lt;=&amp;gt; @team.name) == 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Where Method Calls &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
matching_teams.length.zero?&lt;br /&gt;
(matching_teams[0].name &amp;lt;=&amp;gt; team.name).zero?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Removed Comment out Code==&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Work left to be Done=&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
==Change View to Show==&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
==Do Bookeeping in Models not in the Controllers==&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
==Testing==&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
==Additional Changes to Name==&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
==Unessisary Member Variables==&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
==Clean up Permissions==&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces &amp;lt;pre&amp;gt;action_allowed?&amp;lt;/pre&amp;gt; to happen before any other before actions. This causes any prerequisite or dependent conditions in action_allowed? to have to be set inside &amp;lt;pre&amp;gt;action_allowed?&amp;lt;/pre&amp;gt;. However, this method is not called in the case of a Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
Permissions are checked AGAIN in this call (outside action_allowed?) and are defined here independent of the actual permissions set in the InitiationsController.&lt;br /&gt;
&lt;br /&gt;
This could be addressed to clean up the beginning of the controller. However, this is a sweeping change across the whole codebase.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90184</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90184"/>
		<updated>2014-10-29T00:13:01Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* Method Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction== &lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
===StudentTeamController===&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Refactoring of Old Code==&lt;br /&gt;
===Using Routing Helpers===&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Pluralize StudentTeamController Class Name===&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Style Changes Based on Current Conventions===&lt;br /&gt;
====&amp;quot;Where&amp;quot; Method Calls and Change to More Descriptive Variable Names====&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Where Method Calls &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplication. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places made it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Removed Comment out Code=&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Work left to be Done==&lt;br /&gt;
There is much work left to be done with this controller. Some of the changes have wider scope than just this class.&lt;br /&gt;
=Change View to Show=&lt;br /&gt;
The correct name for the view method is show. This was noticed at the last minue, and because of the use of &amp;quot;view&amp;quot; throughout&lt;br /&gt;
rails simple refactoring tools were not enough to fix this.&lt;br /&gt;
=Do Bookeeping in Models not in the Controllers=&lt;br /&gt;
The largest function by far in this controller is the remove_participant (formally 'leave') function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def remove_participant&lt;br /&gt;
      #remove the topic_id from participants&lt;br /&gt;
      student.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
      #remove the entry from teams_users&lt;br /&gt;
  &lt;br /&gt;
      team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
  &lt;br /&gt;
      if team_user&lt;br /&gt;
        team_user.destroy&lt;br /&gt;
  &lt;br /&gt;
        undo_link &amp;quot;User \&amp;quot;#{team_user.name}\&amp;quot; has been removed from the team successfully. &amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
  &lt;br /&gt;
      #if your old team does not have any members, delete the entry for the team&lt;br /&gt;
      if TeamsUser.where(team_id: params[:team_id]).empty?&lt;br /&gt;
        old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
        if old_team&lt;br /&gt;
          old_team.destroy&lt;br /&gt;
          #if assignment has signup sheet then the topic selected by the team has to go back to the pool&lt;br /&gt;
          #or to the first team in the waitlist&lt;br /&gt;
  &lt;br /&gt;
          sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
          sign_ups.each {|sign_up|&lt;br /&gt;
            #get the topic_id&lt;br /&gt;
            sign_up_topic_id = sign_up.topic_id&lt;br /&gt;
            #destroy the sign_up&lt;br /&gt;
            sign_up.destroy&lt;br /&gt;
  &lt;br /&gt;
            #get the number of non-waitlisted users signed up for this topic&lt;br /&gt;
            non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
            #get the number of max-choosers for the topic&lt;br /&gt;
            max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
  &lt;br /&gt;
            #check if this number is less than the max choosers&lt;br /&gt;
            if non_waitlisted_users.length &amp;lt; max_choosers&lt;br /&gt;
              first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
  &lt;br /&gt;
              #moving the waitlisted user into the confirmed signed up users list&lt;br /&gt;
              if first_waitlisted_user&lt;br /&gt;
                first_waitlisted_user.is_waitlisted = false&lt;br /&gt;
                first_waitlisted_user.save&lt;br /&gt;
  &lt;br /&gt;
                waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id #&amp;lt;this relationship is weird&lt;br /&gt;
                #waitlisted_team_user could be nil since the team the student left could have been the one waitlisted on the topic&lt;br /&gt;
                #and teams_users for the team has been deleted in one of the earlier lines of code&lt;br /&gt;
  &lt;br /&gt;
                if waitlisted_team_user&lt;br /&gt;
                  user_id = waitlisted_team_user.user_id&lt;br /&gt;
                  if user_id&lt;br /&gt;
                    waitlisted_participant = Participant.find_by_user_id user_id&lt;br /&gt;
                    waitlisted_participant.update_topic_id nil&lt;br /&gt;
  &lt;br /&gt;
                  end&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
  &lt;br /&gt;
          }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Everything past the 14th line of code is bookeeping that should be handled by the model itself. In large part, &lt;br /&gt;
relationships could solve all of the checks if members exist or are empty and destroy them with dependent_destroy.&lt;br /&gt;
In addition, the current TeamsUser model should be removed entirely and replaced with the had_many_and_belongs_to relationship.&lt;br /&gt;
=Testing=&lt;br /&gt;
The system currently only has limited RSpec tests. The team was only able to implement rudementary tests. Additional tests&lt;br /&gt;
are required to ensure good code coverage.&lt;br /&gt;
=Additional Changes to Name=&lt;br /&gt;
There is no such construct as a &amp;quot;Student Team&amp;quot;. In fact, &amp;quot;Student Teams&amp;quot; can currently have members who are not students (instructors), &lt;br /&gt;
though the permissions for the instructors actually doing anything in the controller are tied off. A more accurate name of the &lt;br /&gt;
class, and more accurate roles for the class, could be defined by &amp;quot;AssignmentTeamsController&amp;quot; which is the actual focus of this class.&lt;br /&gt;
=Unessisary Member Variables=&lt;br /&gt;
Member variables are exposed outside the scope of the specific action. They should be used in as few situations as possible. A minimal &lt;br /&gt;
set of target classes (Such as @team, and possibly @student) should be all that is used.&lt;br /&gt;
=Clean up Permissions=&lt;br /&gt;
The current permissions scheme forces the permissions to be checked at the beginning of the controller. This makes it so that&lt;br /&gt;
the controller has the dule role of interfaceing the views with the model AND managing its permissions.&lt;br /&gt;
&lt;br /&gt;
The inheritance structure currently forces &amp;lt;pre&amp;gt;action_allowed?&amp;lt;/pre&amp;gt; to happen before any other before actions. This causes any prerequisite or&lt;br /&gt;
dependent conditions in action_allowed? to have to be set inside &amp;lt;pre&amp;gt;action_allowed?&amp;lt;/pre&amp;gt;. However, this method is not called in the case of a &lt;br /&gt;
Super User login, and therefore these types of members need to be set both in the action_allowed? and before the view is shown.&lt;br /&gt;
&lt;br /&gt;
Finally, the current permissions scheme causes the odd structures we see in the &amp;quot;View&amp;quot; call. &lt;br /&gt;
&lt;br /&gt;
   def view&lt;br /&gt;
     #View will check if send_invs and recieved_invs are set before showing&lt;br /&gt;
     #only the owner should be able to see those.&lt;br /&gt;
     return unless current_user_id? student.user_id&lt;br /&gt;
&lt;br /&gt;
     @send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
     @received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
Permissions are checked AGAIN in this call (outside action_allowed?) and are defined here independent of the actual permissions set&lt;br /&gt;
in the InitiationsController.&lt;br /&gt;
=References=&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90182</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90182"/>
		<updated>2014-10-29T00:11:55Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* Method Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction== &lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
===StudentTeamController===&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Refactoring of Old Code==&lt;br /&gt;
===Using Routing Helpers===&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Pluralize StudentTeamController Class Name===&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Style Changes Based on Current Conventions===&lt;br /&gt;
====&amp;quot;Where&amp;quot; Method Calls and Change to More Descriptive Variable Names====&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Where Method Calls &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for &amp;quot;remove&amp;quot; method which didn't mean anything to more understandable name &amp;quot;remove_advertisement&amp;quot;.&lt;br /&gt;
&amp;quot;Leave&amp;quot; was changed to &amp;quot;remove_participant&amp;quot; which is more helpful for reader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplicating data. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places make it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Removed Comment out Code=&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90178</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90178"/>
		<updated>2014-10-29T00:09:49Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* Method Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction== &lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
===StudentTeamController===&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Refactoring of Old Code==&lt;br /&gt;
===Using Routing Helpers===&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Pluralize StudentTeamController Class Name===&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Style Changes Based on Current Conventions===&lt;br /&gt;
====&amp;quot;Where&amp;quot; Method Calls and Change to More Descriptive Variable Names====&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Where Method Calls &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for remove method which didn't mean anything to remove_advertisement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def leave&lt;br /&gt;
&lt;br /&gt;
  def remove_participant&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull up method refactoring technique was used to DRY up the code and avoid duplicating data. For example, statement in code below was used at 3 different places in original code so pulling up that command in one method and calling &amp;quot;team_created_successfully&amp;quot; at all places make it easy to read code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def team_created_successfully&lt;br /&gt;
    undo_link &amp;quot;Team \&amp;quot;#{team.name}\&amp;quot; has been updated successfully. &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Removed Comment out Code=&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90171</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90171"/>
		<updated>2014-10-29T00:01:40Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* Method Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction== &lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
===StudentTeamController===&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Refactoring of Old Code==&lt;br /&gt;
===Using Routing Helpers===&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Pluralize StudentTeamController Class Name===&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Style Changes Based on Current Conventions===&lt;br /&gt;
====&amp;quot;Where&amp;quot; Method Calls and Change to More Descriptive Variable Names====&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Where Method Calls &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
Different method refactoring techniques were used to make clarity and understanding of code very easy and simple.&lt;br /&gt;
For example,&lt;br /&gt;
Rename method technique was used for remove method which didn't mean anything to remove_advertisement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def remove&lt;br /&gt;
&lt;br /&gt;
  def remove_advertisement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Removed Comment out Code=&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90165</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90165"/>
		<updated>2014-10-28T23:55:21Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction== &lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
===StudentTeamController===&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Refactoring of Old Code==&lt;br /&gt;
===Using Routing Helpers===&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Pluralize StudentTeamController Class Name===&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Style Changes Based on Current Conventions===&lt;br /&gt;
====&amp;quot;Where&amp;quot; Method Calls and Change to More Descriptive Variable Names====&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Where Method Calls &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Method Refactoring==&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Removed Comment out Code=&lt;br /&gt;
Commented out code can be restored from the repository. It only serves to clutter the class. Blocks like the one shown below were removed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   #respond_to do |format|&lt;br /&gt;
   # format.html # index.html.erb&lt;br /&gt;
   #format.xml { render :xml =&amp;gt; @log_entries }&lt;br /&gt;
   #end&lt;br /&gt;
   #redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'advertise_for_partners' , :id =&amp;gt; params[:team_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90159</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1461 knn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90159"/>
		<updated>2014-10-28T23:48:03Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza - Refactoring StudentTeamController'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction== &lt;br /&gt;
Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.&lt;br /&gt;
&lt;br /&gt;
One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.&lt;br /&gt;
===StudentTeamController===&lt;br /&gt;
StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:&lt;br /&gt;
*Create, edit or delete a team (name)&lt;br /&gt;
*Add a teamate to the team&lt;br /&gt;
*Leave a team if they want to move to a new team&lt;br /&gt;
*View received and sent invitations&lt;br /&gt;
This controller also provides the student and team instance variables to the corresponding student_team views.&lt;br /&gt;
&lt;br /&gt;
We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:&lt;br /&gt;
*Change the list method to index (and others in the RESTful style)&lt;br /&gt;
*Use Ruby 1.9 style key: value pairs&lt;br /&gt;
*Remove commented-out code&lt;br /&gt;
*Use routing helpers (http://guides.rubyonrails.org/routing.html#path-and-url-helpers)&lt;br /&gt;
*Pluralize the class (StudentTeamsController)&lt;br /&gt;
*Use `.zero?` instead of `== 0`&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==Setting Up Expertiza on Your Computer to Work on it==&lt;br /&gt;
Most people who are new to working on Linux and Github can have issues working, so these links and instructions can help you setting it up on &lt;br /&gt;
your computer for final project or other purposes.&lt;br /&gt;
Setup was done first on Windows and because of lot of gem conflicts with windows, Linux 14.04 was used instead. &lt;br /&gt;
 -Update Linux package&lt;br /&gt;
 -Install Git, Setup username , password&lt;br /&gt;
 -Suggest Installing Ruby with Rbenv Manager&lt;br /&gt;
 -Install ruby version 2+ and look for available versions using -l command&lt;br /&gt;
 -Install rails 4+&lt;br /&gt;
 -Install and setup Java Environment&lt;br /&gt;
 -Check the Ruby, Rails and Java Environment Versions Before cloning Expertiza&lt;br /&gt;
 -Setup for Nokogiri Gem so it doesn't give error&lt;br /&gt;
 -Install Mysql and setup password and keep it safe as it will be required for importing database&lt;br /&gt;
 -Fork and Clone Expertiza from https://github.com/expertiza/expertiza.git&lt;br /&gt;
 -Import Database&lt;br /&gt;
 -Bundle Install should work and GOOD LUCK!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install git&lt;br /&gt;
git config --global user.name &amp;quot;Name Surname&amp;quot;&lt;br /&gt;
git config --global user.email aaa@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/rbenv.git .rbenv&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
echo 'eval &amp;quot;$(rbenv init -)&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build&lt;br /&gt;
echo 'export PATH=&amp;quot;$HOME/.rbenv/plugins/ruby-build/bin:$PATH&amp;quot;' &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash&lt;br /&gt;
git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs&lt;br /&gt;
bundle install --binstubs .bundle/bin&lt;br /&gt;
&lt;br /&gt;
rbenv install -l&lt;br /&gt;
rbenv install 2.1.2&lt;br /&gt;
rbenv global 2.1.2&lt;br /&gt;
gem install rails&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install java7-jdk&lt;br /&gt;
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/&lt;br /&gt;
sudo apt-get install mysql-server libmysqlclient-dev&lt;br /&gt;
&lt;br /&gt;
ruby -v&lt;br /&gt;
rails -v&lt;br /&gt;
java -version&lt;br /&gt;
&lt;br /&gt;
bundle config build.nokogiri --use-system-libraries&lt;br /&gt;
gem install mysql&lt;br /&gt;
mysql -u root -p Your_Database &amp;lt; Database-You-Importing.sql&lt;br /&gt;
gem install rjb&lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Refactoring of Old Code==&lt;br /&gt;
===Using Routing Helpers===&lt;br /&gt;
Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:&lt;br /&gt;
*advertise_for_partner_controller.rb&lt;br /&gt;
*invitation_controller.rb&lt;br /&gt;
*join_team_requests_controller.rb&lt;br /&gt;
*reports_controller.rb&lt;br /&gt;
*response_controller.rb&lt;br /&gt;
*app\views\advertise_for_partner\show.html.erb&lt;br /&gt;
*app\views\student_task\view.html.erb&lt;br /&gt;
*app\views\student_teams\view.html.erb&lt;br /&gt;
The routes changed were as follows:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
redirect_to :controller =&amp;gt;'student_team', :action =&amp;gt; 'edit', :team_id =&amp;gt;params[:team_id], :student_id =&amp;gt; params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Pluralize StudentTeamController Class Name===&lt;br /&gt;
StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class such as in routes directing to StudentTeamsController and in the routes.rb file itself&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_team_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_team do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Redirect Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to view_student_teams_path student_id: student.id&lt;br /&gt;
&lt;br /&gt;
#Routes.rb&lt;br /&gt;
&lt;br /&gt;
resources :student_teams do&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Style Changes Based on Current Conventions===&lt;br /&gt;
====&amp;quot;Where&amp;quot; Method Calls and Change to More Descriptive Variable Names====&lt;br /&gt;
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where &amp;quot;.where&amp;quot; was being used to find just one instance, it was instead changed to &amp;quot;find_by&amp;quot;. The changes made are shown below:&lt;br /&gt;
Old Where Method Calls&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])&lt;br /&gt;
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = &amp;quot;W&amp;quot;', @student.user.id, @student.assignment.id])&lt;br /&gt;
&lt;br /&gt;
#create&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @student.parent_id])&lt;br /&gt;
&lt;br /&gt;
#update&lt;br /&gt;
&lt;br /&gt;
check = AssignmentTeam.where( [&amp;quot;name =? and parent_id =?&amp;quot;, params[:team][:name], @team.parent_id])&lt;br /&gt;
&lt;br /&gt;
#leave&lt;br /&gt;
&lt;br /&gt;
user = TeamsUser.where([&amp;quot;team_id =? and user_id =?&amp;quot;, params[:team_id], @student.user_id]).first&lt;br /&gt;
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])&lt;br /&gt;
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])&lt;br /&gt;
signups = SignedUpUser.where( {:creator_id =&amp;gt; params[:team_id]})&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; false})&lt;br /&gt;
max_choosers = SignUpTopic.where( {:id =&amp;gt; signup_topic_id}).first.max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.where( {:topic_id =&amp;gt; signup_topic_id, :is_waitlisted =&amp;gt; true}).first&lt;br /&gt;
waitlisted_team_user = TeamsUser.where( {:team_id =&amp;gt; first_waitlisted_user.creator_id}).first&lt;br /&gt;
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Where Method Calls &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#view&lt;br /&gt;
&lt;br /&gt;
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id&lt;br /&gt;
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'&lt;br /&gt;
&lt;br /&gt;
#create (change of variable names)&lt;br /&gt;
&lt;br /&gt;
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id&lt;br /&gt;
&lt;br /&gt;
#update (change of variable names)&lt;br /&gt;
&lt;br /&gt;
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id&lt;br /&gt;
&lt;br /&gt;
#remove_participant (renamed method - was #leave; .find and .find_by refactoring)&lt;br /&gt;
&lt;br /&gt;
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id&lt;br /&gt;
old_team = AssignmentTeam.find params[:team_id]&lt;br /&gt;
sign_ups = SignedUpUser.where creator_id: params[:team_id]&lt;br /&gt;
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false&lt;br /&gt;
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers&lt;br /&gt;
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#&amp;lt;order?&lt;br /&gt;
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id &lt;br /&gt;
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Before Actions==&lt;br /&gt;
Two lines were repeated in multiple methods in the StudentTeamsController, one to set the @student instance variable and one to set the @team instance variable. The setting of the @student variable is used in the view, update, edit, create, and leave methods while @team is set in the edit and update methods. The setting of these variables was moved to methods which cache the values to set the local variables lazily. These methods had to be used as before_actions in order to be usable by the view and edit views. Finally, in order to standardize the setting of the instance variable, the name of the :id params value was changed to :student_id in all redirect calls.&lt;br /&gt;
Old Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Setting of @student and @team instance variable&lt;br /&gt;
&lt;br /&gt;
#view, create&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
#edit, leave&lt;br /&gt;
&lt;br /&gt;
@student = AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
&lt;br /&gt;
#edit,update&lt;br /&gt;
&lt;br /&gt;
@team = AssignmentTeam.find(params[:team_id])&lt;br /&gt;
&lt;br /&gt;
Changing of Routes&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :id=&amp;gt; @student.id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Refactored Code&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Before Actions&lt;br /&gt;
&lt;br /&gt;
 def team&lt;br /&gt;
    @team ||= AssignmentTeam.find params[:team_id]&lt;br /&gt;
  end&lt;br /&gt;
  def team=(value)&lt;br /&gt;
    @team = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student&lt;br /&gt;
    @student ||= AssignmentParticipant.find(params[:student_id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def student=(value)&lt;br /&gt;
    @student = value&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  before_action :team, only: [:edit, :update]&lt;br /&gt;
  before_action :student, only: [:view, :update, :edit, :create, :remove_participant]&lt;br /&gt;
&lt;br /&gt;
Changing of Routes (Changed all instances of redirects to view to reflect student_id)&lt;br /&gt;
&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view' , :student_id=&amp;gt; @student.id&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
[http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-linux Setting up Ruby on Rails Environment on Linux]&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_sn&amp;diff=88652</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 sn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_sn&amp;diff=88652"/>
		<updated>2014-09-26T02:38:20Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* Comparison with other debugging tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Debugging in Rails using Pry''' =&lt;br /&gt;
&lt;br /&gt;
Debugging is a process of finding and reducing the bugs or defects in a computer program thereby making it behave as expected. Few of the debugging techniques are [http://en.wikipedia.org/wiki/Debug_code#Print_debugging  Print debugging] (also known as printf debugging), Log debugging and Interactive debugging&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_logging.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://object.io/site/2011/getting-to-know-ruby-debugger/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] provides a range of options to make debugging&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Debugging&amp;lt;/ref&amp;gt; easier which include debug helpers, loggers, graphical debuggers, Pry, and so on&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/debugging_rails_applications.html&amp;lt;/ref&amp;gt;. In the following sections, debugging in rails using PRY is being explained.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction to Pry debugger =&lt;br /&gt;
&lt;br /&gt;
:Pry is an [http://en.wikipedia.org/wiki/Shell_(computing) interactive shell] for the Ruby programming language. Pry could be started at any point within a running program. Due to this, programmers can inspect the program, correct the source code, or change its current state without having to restart the process. Pry is thus notable for its ability to start a [http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop REPL] within a running program.&lt;br /&gt;
&lt;br /&gt;
:Pry has many features that make it extremely efficient to use. One of the example here could be Pry's ''hist --grep'' that makes it easy to search through your Pry history. Also, Pry uses the filesystem metaphor for exposing most of its introspective capabilities such as the ''ls'' command to list the methods and variables and the ''cd'' command to start interacting with a particular object.&lt;br /&gt;
&lt;br /&gt;
:To start a debugging session, the ''require 'pry' '' and ''binding.pry'' lines need to be included in the program that needs to be debugged. The line ''binding.pry'' could be inserted at any point in your program. Whenever the Ruby interpreter executes this line, it opens a Pry REPL session. The code after the ''binding.pry'' statement is not executed unless instructed by the programmer. Changes could be made to fix the code and then return to running program from same point.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
:To use Pry for debugging a Rails application, you first need to download and install Pry-debugger. If you are using Ruby version 2.0 or higher, then download pry-debugger from [https://github.com/deivid-rodriguez/pry-byebug here]. If you are using Ruby version 1.9 or lower, then download pry-debugger from [https://rubygems.org/gems/pry-debugger here].&lt;br /&gt;
&lt;br /&gt;
:To install the debugger use the following command:&amp;lt;ref&amp;gt;http://pryrepl.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install pry-debugger.gem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Include the following line of code on the gem file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'pry-rails', :group =&amp;gt; :development&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Once that is done, the necessary dependencies could be installed using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Execution Commands =&lt;br /&gt;
:To use the execution command, invoke pry normally. There is no need to start your script or application differently. For the sake of clarity in explanation, we would refer to the program below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry'&lt;br /&gt;
def method1 (seller)&lt;br /&gt;
	puts 'Inside method 1'&lt;br /&gt;
	method2(seller)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def method2(seller)&lt;br /&gt;
  binding.pry      	# Execution will stop here.&lt;br /&gt;
  new_products = method3(seller)&lt;br /&gt;
  puts 'After calling method3'&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def method3(seller)&lt;br /&gt;
	puts 'Inside method 3'&lt;br /&gt;
	puts 'Continuing in method 3'&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
method1('xyz')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The Step command: ===&lt;br /&gt;
:The ''step'' command continues execution by moving into the method on the next line. To put it in another way, the command takes us deeper into the method. Following our example, the ''step'' command would take us into ''method3'' at which point we would be asked what to do next. The following screenshot demonstrates our example:&lt;br /&gt;
&lt;br /&gt;
[[File:Step.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== The Next command: ===&lt;br /&gt;
:The ''next'' command runs the current line and moves to the next line in the current context.  If the next line in the code is a method call, then unlike the ''step'' method the execution does not go deeper into the method. Following our example, if we execute the above code, the execution stop at the ''binding.pry'' line and the debugger asks us for the further action. On using the ''next'' command, the execution moves to the next line that is '' new_products = method3(seller)'' without going deeper into the method. The debugger now waits for another instruction from the programmer and if the command is ''next'' again, the debugger simply goes to the next line of code after executing the method. Thus, all the code within the ''method3'' method (which would otherwise be many steps), has been concluded with a single use of the ''next'' command. The example could be seen in the following screenshot:&lt;br /&gt;
&lt;br /&gt;
[[File:Next.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== The Finish command: ===&lt;br /&gt;
:Now once we have stepped into a method using the ''step'' command, the debugger would ask us what needs to be done next. Now if we want to jump to the end of the method without the debugger asking us our choice of navigation command at the end of each line, we could use the ''finish'' command. The ''finish'' command would execute the code in the method and return back to the point from where the method was called. In our example, while the debugger is in ''method3'', the ''finish'' command would complete the code execution in ''method3'' and return back to ''method2''.&lt;br /&gt;
&lt;br /&gt;
=== The Continue command: ===&lt;br /&gt;
:With this command we can abandon the pry session and continue the normal execution of the program. If the interpreter encounters another ''binding.pry'', a pry session is again opened. This can be incredibly annoying, since our program will stop and we’ll have to navigate the debugger every single time, so we’ll probably want to type exit-program to cancel the effect of any following ''binding.pry'' statements, thereby exiting our rails application.&lt;br /&gt;
&lt;br /&gt;
=== Breakpoints: ===&lt;br /&gt;
:You could set or change the breakpoints in a program directly using Pry. The ''break'' command is used for this purpose. You could set breakpoints in the current file, or in any other file, or a method. Conditional breakpoints could also be changed or set using optional expressions.&lt;br /&gt;
&lt;br /&gt;
:Command to display the list of breakpoints and conditional breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break --condition 4 x &amp;gt; 2      Change condition on breakpoint #4 to 'x &amp;gt; 2'.&lt;br /&gt;
break --condition 6            Remove the condition on breakpoint #6.&lt;br /&gt;
break                          List all breakpoints. (Same as `breakpoints`)&lt;br /&gt;
break --show 2                 Show details about breakpoint #2.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Setting breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break 5                        Break at line 5 in the current file.&lt;br /&gt;
break &amp;lt;class_name&amp;gt;#run         Break at the start of `&amp;lt;class_name&amp;gt;#run`.&lt;br /&gt;
break app/models/test.rb:4     Break at line 4 in test.rb.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Deleting breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break --delete 5               Delete breakpoint #5.&lt;br /&gt;
break --disable-all            Disable all breakpoints.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The Edit command: ===&lt;br /&gt;
:You could edit the code in a file by just switching to the editor rather than having to end the Pry session. This could be done using the ''edit'' command&amp;lt;ref&amp;gt;http://kgrz.io/pry/2014/02/07/Prys-edit-command.html&amp;lt;/ref&amp;gt;. On using the ''edit'' command, a new editor window pops up thereby enabling the programmer to edit the code. However, you need to specify the type of editor in the ''.pryrc'' file. For example, in order to edit the code using a Notepad editor, you need to specify the following in the ''.pryrc'' file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pry.config.editor = 'Notepad'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:SnOutput1.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== View the documentation or source for a method: ===&lt;br /&gt;
:You sometimes would want to know how a particular method works or what kind of arguments it takes. The ''show-doc'' method could help you determine that. Also, you would want to know the source of the method. This could be done using the ''show-method'' command.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pry(main)&amp;gt; def foo&lt;br /&gt;
pry(main)*   puts &amp;quot;Welcome to the foo!!&amp;quot;&lt;br /&gt;
pry(main)* end  &lt;br /&gt;
=&amp;gt; nil&lt;br /&gt;
pry(main)&amp;gt; show-method foo&lt;br /&gt;
 &lt;br /&gt;
From: (pry) @ line 3:&lt;br /&gt;
Number of lines: 3&lt;br /&gt;
Owner: Object&lt;br /&gt;
Visibility: private&lt;br /&gt;
 &lt;br /&gt;
def foo&lt;br /&gt;
  puts &amp;quot;Welcome to the foo!!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of other commonly used commands: ===&lt;br /&gt;
:The other list of commands could be found by typing ''help''&amp;lt;ref&amp;gt;https://github.com/pry/pry/wiki/Command-system#Help_command&amp;lt;/ref&amp;gt;. The following shows other list of commands:&lt;br /&gt;
&lt;br /&gt;
[[File:Help1.jpg]]&lt;br /&gt;
&lt;br /&gt;
:Interested people can learn more about using Pry as a debugger by watching the video [http://www.youtube.com/watch?v=o90CCPjcIKE tutorial].&lt;br /&gt;
&lt;br /&gt;
= Remote Debugging&amp;lt;ref&amp;gt;http://wiki.freepascal.org/Remote_Debugging&amp;lt;/ref&amp;gt; =&lt;br /&gt;
:So far, Pry has been a good tool to digging into the code and checking how the code is actually working and what is exactly going on inside the code. We used ''binding.pry'' inside the program where the execution stops and the user is asked to give further instructions. However, there are situations where the execution of the program would not stop and the would not allow you to inspect the code especially in situations when [https://github.com/yegrb/yeg-wiki/wiki/Managing-application-processes-with-the-Foreman-gem Foreman] is used to manage processes. In such situation, ''pry-remote'' could be of help.&lt;br /&gt;
&lt;br /&gt;
:When a process that is being run by Foreman comes across ''binding.pry'', it would halt but a Pry session would not be opened. You would be forced to kill the process as the application actually freezes. Thus, in such cases ''pry-remote'' would be a great solution and in order to work around with this, you need to first install the gem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install pry-remote&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Then run bundler:&lt;br /&gt;
&amp;lt;pre&amp;gt;    &lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Once you have installed ''pry-remote'', a breakpoint can be added using ''binding.remote_pry'' anywhere in the program from where the code needs to be debugged. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:''Pry-remote'' would block your program when it hits the ''binding.remote_pry'' and open a Drb endpoint that a client can connect to&amp;lt;ref&amp;gt;http://www.ruby-doc.org/stdlib-1.9.3/libdoc/drb/rdoc/DRb.html&amp;lt;/ref&amp;gt;. Running pry-remote in a shell will then connect to the session. You would then be able to interact with Pry as you would normally do. You could unblock the program by using ''exit''.&lt;br /&gt;
&lt;br /&gt;
= Comparison with other debugging tools =&lt;br /&gt;
Pry is a replacement for Ruby's default REPL,irb. It has many more additional features as compared to irb. Some of the features that provide Pry an edge over the other debugging tools are as follows:&lt;br /&gt;
:*Pry enables code or syntax highlighting, auto identation and a runtime debugging console.&lt;br /&gt;
:*It has the ability to load any portion of the file in your text editor directly into the REPL session.&lt;br /&gt;
&lt;br /&gt;
Other Debuggers available in the market are:&lt;br /&gt;
:*[http://www.jetbrains.com/ruby/quickstart/ JetBrains RubyMine] Commercial but very easy to use windows based debugger. It supports Ruby versions from 1.8.6 to 2.1.&lt;br /&gt;
:*[http://komodoide.com/features/ Komodo] Commercial IDE used for Ruby and other languages like Perl and java. It has graphical debugger and supports multi-process debugging.&lt;br /&gt;
:*[http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-chrome-devtools.html Chrome Dev-tools] The elements tab is used to debug and get rapid feedback about experimental design changes in HTML or CSS.&lt;br /&gt;
:*[http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-memcached.html Memcached] In production environment this tool can be used in addition with Heroku to access detailed stats about Memcached usage to find if you have high hit rate or low eviction rate.&lt;br /&gt;
:*[http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-operating-system-tools.html Operating System Tools] Mostly a mixture of commands used to debug only specific errors for example, Curl to debug URL's or G Debugger to debug infinite loops.&lt;br /&gt;
&lt;br /&gt;
[http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html This website has a lot of comparison between Pry Debugger with other debuggers available in market.]&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_sn&amp;diff=88650</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 sn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_sn&amp;diff=88650"/>
		<updated>2014-09-26T02:37:14Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* Comparison with other debugging tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Debugging in Rails using Pry''' =&lt;br /&gt;
&lt;br /&gt;
Debugging is a process of finding and reducing the bugs or defects in a computer program thereby making it behave as expected. Few of the debugging techniques are [http://en.wikipedia.org/wiki/Debug_code#Print_debugging  Print debugging] (also known as printf debugging), Log debugging and Interactive debugging&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_logging.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://object.io/site/2011/getting-to-know-ruby-debugger/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] provides a range of options to make debugging&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Debugging&amp;lt;/ref&amp;gt; easier which include debug helpers, loggers, graphical debuggers, Pry, and so on&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/debugging_rails_applications.html&amp;lt;/ref&amp;gt;. In the following sections, debugging in rails using PRY is being explained.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction to Pry debugger =&lt;br /&gt;
&lt;br /&gt;
:Pry is an [http://en.wikipedia.org/wiki/Shell_(computing) interactive shell] for the Ruby programming language. Pry could be started at any point within a running program. Due to this, programmers can inspect the program, correct the source code, or change its current state without having to restart the process. Pry is thus notable for its ability to start a [http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop REPL] within a running program.&lt;br /&gt;
&lt;br /&gt;
:Pry has many features that make it extremely efficient to use. One of the example here could be Pry's ''hist --grep'' that makes it easy to search through your Pry history. Also, Pry uses the filesystem metaphor for exposing most of its introspective capabilities such as the ''ls'' command to list the methods and variables and the ''cd'' command to start interacting with a particular object.&lt;br /&gt;
&lt;br /&gt;
:To start a debugging session, the ''require 'pry' '' and ''binding.pry'' lines need to be included in the program that needs to be debugged. The line ''binding.pry'' could be inserted at any point in your program. Whenever the Ruby interpreter executes this line, it opens a Pry REPL session. The code after the ''binding.pry'' statement is not executed unless instructed by the programmer. Changes could be made to fix the code and then return to running program from same point.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
:To use Pry for debugging a Rails application, you first need to download and install Pry-debugger. If you are using Ruby version 2.0 or higher, then download pry-debugger from [https://github.com/deivid-rodriguez/pry-byebug here]. If you are using Ruby version 1.9 or lower, then download pry-debugger from [https://rubygems.org/gems/pry-debugger here].&lt;br /&gt;
&lt;br /&gt;
:To install the debugger use the following command:&amp;lt;ref&amp;gt;http://pryrepl.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install pry-debugger.gem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Include the following line of code on the gem file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'pry-rails', :group =&amp;gt; :development&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Once that is done, the necessary dependencies could be installed using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Execution Commands =&lt;br /&gt;
:To use the execution command, invoke pry normally. There is no need to start your script or application differently. For the sake of clarity in explanation, we would refer to the program below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry'&lt;br /&gt;
def method1 (seller)&lt;br /&gt;
	puts 'Inside method 1'&lt;br /&gt;
	method2(seller)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def method2(seller)&lt;br /&gt;
  binding.pry      	# Execution will stop here.&lt;br /&gt;
  new_products = method3(seller)&lt;br /&gt;
  puts 'After calling method3'&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def method3(seller)&lt;br /&gt;
	puts 'Inside method 3'&lt;br /&gt;
	puts 'Continuing in method 3'&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
method1('xyz')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The Step command: ===&lt;br /&gt;
:The ''step'' command continues execution by moving into the method on the next line. To put it in another way, the command takes us deeper into the method. Following our example, the ''step'' command would take us into ''method3'' at which point we would be asked what to do next. The following screenshot demonstrates our example:&lt;br /&gt;
&lt;br /&gt;
[[File:Step.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== The Next command: ===&lt;br /&gt;
:The ''next'' command runs the current line and moves to the next line in the current context.  If the next line in the code is a method call, then unlike the ''step'' method the execution does not go deeper into the method. Following our example, if we execute the above code, the execution stop at the ''binding.pry'' line and the debugger asks us for the further action. On using the ''next'' command, the execution moves to the next line that is '' new_products = method3(seller)'' without going deeper into the method. The debugger now waits for another instruction from the programmer and if the command is ''next'' again, the debugger simply goes to the next line of code after executing the method. Thus, all the code within the ''method3'' method (which would otherwise be many steps), has been concluded with a single use of the ''next'' command. The example could be seen in the following screenshot:&lt;br /&gt;
&lt;br /&gt;
[[File:Next.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== The Finish command: ===&lt;br /&gt;
:Now once we have stepped into a method using the ''step'' command, the debugger would ask us what needs to be done next. Now if we want to jump to the end of the method without the debugger asking us our choice of navigation command at the end of each line, we could use the ''finish'' command. The ''finish'' command would execute the code in the method and return back to the point from where the method was called. In our example, while the debugger is in ''method3'', the ''finish'' command would complete the code execution in ''method3'' and return back to ''method2''.&lt;br /&gt;
&lt;br /&gt;
=== The Continue command: ===&lt;br /&gt;
:With this command we can abandon the pry session and continue the normal execution of the program. If the interpreter encounters another ''binding.pry'', a pry session is again opened. This can be incredibly annoying, since our program will stop and we’ll have to navigate the debugger every single time, so we’ll probably want to type exit-program to cancel the effect of any following ''binding.pry'' statements, thereby exiting our rails application.&lt;br /&gt;
&lt;br /&gt;
=== Breakpoints: ===&lt;br /&gt;
:You could set or change the breakpoints in a program directly using Pry. The ''break'' command is used for this purpose. You could set breakpoints in the current file, or in any other file, or a method. Conditional breakpoints could also be changed or set using optional expressions.&lt;br /&gt;
&lt;br /&gt;
:Command to display the list of breakpoints and conditional breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break --condition 4 x &amp;gt; 2      Change condition on breakpoint #4 to 'x &amp;gt; 2'.&lt;br /&gt;
break --condition 6            Remove the condition on breakpoint #6.&lt;br /&gt;
break                          List all breakpoints. (Same as `breakpoints`)&lt;br /&gt;
break --show 2                 Show details about breakpoint #2.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Setting breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break 5                        Break at line 5 in the current file.&lt;br /&gt;
break &amp;lt;class_name&amp;gt;#run         Break at the start of `&amp;lt;class_name&amp;gt;#run`.&lt;br /&gt;
break app/models/test.rb:4     Break at line 4 in test.rb.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Deleting breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break --delete 5               Delete breakpoint #5.&lt;br /&gt;
break --disable-all            Disable all breakpoints.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The Edit command: ===&lt;br /&gt;
:You could edit the code in a file by just switching to the editor rather than having to end the Pry session. This could be done using the ''edit'' command&amp;lt;ref&amp;gt;http://kgrz.io/pry/2014/02/07/Prys-edit-command.html&amp;lt;/ref&amp;gt;. On using the ''edit'' command, a new editor window pops up thereby enabling the programmer to edit the code. However, you need to specify the type of editor in the ''.pryrc'' file. For example, in order to edit the code using a Notepad editor, you need to specify the following in the ''.pryrc'' file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pry.config.editor = 'Notepad'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:SnOutput1.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== View the documentation or source for a method: ===&lt;br /&gt;
:You sometimes would want to know how a particular method works or what kind of arguments it takes. The ''show-doc'' method could help you determine that. Also, you would want to know the source of the method. This could be done using the ''show-method'' command.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pry(main)&amp;gt; def foo&lt;br /&gt;
pry(main)*   puts &amp;quot;Welcome to the foo!!&amp;quot;&lt;br /&gt;
pry(main)* end  &lt;br /&gt;
=&amp;gt; nil&lt;br /&gt;
pry(main)&amp;gt; show-method foo&lt;br /&gt;
 &lt;br /&gt;
From: (pry) @ line 3:&lt;br /&gt;
Number of lines: 3&lt;br /&gt;
Owner: Object&lt;br /&gt;
Visibility: private&lt;br /&gt;
 &lt;br /&gt;
def foo&lt;br /&gt;
  puts &amp;quot;Welcome to the foo!!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of other commonly used commands: ===&lt;br /&gt;
:The other list of commands could be found by typing ''help''&amp;lt;ref&amp;gt;https://github.com/pry/pry/wiki/Command-system#Help_command&amp;lt;/ref&amp;gt;. The following shows other list of commands:&lt;br /&gt;
&lt;br /&gt;
[[File:Help1.jpg]]&lt;br /&gt;
&lt;br /&gt;
:Interested people can learn more about using Pry as a debugger by watching the video [http://www.youtube.com/watch?v=o90CCPjcIKE tutorial].&lt;br /&gt;
&lt;br /&gt;
= Remote Debugging&amp;lt;ref&amp;gt;http://wiki.freepascal.org/Remote_Debugging&amp;lt;/ref&amp;gt; =&lt;br /&gt;
:So far, Pry has been a good tool to digging into the code and checking how the code is actually working and what is exactly going on inside the code. We used ''binding.pry'' inside the program where the execution stops and the user is asked to give further instructions. However, there are situations where the execution of the program would not stop and the would not allow you to inspect the code especially in situations when [https://github.com/yegrb/yeg-wiki/wiki/Managing-application-processes-with-the-Foreman-gem Foreman] is used to manage processes. In such situation, ''pry-remote'' could be of help.&lt;br /&gt;
&lt;br /&gt;
:When a process that is being run by Foreman comes across ''binding.pry'', it would halt but a Pry session would not be opened. You would be forced to kill the process as the application actually freezes. Thus, in such cases ''pry-remote'' would be a great solution and in order to work around with this, you need to first install the gem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install pry-remote&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Then run bundler:&lt;br /&gt;
&amp;lt;pre&amp;gt;    &lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Once you have installed ''pry-remote'', a breakpoint can be added using ''binding.remote_pry'' anywhere in the program from where the code needs to be debugged. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:''Pry-remote'' would block your program when it hits the ''binding.remote_pry'' and open a Drb endpoint that a client can connect to&amp;lt;ref&amp;gt;http://www.ruby-doc.org/stdlib-1.9.3/libdoc/drb/rdoc/DRb.html&amp;lt;/ref&amp;gt;. Running pry-remote in a shell will then connect to the session. You would then be able to interact with Pry as you would normally do. You could unblock the program by using ''exit''.&lt;br /&gt;
&lt;br /&gt;
= Comparison with other debugging tools =&lt;br /&gt;
Pry is a replacement for Ruby's default REPL,irb. It has many more additional features as compared to irb. Some of the features that provide Pry an edge over the other debugging tools are as follows:&lt;br /&gt;
:*Pry enables code or syntax highlighting, auto identation and a runtime debugging console.&lt;br /&gt;
:*It has the ability to load any portion of the file in your text editor directly into the REPL session.&lt;br /&gt;
&lt;br /&gt;
Other Debuggers available in the market are:&lt;br /&gt;
:*[http://www.jetbrains.com/ruby/quickstart/ JetBrains RubyMine] Commercial but very easy to use windows based debugger. It supports Ruby versions from 1.8.6 to 2.1.&lt;br /&gt;
:*[http://komodoide.com/features/ Komodo] Commercial IDE used for Ruby and other languages like Perl and java. It has graphical debugger and supports multi-process debugging.&lt;br /&gt;
:*[http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-chrome-devtools.html Chrome Dev-tools] The elements tab is used to debug and get rapid feedback about experimental design changes in HTML or CSS.&lt;br /&gt;
:*[http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-memcached.html Memcached] In production environment this tool can be used in addition with Heroku to access detailed stats about Memcached usage to find if you have hit rate or low eviction rate.&lt;br /&gt;
:*[http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-operating-system-tools.html Operating System Tools] Mostly a mixture of commands used to debug only specific errors for example, Curl to debug URL's or G Debugger to debug infinite loops.&lt;br /&gt;
&lt;br /&gt;
[http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html This website has a lot of comparison between Pry Debugger with other debuggers available in market.]&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_sn&amp;diff=88043</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 sn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_sn&amp;diff=88043"/>
		<updated>2014-09-24T03:01:54Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* List of other commonly used commands: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Debugging in Rails using Pry''' =&lt;br /&gt;
&lt;br /&gt;
Debugging is a process of finding and reducing the bugs or defects in a computer program thereby making it behave as expected. Few of the debugging techniques are [http://en.wikipedia.org/wiki/Debug_code#Print_debugging  Print debugging] (also known as printf debugging), Log debugging and Interactive debugging&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_logging.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://object.io/site/2011/getting-to-know-ruby-debugger/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] provides a range of options to make debugging&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Debugging&amp;lt;/ref&amp;gt; easier which include debug helpers, loggers, graphical debuggers, Pry, and so on&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/debugging_rails_applications.html&amp;lt;/ref&amp;gt;. In the following sections, debugging in rails using PRY is being explained.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction to Pry debugger =&lt;br /&gt;
&lt;br /&gt;
:Pry is an [http://en.wikipedia.org/wiki/Shell_(computing) interactive shell] for the Ruby programming language. Pry could be started at any point within a running program. Due to this, programmers can inspect the program, correct the source code, or change its current state without having to restart the process. Pry is thus notable for its ability to start a [http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop REPL] within a running program.&lt;br /&gt;
&lt;br /&gt;
:Pry has many features that make it extremely efficient to use. One of the example here could be Pry's ''hist --grep'' that makes it easy to search through your Pry history. Also, Pry uses the filesystem metaphor for exposing most of its introspective capabilities such as the ''ls'' command to list the methods and variables and the ''cd'' command to start interacting with a particular object.&lt;br /&gt;
&lt;br /&gt;
:To start a debugging session, you need to include the ''require 'pry' '' and ''binding.pry'' lines in your program that needs to be debugged. You could insert the line ''binding.pry'' at any point in your program. Whenever the Ruby interpreter executes this line, it opens a Pry REPL session. The code after the ''binding.pry'' statement is not executed unless instructed by the programmer. We could make changes to fix the code and then return to running program from same point.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
:To use Pry for debugging a Rails application, you first need to download and install Pry-debugger. If you are using Ruby version 2.0 or higher, then download pry-debugger from [https://github.com/deivid-rodriguez/pry-byebug here]. If you are using Ruby version 1.9 or lower, then download pry-debugger from [https://rubygems.org/gems/pry-debugger here].&lt;br /&gt;
&lt;br /&gt;
:To install the debugger use the following command:&amp;lt;ref&amp;gt;http://pryrepl.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install pry-debugger.gem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Include the following line of code on the gem file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'pry-rails', :group =&amp;gt; :development&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Once that is done, the necessary dependencies could be installed using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Execution Commands =&lt;br /&gt;
:To use the execution command, invoke pry normally. There is no need to start your script or application differently. For the sake of clarity in explanation, we would refer to the program below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry'&lt;br /&gt;
def method1 (seller)&lt;br /&gt;
	puts 'Inside method 1'&lt;br /&gt;
	method2(seller)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def method2(seller)&lt;br /&gt;
  binding.pry      	# Execution will stop here.&lt;br /&gt;
  new_products = method3(seller)&lt;br /&gt;
  puts 'After calling method3'&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def method3(seller)&lt;br /&gt;
	puts 'Inside method 3'&lt;br /&gt;
	puts 'Continuing in method 3'&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
method1('xyz')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The Step command: ===&lt;br /&gt;
:The ''step'' command continues execution by moving into the method on the next line. To put it in another way, the command takes us deeper into the method. Following our example, the ''step'' command would take us into ''method3'' at which point we would be asked what to do next. The following screenshot demonstrates our example:&lt;br /&gt;
&lt;br /&gt;
[[File:Step.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== The Next command: ===&lt;br /&gt;
:The ''next'' command runs the current line and moves to the next line in the current context.  If the next line in the code is a method call, then unlike the ''step'' method the execution does not go deeper into the method. Following our example, if we execute the above code, the execution stop at the ''binding.pry'' line and the debugger asks us for the further action. On using the ''next'' command, the execution moves to the next line that is '' new_products = method3(seller)'' without going deeper into the method. The debugger now waits for another instruction from the programmer and if the command is ''next'' again, the debugger simply goes to the next line of code after executing the method. Thus, all the code within the ''method3'' method (which would otherwise be many steps), has been concluded with a single use of the ''next'' command. The example could be seen in the following screenshot:&lt;br /&gt;
&lt;br /&gt;
[[File:Next.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== The Finish command: ===&lt;br /&gt;
:Now once we have stepped into a method using the ''step'' command, the debugger would ask us what needs to be done next. Now if we want to jump to the end of the method without the debugger asking us our choice of navigation command at the end of each line, we could use the ''finish'' command. The ''finish'' command would execute the code in the method and return back to the point from where the method was called. In our example, while the debugger is in ''method3'', the ''finish'' command would complete the code execution in ''method3'' and return back to ''method2''.&lt;br /&gt;
&lt;br /&gt;
=== The Continue command: ===&lt;br /&gt;
:With this command we can abandon the pry session and continue the normal execution of the program. If the interpreter encounters another ''binding.pry'', a pry session is again opened. This can be incredibly annoying, since our program will stop and we’ll have to navigate the debugger every single time, so we’ll probably want to type exit-program to cancel the effect of any following ''binding.pry'' statements, thereby exiting our rails application.&lt;br /&gt;
&lt;br /&gt;
=== Breakpoints: ===&lt;br /&gt;
:You could set or change the breakpoints in a program directly using Pry. The ''break'' command is used for this purpose. You could set breakpoints in the current file, or in any other file, or a method. Conditional breakpoints could also be changed or set using optional expressions.&lt;br /&gt;
&lt;br /&gt;
:Command to display the list of breakpoints and conditional breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break --condition 4 x &amp;gt; 2      Change condition on breakpoint #4 to 'x &amp;gt; 2'.&lt;br /&gt;
break --condition 6            Remove the condition on breakpoint #6.&lt;br /&gt;
break                          List all breakpoints. (Same as `breakpoints`)&lt;br /&gt;
break --show 2                 Show details about breakpoint #2.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Setting breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break 5                        Break at line 5 in the current file.&lt;br /&gt;
break &amp;lt;class_name&amp;gt;#run         Break at the start of `&amp;lt;class_name&amp;gt;#run`.&lt;br /&gt;
break app/models/test.rb:4     Break at line 4 in test.rb.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Deleting breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break --delete 5               Delete breakpoint #5.&lt;br /&gt;
break --disable-all            Disable all breakpoints.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The Edit command: ===&lt;br /&gt;
:You could edit the code in a file by just switching to the editor rather than having to end the Pry session. This could be done using the ''edit'' command&amp;lt;ref&amp;gt;http://kgrz.io/pry/2014/02/07/Prys-edit-command.html&amp;lt;/ref&amp;gt;. On using the ''edit'' command, a new editor window pops up thereby enabling the programmer to edit the code. However, you need to specify the type of editor in the ''.pryrc'' file. For example, in order to edit the code using a Notepad editor, you need to specify the following in the ''.pryrc'' file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pry.config.editor = 'Notepad'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:SnOutput1.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== View the documentation or source for a method: ===&lt;br /&gt;
:You sometimes would want to know how a particular method works or what kind of arguments it takes. The ''show-doc'' method could help you determine that. Also, you would want to know the source of the method. This could be done using the ''show-method'' command.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pry(main)&amp;gt; def foo&lt;br /&gt;
pry(main)*   puts &amp;quot;Welcome to the foo!!&amp;quot;&lt;br /&gt;
pry(main)* end  &lt;br /&gt;
=&amp;gt; nil&lt;br /&gt;
pry(main)&amp;gt; show-method foo&lt;br /&gt;
 &lt;br /&gt;
From: (pry) @ line 3:&lt;br /&gt;
Number of lines: 3&lt;br /&gt;
Owner: Object&lt;br /&gt;
Visibility: private&lt;br /&gt;
 &lt;br /&gt;
def foo&lt;br /&gt;
  puts &amp;quot;Welcome to the foo!!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of other commonly used commands: ===&lt;br /&gt;
:The other list of commands could be found by typing ''help''&amp;lt;ref&amp;gt;https://github.com/pry/pry/wiki/Command-system#Help_command&amp;lt;/ref&amp;gt;. The following shows other list of commands:&lt;br /&gt;
&lt;br /&gt;
[[File:Help1.jpg]]&lt;br /&gt;
&lt;br /&gt;
:Interested people can learn more about using Pry as a debugger by watching this video [http://www.youtube.com/watch?v=o90CCPjcIKE tutorial].&lt;br /&gt;
&lt;br /&gt;
= Remote Debugging&amp;lt;ref&amp;gt;http://wiki.freepascal.org/Remote_Debugging&amp;lt;/ref&amp;gt; =&lt;br /&gt;
:So far, Pry has been a good tool to digging into the code and checking how the code is actually working and what is exactly going on inside the code. We used ''binding.pry'' inside the program where the execution stops and the user is asked to give further instructions. However, there are situations where the execution of the program would not stop and the would not allow you to inspect the code especially in situations when [https://github.com/yegrb/yeg-wiki/wiki/Managing-application-processes-with-the-Foreman-gem Foreman] is used to manage processes. In such situation, ''pry-remote'' could be of help.&lt;br /&gt;
&lt;br /&gt;
:When a process that is being run by Foreman comes across ''binding.pry'', it would halt but a Pry session would not be opened. You would be forced to kill the process as the application actually freezes. Thus, in such cases ''pry-remote'' would be a great solution and in order to work around with this, you need to first install the gem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install pry-remote&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Then run bundler:&lt;br /&gt;
&amp;lt;pre&amp;gt;    &lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Once you have installed ''pry-remote'', a breakpoint can be added using ''binding.remote_pry'' anywhere in the program from where the code needs to be debugged. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:''Pry-remote'' would block your program when it hits the ''binding.remote_pry'' and open a Drb endpoint that a client can connect to&amp;lt;ref&amp;gt;http://www.ruby-doc.org/stdlib-1.9.3/libdoc/drb/rdoc/DRb.html&amp;lt;/ref&amp;gt;. Running pry-remote in a shell will then connect to the session. You would then be able to interact with Pry as you would normally do. You could unblock the program by using ''exit''.&lt;br /&gt;
&lt;br /&gt;
= Comparison with other debugging tools =&lt;br /&gt;
Pry is a replacement for Ruby's default REPL,irb. It has many more additional features as compared to irb. Some of the features that provide Pry an edge over the other debugging tools are as follows:&lt;br /&gt;
:*Pry enables code or syntax highlighting, auto identation and a runtime debugging console.&lt;br /&gt;
:*It has the ability to load any portion of the file in your text editor directly into the REPL session.&lt;br /&gt;
[http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html This website has a lot of comparison between Pry Debugger with other debuggers available in market.]&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_sn&amp;diff=88041</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 sn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_sn&amp;diff=88041"/>
		<updated>2014-09-24T02:57:14Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* Comparison with other debugging tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Debugging in Rails using Pry''' =&lt;br /&gt;
&lt;br /&gt;
Debugging is a process of finding and reducing the bugs or defects in a computer program thereby making it behave as expected. Few of the debugging techniques are [http://en.wikipedia.org/wiki/Debug_code#Print_debugging  Print debugging] (also known as printf debugging), Log debugging and Interactive debugging&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_logging.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://object.io/site/2011/getting-to-know-ruby-debugger/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] provides a range of options to make debugging&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Debugging&amp;lt;/ref&amp;gt; easier which include debug helpers, loggers, graphical debuggers, Pry, and so on&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/debugging_rails_applications.html&amp;lt;/ref&amp;gt;. In the following sections, debugging in rails using PRY is being explained.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction to Pry debugger =&lt;br /&gt;
&lt;br /&gt;
:Pry is an [http://en.wikipedia.org/wiki/Shell_(computing) interactive shell] for the Ruby programming language. Pry could be started at any point within a running program. Due to this, programmers can inspect the program, correct the source code, or change its current state without having to restart the process. Pry is thus notable for its ability to start a [http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop REPL] within a running program.&lt;br /&gt;
&lt;br /&gt;
:Pry has many features that make it extremely efficient to use. One of the example here could be Pry's ''hist --grep'' that makes it easy to search through your Pry history. Also, Pry uses the filesystem metaphor for exposing most of its introspective capabilities such as the ''ls'' command to list the methods and variables and the ''cd'' command to start interacting with a particular object.&lt;br /&gt;
&lt;br /&gt;
:To start a debugging session, you need to include the ''require 'pry' '' and ''binding.pry'' lines in your program that needs to be debugged. You could insert the line ''binding.pry'' at any point in your program. Whenever the Ruby interpreter executes this line, it opens a Pry REPL session. The code after the ''binding.pry'' statement is not executed unless instructed by the programmer. We could make changes to fix the code and then return to running program from same point.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
:To use Pry for debugging a Rails application, you first need to download and install Pry-debugger. If you are using Ruby version 2.0 or higher, then download pry-debugger from [https://github.com/deivid-rodriguez/pry-byebug here]. If you are using Ruby version 1.9 or lower, then download pry-debugger from [https://rubygems.org/gems/pry-debugger here].&lt;br /&gt;
&lt;br /&gt;
:To install the debugger use the following command:&amp;lt;ref&amp;gt;http://pryrepl.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install pry-debugger.gem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Include the following line of code on the gem file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'pry-rails', :group =&amp;gt; :development&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Once that is done, the necessary dependencies could be installed using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Execution Commands =&lt;br /&gt;
:To use the execution command, invoke pry normally. There is no need to start your script or application differently. For the sake of clarity in explanation, we would refer to the program below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry'&lt;br /&gt;
def method1 (seller)&lt;br /&gt;
	puts 'Inside method 1'&lt;br /&gt;
	method2(seller)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def method2(seller)&lt;br /&gt;
  binding.pry      	# Execution will stop here.&lt;br /&gt;
  new_products = method3(seller)&lt;br /&gt;
  puts 'After calling method3'&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def method3(seller)&lt;br /&gt;
	puts 'Inside method 3'&lt;br /&gt;
	puts 'Continuing in method 3'&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
method1('xyz')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The Step command: ===&lt;br /&gt;
:The ''step'' command continues execution by moving into the method on the next line. To put it in another way, the command takes us deeper into the method. Following our example, the ''step'' command would take us into ''method3'' at which point we would be asked what to do next. The following screenshot demonstrates our example:&lt;br /&gt;
&lt;br /&gt;
[[File:Step.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== The Next command: ===&lt;br /&gt;
:The ''next'' command runs the current line and moves to the next line in the current context.  If the next line in the code is a method call, then unlike the ''step'' method the execution does not go deeper into the method. Following our example, if we execute the above code, the execution stop at the ''binding.pry'' line and the debugger asks us for the further action. On using the ''next'' command, the execution moves to the next line that is '' new_products = method3(seller)'' without going deeper into the method. The debugger now waits for another instruction from the programmer and if the command is ''next'' again, the debugger simply goes to the next line of code after executing the method. Thus, all the code within the ''method3'' method (which would otherwise be many steps), has been concluded with a single use of the ''next'' command. The example could be seen in the following screenshot:&lt;br /&gt;
&lt;br /&gt;
[[File:Next.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== The Finish command: ===&lt;br /&gt;
:Now once we have stepped into a method using the ''step'' command, the debugger would ask us what needs to be done next. Now if we want to jump to the end of the method without the debugger asking us our choice of navigation command at the end of each line, we could use the ''finish'' command. The ''finish'' command would execute the code in the method and return back to the point from where the method was called. In our example, while the debugger is in ''method3'', the ''finish'' command would complete the code execution in ''method3'' and return back to ''method2''.&lt;br /&gt;
&lt;br /&gt;
=== The Continue command: ===&lt;br /&gt;
:With this command we can abandon the pry session and continue the normal execution of the program. If the interpreter encounters another ''binding.pry'', a pry session is again opened. This can be incredibly annoying, since our program will stop and we’ll have to navigate the debugger every single time, so we’ll probably want to type exit-program to cancel the effect of any following ''binding.pry'' statements, thereby exiting our rails application.&lt;br /&gt;
&lt;br /&gt;
=== Breakpoints: ===&lt;br /&gt;
:You could set or change the breakpoints in a program directly using Pry. The ''break'' command is used for this purpose. You could set breakpoints in the current file, or in any other file, or a method. Conditional breakpoints could also be changed or set using optional expressions.&lt;br /&gt;
&lt;br /&gt;
:Command to display the list of breakpoints and conditional breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break --condition 4 x &amp;gt; 2      Change condition on breakpoint #4 to 'x &amp;gt; 2'.&lt;br /&gt;
break --condition 6            Remove the condition on breakpoint #6.&lt;br /&gt;
break                          List all breakpoints. (Same as `breakpoints`)&lt;br /&gt;
break --show 2                 Show details about breakpoint #2.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Setting breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break 5                        Break at line 5 in the current file.&lt;br /&gt;
break &amp;lt;class_name&amp;gt;#run         Break at the start of `&amp;lt;class_name&amp;gt;#run`.&lt;br /&gt;
break app/models/test.rb:4     Break at line 4 in test.rb.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Deleting breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break --delete 5               Delete breakpoint #5.&lt;br /&gt;
break --disable-all            Disable all breakpoints.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The Edit command: ===&lt;br /&gt;
:You could edit the code in a file by just switching to the editor rather than having to end the Pry session. This could be done using the ''edit'' command&amp;lt;ref&amp;gt;http://kgrz.io/pry/2014/02/07/Prys-edit-command.html&amp;lt;/ref&amp;gt;. On using the ''edit'' command, a new editor window pops up thereby enabling the programmer to edit the code. However, you need to specify the type of editor in the ''.pryrc'' file. For example, in order to edit the code using a Notepad editor, you need to specify the following in the ''.pryrc'' file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pry.config.editor = 'Notepad'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:SnOutput1.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== View the documentation or source for a method: ===&lt;br /&gt;
:You sometimes would want to know how a particular method works or what kind of arguments it takes. The ''show-doc'' method could help you determine that. Also, you would want to know the source of the method. This could be done using the ''show-method'' command.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pry(main)&amp;gt; def foo&lt;br /&gt;
pry(main)*   puts &amp;quot;Welcome to the foo!!&amp;quot;&lt;br /&gt;
pry(main)* end  &lt;br /&gt;
=&amp;gt; nil&lt;br /&gt;
pry(main)&amp;gt; show-method foo&lt;br /&gt;
 &lt;br /&gt;
From: (pry) @ line 3:&lt;br /&gt;
Number of lines: 3&lt;br /&gt;
Owner: Object&lt;br /&gt;
Visibility: private&lt;br /&gt;
 &lt;br /&gt;
def foo&lt;br /&gt;
  puts &amp;quot;Welcome to the foo!!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of other commonly used commands: ===&lt;br /&gt;
:The other list of commands could be found by typing ''help''&amp;lt;ref&amp;gt;https://github.com/pry/pry/wiki/Command-system#Help_command&amp;lt;/ref&amp;gt;. The following shows other list of commands:&lt;br /&gt;
&lt;br /&gt;
[[File:Help1.jpg]]&lt;br /&gt;
&lt;br /&gt;
= Remote Debugging&amp;lt;ref&amp;gt;http://wiki.freepascal.org/Remote_Debugging&amp;lt;/ref&amp;gt; =&lt;br /&gt;
:So far, Pry has been a good tool to digging into the code and checking how the code is actually working and what is exactly going on inside the code. We used ''binding.pry'' inside the program where the execution stops and the user is asked to give further instructions. However, there are situations where the execution of the program would not stop and the would not allow you to inspect the code especially in situations when [https://github.com/yegrb/yeg-wiki/wiki/Managing-application-processes-with-the-Foreman-gem Foreman] is used to manage processes. In such situation, ''pry-remote'' could be of help.&lt;br /&gt;
&lt;br /&gt;
:When a process that is being run by Foreman comes across ''binding.pry'', it would halt but a Pry session would not be opened. You would be forced to kill the process as the application actually freezes. Thus, in such cases ''pry-remote'' would be a great solution and in order to work around with this, you need to first install the gem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install pry-remote&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Then run bundler:&lt;br /&gt;
&amp;lt;pre&amp;gt;    &lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Once you have installed ''pry-remote'', a breakpoint can be added using ''binding.remote_pry'' anywhere in the program from where the code needs to be debugged. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:''Pry-remote'' would block your program when it hits the ''binding.remote_pry'' and open a Drb endpoint that a client can connect to&amp;lt;ref&amp;gt;http://www.ruby-doc.org/stdlib-1.9.3/libdoc/drb/rdoc/DRb.html&amp;lt;/ref&amp;gt;. Running pry-remote in a shell will then connect to the session. You would then be able to interact with Pry as you would normally do. You could unblock the program by using ''exit''.&lt;br /&gt;
&lt;br /&gt;
= Comparison with other debugging tools =&lt;br /&gt;
Pry is a replacement for Ruby's default REPL,irb. It has many more additional features as compared to irb. Some of the features that provide Pry an edge over the other debugging tools are as follows:&lt;br /&gt;
:*Pry enables code or syntax highlighting, auto identation and a runtime debugging console.&lt;br /&gt;
:*It has the ability to load any portion of the file in your text editor directly into the REPL session.&lt;br /&gt;
[http://www.jackkinsella.ie/2014/06/06/debugging-rails-with-pry-debugger.html This website has a lot of comparison between Pry Debugger with other debuggers available in market.]&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_sn&amp;diff=88039</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 26 sn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_26_sn&amp;diff=88039"/>
		<updated>2014-09-24T02:54:34Z</updated>

		<summary type="html">&lt;p&gt;Nurahman: /* Debugging in Rails using Pry */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Debugging in Rails using Pry''' =&lt;br /&gt;
&lt;br /&gt;
Debugging is a process of finding and reducing the bugs or defects in a computer program thereby making it behave as expected. Few of the debugging techniques are [http://en.wikipedia.org/wiki/Debug_code#Print_debugging  Print debugging] (also known as printf debugging), Log debugging and Interactive debugging&amp;lt;ref&amp;gt;http://rubylearning.com/satishtalim/ruby_logging.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://object.io/site/2011/getting-to-know-ruby-debugger/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] provides a range of options to make debugging&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Debugging&amp;lt;/ref&amp;gt; easier which include debug helpers, loggers, graphical debuggers, Pry, and so on&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/debugging_rails_applications.html&amp;lt;/ref&amp;gt;. In the following sections, debugging in rails using PRY is being explained.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction to Pry debugger =&lt;br /&gt;
&lt;br /&gt;
:Pry is an [http://en.wikipedia.org/wiki/Shell_(computing) interactive shell] for the Ruby programming language. Pry could be started at any point within a running program. Due to this, programmers can inspect the program, correct the source code, or change its current state without having to restart the process. Pry is thus notable for its ability to start a [http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop REPL] within a running program.&lt;br /&gt;
&lt;br /&gt;
:Pry has many features that make it extremely efficient to use. One of the example here could be Pry's ''hist --grep'' that makes it easy to search through your Pry history. Also, Pry uses the filesystem metaphor for exposing most of its introspective capabilities such as the ''ls'' command to list the methods and variables and the ''cd'' command to start interacting with a particular object.&lt;br /&gt;
&lt;br /&gt;
:To start a debugging session, you need to include the ''require 'pry' '' and ''binding.pry'' lines in your program that needs to be debugged. You could insert the line ''binding.pry'' at any point in your program. Whenever the Ruby interpreter executes this line, it opens a Pry REPL session. The code after the ''binding.pry'' statement is not executed unless instructed by the programmer. We could make changes to fix the code and then return to running program from same point.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
:To use Pry for debugging a Rails application, you first need to download and install Pry-debugger. If you are using Ruby version 2.0 or higher, then download pry-debugger from [https://github.com/deivid-rodriguez/pry-byebug here]. If you are using Ruby version 1.9 or lower, then download pry-debugger from [https://rubygems.org/gems/pry-debugger here].&lt;br /&gt;
&lt;br /&gt;
:To install the debugger use the following command:&amp;lt;ref&amp;gt;http://pryrepl.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install pry-debugger.gem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Include the following line of code on the gem file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'pry-rails', :group =&amp;gt; :development&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Once that is done, the necessary dependencies could be installed using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Execution Commands =&lt;br /&gt;
:To use the execution command, invoke pry normally. There is no need to start your script or application differently. For the sake of clarity in explanation, we would refer to the program below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'pry'&lt;br /&gt;
def method1 (seller)&lt;br /&gt;
	puts 'Inside method 1'&lt;br /&gt;
	method2(seller)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def method2(seller)&lt;br /&gt;
  binding.pry      	# Execution will stop here.&lt;br /&gt;
  new_products = method3(seller)&lt;br /&gt;
  puts 'After calling method3'&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def method3(seller)&lt;br /&gt;
	puts 'Inside method 3'&lt;br /&gt;
	puts 'Continuing in method 3'&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
method1('xyz')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The Step command: ===&lt;br /&gt;
:The ''step'' command continues execution by moving into the method on the next line. To put it in another way, the command takes us deeper into the method. Following our example, the ''step'' command would take us into ''method3'' at which point we would be asked what to do next. The following screenshot demonstrates our example:&lt;br /&gt;
&lt;br /&gt;
[[File:Step.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== The Next command: ===&lt;br /&gt;
:The ''next'' command runs the current line and moves to the next line in the current context.  If the next line in the code is a method call, then unlike the ''step'' method the execution does not go deeper into the method. Following our example, if we execute the above code, the execution stop at the ''binding.pry'' line and the debugger asks us for the further action. On using the ''next'' command, the execution moves to the next line that is '' new_products = method3(seller)'' without going deeper into the method. The debugger now waits for another instruction from the programmer and if the command is ''next'' again, the debugger simply goes to the next line of code after executing the method. Thus, all the code within the ''method3'' method (which would otherwise be many steps), has been concluded with a single use of the ''next'' command. The example could be seen in the following screenshot:&lt;br /&gt;
&lt;br /&gt;
[[File:Next.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== The Finish command: ===&lt;br /&gt;
:Now once we have stepped into a method using the ''step'' command, the debugger would ask us what needs to be done next. Now if we want to jump to the end of the method without the debugger asking us our choice of navigation command at the end of each line, we could use the ''finish'' command. The ''finish'' command would execute the code in the method and return back to the point from where the method was called. In our example, while the debugger is in ''method3'', the ''finish'' command would complete the code execution in ''method3'' and return back to ''method2''.&lt;br /&gt;
&lt;br /&gt;
=== The Continue command: ===&lt;br /&gt;
:With this command we can abandon the pry session and continue the normal execution of the program. If the interpreter encounters another ''binding.pry'', a pry session is again opened. This can be incredibly annoying, since our program will stop and we’ll have to navigate the debugger every single time, so we’ll probably want to type exit-program to cancel the effect of any following ''binding.pry'' statements, thereby exiting our rails application.&lt;br /&gt;
&lt;br /&gt;
=== Breakpoints: ===&lt;br /&gt;
:You could set or change the breakpoints in a program directly using Pry. The ''break'' command is used for this purpose. You could set breakpoints in the current file, or in any other file, or a method. Conditional breakpoints could also be changed or set using optional expressions.&lt;br /&gt;
&lt;br /&gt;
:Command to display the list of breakpoints and conditional breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break --condition 4 x &amp;gt; 2      Change condition on breakpoint #4 to 'x &amp;gt; 2'.&lt;br /&gt;
break --condition 6            Remove the condition on breakpoint #6.&lt;br /&gt;
break                          List all breakpoints. (Same as `breakpoints`)&lt;br /&gt;
break --show 2                 Show details about breakpoint #2.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Setting breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break 5                        Break at line 5 in the current file.&lt;br /&gt;
break &amp;lt;class_name&amp;gt;#run         Break at the start of `&amp;lt;class_name&amp;gt;#run`.&lt;br /&gt;
break app/models/test.rb:4     Break at line 4 in test.rb.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Deleting breakpoints:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
break --delete 5               Delete breakpoint #5.&lt;br /&gt;
break --disable-all            Disable all breakpoints.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The Edit command: ===&lt;br /&gt;
:You could edit the code in a file by just switching to the editor rather than having to end the Pry session. This could be done using the ''edit'' command&amp;lt;ref&amp;gt;http://kgrz.io/pry/2014/02/07/Prys-edit-command.html&amp;lt;/ref&amp;gt;. On using the ''edit'' command, a new editor window pops up thereby enabling the programmer to edit the code. However, you need to specify the type of editor in the ''.pryrc'' file. For example, in order to edit the code using a Notepad editor, you need to specify the following in the ''.pryrc'' file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Pry.config.editor = 'Notepad'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:SnOutput1.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== View the documentation or source for a method: ===&lt;br /&gt;
:You sometimes would want to know how a particular method works or what kind of arguments it takes. The ''show-doc'' method could help you determine that. Also, you would want to know the source of the method. This could be done using the ''show-method'' command.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pry(main)&amp;gt; def foo&lt;br /&gt;
pry(main)*   puts &amp;quot;Welcome to the foo!!&amp;quot;&lt;br /&gt;
pry(main)* end  &lt;br /&gt;
=&amp;gt; nil&lt;br /&gt;
pry(main)&amp;gt; show-method foo&lt;br /&gt;
 &lt;br /&gt;
From: (pry) @ line 3:&lt;br /&gt;
Number of lines: 3&lt;br /&gt;
Owner: Object&lt;br /&gt;
Visibility: private&lt;br /&gt;
 &lt;br /&gt;
def foo&lt;br /&gt;
  puts &amp;quot;Welcome to the foo!!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List of other commonly used commands: ===&lt;br /&gt;
:The other list of commands could be found by typing ''help''&amp;lt;ref&amp;gt;https://github.com/pry/pry/wiki/Command-system#Help_command&amp;lt;/ref&amp;gt;. The following shows other list of commands:&lt;br /&gt;
&lt;br /&gt;
[[File:Help1.jpg]]&lt;br /&gt;
&lt;br /&gt;
= Remote Debugging&amp;lt;ref&amp;gt;http://wiki.freepascal.org/Remote_Debugging&amp;lt;/ref&amp;gt; =&lt;br /&gt;
:So far, Pry has been a good tool to digging into the code and checking how the code is actually working and what is exactly going on inside the code. We used ''binding.pry'' inside the program where the execution stops and the user is asked to give further instructions. However, there are situations where the execution of the program would not stop and the would not allow you to inspect the code especially in situations when [https://github.com/yegrb/yeg-wiki/wiki/Managing-application-processes-with-the-Foreman-gem Foreman] is used to manage processes. In such situation, ''pry-remote'' could be of help.&lt;br /&gt;
&lt;br /&gt;
:When a process that is being run by Foreman comes across ''binding.pry'', it would halt but a Pry session would not be opened. You would be forced to kill the process as the application actually freezes. Thus, in such cases ''pry-remote'' would be a great solution and in order to work around with this, you need to first install the gem:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install pry-remote&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Then run bundler:&lt;br /&gt;
&amp;lt;pre&amp;gt;    &lt;br /&gt;
bundle install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:Once you have installed ''pry-remote'', a breakpoint can be added using ''binding.remote_pry'' anywhere in the program from where the code needs to be debugged. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    binding.remote_pry&lt;br /&gt;
    ...&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:''Pry-remote'' would block your program when it hits the ''binding.remote_pry'' and open a Drb endpoint that a client can connect to&amp;lt;ref&amp;gt;http://www.ruby-doc.org/stdlib-1.9.3/libdoc/drb/rdoc/DRb.html&amp;lt;/ref&amp;gt;. Running pry-remote in a shell will then connect to the session. You would then be able to interact with Pry as you would normally do. You could unblock the program by using ''exit''.&lt;br /&gt;
&lt;br /&gt;
= Comparison with other debugging tools =&lt;br /&gt;
Pry is a replacement for Ruby's default REPL,irb. It has many more additional features as compared to irb. Some of the features that provide Pry an edge over the other debugging tools are as follows:&lt;br /&gt;
:*Pry enables code or syntax highlighting, auto identation and a runtime debugging console.&lt;br /&gt;
:*It has the ability to load any portion of the file in your text editor directly into the REPL session.&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nurahman</name></author>
	</entry>
</feed>