<?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=Njclimer</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=Njclimer"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Njclimer"/>
	<updated>2026-06-06T22:14:58Z</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=90213</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=90213"/>
		<updated>2014-10-29T01:06:10Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: /* References */&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;
&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>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90212</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=90212"/>
		<updated>2014-10-29T01:05:59Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: /* References */&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;
&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;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit Global Style Guide]&lt;br /&gt;
[https://github.com/expertiza/expertiza/ Expertiza Github Repository]&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/431 Pull Request for E1461]&lt;/div&gt;</summary>
		<author><name>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90209</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=90209"/>
		<updated>2014-10-29T01:04:15Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: /* References */&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;
&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]&lt;/div&gt;</summary>
		<author><name>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90208</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=90208"/>
		<updated>2014-10-29T01:03:31Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: /* Bug in Create */&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;
&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;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit]&lt;/div&gt;</summary>
		<author><name>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90206</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=90206"/>
		<updated>2014-10-29T01:01:57Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: /* Clean up Permissions */&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;
&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 as well.&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;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit]&lt;/div&gt;</summary>
		<author><name>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90205</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=90205"/>
		<updated>2014-10-29T01:01:30Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: /* Clean up Permissions */&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;
&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;
     @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 as well.&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;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit]&lt;/div&gt;</summary>
		<author><name>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90204</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=90204"/>
		<updated>2014-10-29T01:00:13Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: /* 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;
&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;
==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 as well.&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;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit]&lt;/div&gt;</summary>
		<author><name>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90203</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=90203"/>
		<updated>2014-10-29T00:59:37Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: /* 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;
==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;
==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 as well.&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;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit]&lt;/div&gt;</summary>
		<author><name>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90202</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=90202"/>
		<updated>2014-10-29T00:57:15Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: &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;
&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;
==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 as well.&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;
[https://docs.google.com/document/d/1qQD7fcypFk77nq7Jx7ZNyCNpLyt1oXKaq5G-W7zkV3k/edit]&lt;/div&gt;</summary>
		<author><name>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90197</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=90197"/>
		<updated>2014-10-29T00:51:39Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: /* Style Changes Based on Current Conventions */&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;
&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;
==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 as well.&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>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90193</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=90193"/>
		<updated>2014-10-29T00:36:03Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: /* &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;
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;
&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;
==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 as well.&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>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90191</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=90191"/>
		<updated>2014-10-29T00:28:35Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: /* Clean up Permissions */&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;
==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 as well.&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>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90188</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=90188"/>
		<updated>2014-10-29T00:17:56Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: /* Clean up Permissions */&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 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>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90187</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=90187"/>
		<updated>2014-10-29T00:17:22Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: /* Clean up Permissions */&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;
&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>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90186</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=90186"/>
		<updated>2014-10-29T00:16:07Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: /* 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;
===&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;
&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>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90185</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=90185"/>
		<updated>2014-10-29T00:15:41Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: &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>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90183</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=90183"/>
		<updated>2014-10-29T00:12:34Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: &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;
==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>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90162</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=90162"/>
		<updated>2014-10-28T23:50:55Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: &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;
=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>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1461_knn&amp;diff=90161</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=90161"/>
		<updated>2014-10-28T23:50:15Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: &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;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Removed Comment out Code&lt;br /&gt;
&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;
&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;
&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>Njclimer</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_16_av&amp;diff=88472</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 16 av</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_16_av&amp;diff=88472"/>
		<updated>2014-09-25T22:16:45Z</updated>

		<summary type="html">&lt;p&gt;Njclimer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/document/d/1eq3XHiUUBIrEBx-R2Mgolaw7HttSgzPniwDLEF5oVk0/edit?pli=1 Writeup Page]&lt;br /&gt;
&amp;lt;b&amp;gt;Continuous integration pipelines&amp;lt;/b&amp;gt; (CIP) are software packages that help groups of developers manage, maintain, merge, build and test software continuously and automatically throughout the day. These packages provide the infrastructure to support the practice of &amp;lt;b&amp;gt;Continuous Integration&amp;lt;/b&amp;gt; (CI), a method of continuously combining everyone changes in order to prevent integration issues.&lt;br /&gt;
&lt;br /&gt;
=Continuous Integration=&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
==Introduction to the Pactice of Continuous Integration==&lt;br /&gt;
Before we talk about the pipelines that support it, we must define continuose integration itself. Continuous integration has gained a lot of popularity with agile development, called out specifically in the flavor of agile called Extreme Programming (XP).&amp;lt;ref name=&amp;quot;Stahl&amp;quot;&amp;gt;D. Ståhl Modeling continuous integration practice differences in industry software development J. Syst. Software 87pp. 48 &amp;lt;last_page&amp;gt; 59. 2014. . DOI: 10.1016/j.jss.2013.08.032.&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;Meyer&amp;quot;&amp;gt;M. Meyer. Continuous integration and its tools IEEE Software 31(3), pp. 14 &amp;lt;last_page&amp;gt; 16. 2014. . DOI: 10.1109/MS.2014.58.&amp;lt;/ref&amp;gt; As agile developers began to shy away from the traditional waterfall development cycle and move towards smaller cycles, the need to limit the global gates that software needed to go through arose.&lt;br /&gt;
&lt;br /&gt;
The core idea is that the longer code sits with a developer, the more bugs they can introduce to the code. The older bugs are, the more they cost to fix. To combat this, continuous integration is a push to test, merge, combine, and package builds every day.&lt;br /&gt;
&lt;br /&gt;
One of the core tenets of agile program that enable continuous integration is the idea of test driven development. Test driven development is the idea that you should design the tests that a piece of code should pass before developing the code, then writing the minimal amount of code required to pass all tests. If there is a function or feature that is not captured by the tests, it should not be coded. These tests were first developed as personal unit tests. Later, this was expanded into automated unit testing with unit testing frameworks, such as CUnit, JUnit, etc.&lt;br /&gt;
By running the test on each commit, it becomes immediately apparent on which commit the bug was introduced or exposed. This allows for less backtracking when dealing with show-stopping bugs.&amp;lt;ref name=&amp;quot;P.Duvall&amp;quot;&amp;gt; P. Duvall, S. Matyas and A. Glover. Continuous Integration: Improving Software Quality and Reducing Risk 2007Available: Table of contents only http://www.loc.gov/catdir/toc/ecip0714/2007012001.html&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;Meyer&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Later developments in this process adopted the use of a “build server”-a separate, clean development environment that is independent of the developers work environment. By integrating the source control, build server, and unit testing into one interface, the whole process can be managed from one single pipeline.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Continuous Integration History===&lt;br /&gt;
The idea for continuous integration has been around for a lot longer than there has been a name for it or tools to run it. Nightly or daily builds have been toted as a valued for decades.&amp;lt;ref name=&amp;quot;M.Fowler&amp;quot;/&amp;gt;&lt;br /&gt;
Many institutions began with in-house processes that supported some form continuous development. These systems were primarily put in place to deal with the resource heavy requirements of building and maintaining software. This induced daily cycles of commit, merge, test, and report. As the popularity of this system arose, it created a market for continuous integration pipeline software. These in house tools used build automation tools like build servers to create their software.&lt;br /&gt;
&lt;br /&gt;
One of the oldest of these software packages was CruiseControll. Release in March, 2001, this software has been iterated upon for many years.&lt;br /&gt;
&lt;br /&gt;
Another early riser in the field was Hudson. Created at Sun Micro-systems, it was released under the MIT License, so it was free (as in speech). It became popular as an open source alternative to Cruise Control. When Sun Microsystems was sold to Oracle, the creates forked the project to keep it “free”, creating the Jenkins.&lt;br /&gt;
&lt;br /&gt;
Since that time, the number of products have become widespread, touting such features as cloud integration, integration with different source control, and a myriad of language support&lt;br /&gt;
===Benefits and Drawbacks===&lt;br /&gt;
Proponents state that the bugs are caught sooner, following the “Fail faster” paradigm in software engineering. Because it is strongly built on automation, proponents state that continuous integration will reduce repetitive processes that will slow down the code. &amp;lt;ref name=&amp;quot;P.Duvall&amp;quot;/&amp;gt; &amp;lt;ref name=&amp;quot;M.Fowler&amp;quot;&amp;gt;M. Fowler. (01 May 2006). Continuous Integration. Available: http://martinfowler.com/articles/continuousIntegration.html&amp;lt;/ref&amp;gt; However, the most powerful result of the process is that it maintains an up-to-date “clean” node of the software. This software can usually be packaged into a release with little additional effort. This provides risk mitigation by having a partially complete product, as well as aids in bug tracking. &amp;lt;ref name=&amp;quot;P.Duvall&amp;quot;/&amp;gt;&amp;lt;ref name=&amp;quot;M.Fowler&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Skeptics state that continuous integration requires costly frameworks and framework maintenance, and gives little benefit over frequent integration. There is no unified standard on how to implement CI and thus it is hard to measure its affects. It is such a huge process and time consuming process that it is difficult to tell which parts improve and which parts do nothing to help the software development process.&amp;lt;ref name=&amp;quot;Stahl&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction to Continuose Integration Software (Pipelines)=&lt;br /&gt;
&lt;br /&gt;
There are many suggested features for continous integration software pipeline. These software piplenes could be adhoc and built in house, or externally provided. This section will cover best practices and procedures to ensure functional system builds that report no unexpected errors to the developers. Features include version control, build and test automation, as well as developer housekeeping rules that streamline the process into an  powerful software development tool.  Below are essential principles of continuous integration:&lt;br /&gt;
===Maintain a Source Repository===&lt;br /&gt;
Source code can become very complex in larger systems. Continuous integration mitigates untracked branching that developers wish to avoid. The entire code for a functional build should be on the central repository, including test cases, configuration files, and database schemas. For proper functionality, the baseline suggestion is to host the information in a source code management system like Subversion, where all developers push towards the current build.&amp;lt;ref name=&amp;quot;M.Fowler&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Automate the Build===&lt;br /&gt;
Across the numerous development platforms, there are many build scripts that are used to configure a project and in some cases using very uncommon commands. Sometimes changes to the source code file structure can cause the build scripts to change. Therefore automation can serve to reduce the possibility of incorrect configurations and simplify the entire build process.&amp;lt;ref name=&amp;quot;P.Duvall&amp;quot;/&amp;gt; Automated build systems are standard in a number of systems . Java developers created Ant, Unix users configure with make, .NET developers prominently use MSBuild, and Ruby has the rake command that automates configuration, build, and database migration.&lt;br /&gt;
&lt;br /&gt;
It is imperative that these builds include all source code committed to the repository.&amp;lt;ref name=&amp;quot;P.Duvall&amp;quot;/&amp;gt; This means that introducing a new machine should only require downloading the project source and instructing a single command to have a fully functional application or executable.&lt;br /&gt;
&lt;br /&gt;
===Make Your Build Self-Testing===&lt;br /&gt;
Extreme Programming(XP) and Test Driven Development(TDD) show that self-testing code is very valuable in catching the bugs that sometimes slip through regression test coverage. In continuous integration pipelines, these development methodologies aren't paramount to an effective system. The significance is in having having the ability to build test code that covers a majority of the project by issuing issuing a single command.&amp;lt;ref name=&amp;quot;M.Fowler&amp;quot;/&amp;gt; Since this procedure is called after a clean commit, a resulting failure in the test code build should result in a failed project build as well. Essentially,  this automatic testing procedure gives developers confidence in functional project releases. &lt;br /&gt;
===All Contributors Commit To the Mainline Every Day===&lt;br /&gt;
Frequent communication is a major facet of continuous integration. Each day developers follow a series of operations to submit successful repository changes:&lt;br /&gt;
*Retrieve and update the trunk or mainline code&lt;br /&gt;
*Fix any conflicts as they merge their commit to the trunk&lt;br /&gt;
*Pass automatic build in testing and release&lt;br /&gt;
Once the commit is established on the trunk, other developers can follow the same procedure to validate their contributions while the version control system provided another form of error checking in file inconsistencies. Continuous integration requires this quick and constant communication so that any code conflicts can be found and removed in a fast manner.&amp;lt;ref name=&amp;quot;P.Duvall&amp;quot;/&amp;gt; When an error is detected in running code rather than compilation, the system of continuous commits reduces the search time for repository changes that caused the system to break. &lt;br /&gt;
===Every Commit Should Build the Mainline on an Integration Machine===&lt;br /&gt;
After every commit from a developer merging changes to the mainline, the system should execute some automated build script or a daemon to automatically configure and run the build process.&amp;lt;ref name=&amp;quot;M.Fowler&amp;quot;/&amp;gt; Each commit is only successful if the build of the main source code passes. Of course this does give each developer the responsibility of maintaining source code in good state, as their changes may introduce error to the system.&lt;br /&gt;
&lt;br /&gt;
===Keep the Build Fast===&lt;br /&gt;
Commits to the system should be frequent. The system uses quick iterations as a way to reduce the amount of bugs introduced to the code base. Continuous integration utilizes the deployment pipeline as a two staged process for committing a correct build.&amp;lt;ref name=&amp;quot;M.Fowler&amp;quot;/&amp;gt; In the first stage, the build process consists of unit testing and merging with the mainline on a localized copy of the source and a mock or nonexistent database. After the commit build stage, the developer will have a good commit sent to the server for testing on the production database and source filesystem. Building on both the production level and local versions is imperative, as it allows developers more code coverage with the ability to utilize performance testing in the build process.&lt;br /&gt;
===Test in a Clone of the Production Environment===&lt;br /&gt;
As previously noted, the mainline should be tested in a local copy before the server automated build test.&amp;lt;ref name=&amp;quot;P.Duvall&amp;quot;/&amp;gt; Since developers may operate in varied computing environments, resulting errors from updating to the mainline can be machine dependent, thus only fixable by the developer with that specific code conflict. Setting up an environment cloned as closely to the source environment as possible, promotes the ability to set up a testing environment that can relay performance testing of the build without affecting the production database. Therefore if a test fails in the mock environment, then the commit will not take effect on the mainline of the version control system.&lt;br /&gt;
===Make it Easy for Anyone to Get the Latest Executable===&lt;br /&gt;
It seems trivial to note, but all contributors, meaning developers and testers, should have access to the current build.&amp;lt;ref name=&amp;quot;P.Duvall&amp;quot;/&amp;gt;&amp;lt;ref name=&amp;quot;M.Fowler&amp;quot;/&amp;gt; Keeping multiple eyes on the development of the code base ultimately mitigates any bugs or defects that could go untracked in the build process. When a contributor sees a issue in the code, they are instinctively prompted to call attention to this mistake. Again, taking us back to the recurring moniker that the earlier conflict is found, the quicker it can be handled.&lt;br /&gt;
===Everyone can see what's happening===&lt;br /&gt;
Visibility is truly important in developing projects that have a varied number of developers, each committing numerous times daily towards a complex code base. In some cases, those developing the executable may be operating in distant locations. Continuous integration promotes accountability in version changes. Everyone working on the project should know the state of the current build as well as the author of each commit to the system.&amp;lt;ref name=&amp;quot;P.Duvall&amp;quot;/&amp;gt; With a full awareness, contributors know who to contact for relevant issues and get a deeper understanding of the code base.&lt;br /&gt;
===Automate Deployment===&lt;br /&gt;
Expounding the principle of automated build, a system operating a continuous integration platform should be structured to configure and build in various environments. Notably, the system needs environments for commit testing, secondary testing, and a production application environment. Constant file transfers and updates relies on the use of simple command scripts to establish the previously denoted build procedure in a single operation. Other than providing this time savings, the automated build process ensures that the code mainline is in a healthy functioning state before any release.&amp;lt;ref name=&amp;quot;M.Fowler&amp;quot;/&amp;gt;&lt;br /&gt;
=Platforms=&lt;br /&gt;
===Jenkins&amp;lt;ref name=&amp;quot;Jenkins&amp;quot;&amp;gt;Jenkins CI. (). Welcome to Jenkins CI! | Jenkins CI . Available: http://jenkins-ci.org/.&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Jenkins is an open source project that split from one of the earliest CI pipelines, Hudson, in 2010. As one of the longest running pipelines, it has been continuously extended, supporting many different languages, including C, C++, Java, and Python.&lt;br /&gt;
===Bamboo&amp;lt;ref name=&amp;quot;bamboo&amp;quot;&amp;gt;(). Continuous Integration &amp;amp; Build Server - Bamboo https://www.atlassian.com/software/bamboo &amp;lt;/ref&amp;gt;===&lt;br /&gt;
Bamboo is proprietary build server. Built by the same company that made One of its unique feature is that is can expose the service on the cloud rather than having the developers push it themselves. It also professesses being able to be integrated with Jira, an issue tracking software.&lt;br /&gt;
===ThoughtWorks Go&amp;lt;ref name=&amp;quot;thought&amp;quot;&amp;gt;(2014, September 18). Continuous Integration | ThoughtWorks [Online]. Available: http://www.thoughtworks.com/continuous-integration.&amp;lt;/ref&amp;gt;===&lt;br /&gt;
 &lt;br /&gt;
Thoughtworks Go highlights continuous integration as a key component of an expanded production mechanism that the creators Go envision as concept called Continuous Delivery. These CD platforms are extremely useful for managing code releases in large organizations. The service of helps promote lean and dynamic low-risk releases that streamline the ability to automate development and test that always ensures completely functional deployments.&lt;br /&gt;
  &lt;br /&gt;
Software is available on multiple development operating systems including Windows, Mac OS X, popular Linux distributions, Solaris, and Package OS. &lt;br /&gt;
&lt;br /&gt;
===Travis-ci&amp;lt;ref name=&amp;quot;travis&amp;quot;&amp;gt;(2014, September 17). Travis CI: Getting started [Online]. Available: http://docs.travis-ci.com/user/getting-started/.&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Travis is a hosted and distributed continuous integration service. As it’s mainly suggested for closed projects, the service is integrated with GitHub to utilizes the version control framework for determining builds.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
===References to Continuous Integration===&lt;br /&gt;
*http://en.wikipedia.org/wiki/Continuous_integration&lt;br /&gt;
*http://www.methodsandtools.com/archive/archive.php?id=121&lt;br /&gt;
*http://en.wikipedia.org/wiki/Comparison_of_continuous_integration_software&lt;br /&gt;
*http://www.martinfowler.com/articles/continuousIntegration.html&lt;br /&gt;
*http://ieeexplore.ieee.org.prox.lib.ncsu.edu/stamp/stamp.jsp?tp=&amp;amp;arnumber=6802994&lt;br /&gt;
&lt;br /&gt;
===References to Specific Pipelines===&lt;br /&gt;
*http://hudson-ci.org/&lt;br /&gt;
*https://travis-ci.com/&lt;br /&gt;
*http://jenkins-ci.org/&lt;br /&gt;
*http://www.thoughtworks.com/products/go-continuous-delivery&lt;br /&gt;
*https://www.atlassian.com/software/bamboo&lt;br /&gt;
*http://integrity.github.io/&lt;br /&gt;
*http://stridercd.com/&lt;br /&gt;
*http://en.wikipedia.org/wiki/Team_Foundation_Server&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Njclimer</name></author>
	</entry>
</feed>