CSC/ECE 517 Spring 2014/oss E1414 st: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
 
(55 intermediate revisions by 3 users not shown)
Line 2: Line 2:
''Please be advised that we do not have deployment link, since our work are all back-end tests''
''Please be advised that we do not have deployment link, since our work are all back-end tests''
__TOC__
__TOC__
==Classes==
== Introduction ==
=== app/controllers/teams_controller.rb ===
This project will be an extension of our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2014/oss_E1406_st previous E1406 project]. For the previous project, we did some refactoring and testing for the controllers related to teams. This time, we are going to reuse most of our test environment, but extend the tests to other team-related classes. We also expect to examine and report the code that may require refactoring.
== Test Environment ==
teams_controller contains functionalities for team management for instructor/TA accounts.  
 
Instructor/TA can:
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]
* view current teams
;Sample data : Fixtures (under /test/fixtures)
* create new teams
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]
* import/export teams
 
* delete all teams/delete specified team
== Background ==
* copy existing teams from a course down to an assignment(inherit)
* update team's information


=== app/controllers/student_team_controller.rb ===
=== teams_users.rb & teams_users_controller.rb===
The student_team_controller support team management for student account.
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.
student can
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.
* create team
=== teams_participant.rb & teams_participant_controller.rb===
* view current team (including team invitations received and sent)
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.
* advertise for their team
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.
* remove the advertise for their team
=== advertise_for_partner.rb ===
* leave the team
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful.
* It seems like there has been a functional test, but the class name and set up looks like the other class. It may be necessary to re-run, and even re-write the test
=== team.rb ===
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation
* There exists a unit test for team model, but there are only two test cases. Also, some of the methods under team.rb are duplicated, or either marked as not working. Further research may be required before starting to do the test.


==Classes==
=== app/models/teams_users.rb===
=== app/models/teams_users.rb===
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.
Line 35: Line 38:
* remove all members belonging to an item
* remove all members belonging to an item


== Background ==
=== app/controllers/advertise_for_partners_controller.rb ===
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.
 
A student can:
* create a new advertisement for the team
* edit the advertisement content
* remove advertisement record from the table for the specific team
 
=== app/models/teams_participant.rb===
The teams_participant.rb is a model belonging to both users and teams. It is used when a team participant is created, listed or deleted.
 
=== app/controllers/teams_participant_controller.rb===
The teams_participant_controller support team participants management so the team participant:
* get a participant name by inputting part of the name
* list team participants of a team
* add a participant to a team
* remove a selected team participant from a team
* remove all team participants belonging to an item
 
=== app/models/team.rb ===
The “team” object represents a team that consists students who are either participants of course or assignment.
a team will response to the request on:


=== teams_users.rb & teams_users_controller.rb===
;get_participants : get participant in the team
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.
;delete : delete a team member in the team
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.
;get_node_type : will return “TeamNode”
;get_author_name : will return team’s name
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)
;get_possible_team_members(name) : find a team member by name
;has_user(user : find a team member by user object
;add_member(user, assignment_id) : add a user to an assignment team
;copy_members(new_team) : copy current member in the team to the new team
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1)
;import_team_members(starting_index, row) : import user from specific index of users and length


== Setup ==
== Setup ==
Line 46: Line 82:
Fixtures needed for corresponding classes are listed below
Fixtures needed for corresponding classes are listed below


=== app/models/teams_users.rb & app/controllers/teams_users_controller.rb ===
=== fixtures use in common ===
* Teams.yml
* teams.yml
* Usres.yml  
* users.yml
* Teams_Uers.yml
* teams_users.yml
* Courses.yml
* courses.yml
* Assignments.yml
* assignments.yml
 
=== teams_participant.rb & teams_participant_controller.rb ===
Besides the above fixtures, we also need the following fixrure
* teams_participant.yml
 
=== teams.rb ===
* teams_participant.yml
* join_team_requests.yml
* participants.yml
* nodes.yml
 
== Use Case Diagram ==
 
=== teams_participant_controller.rb ===
[[File:New.jpg]]
 
=== advertise_for_partner_controller.rb ===
[[File:Usecase_E1414_advertise.jpg]]


== Testing Scenarios ==
== Testing Scenarios ==


=== app/models/teams_users.rb & app/controllers/teams_users_controller.rb ===
=== teams_users_controller.rb ===
[[File:TeamUsersStory.png]]
[[File:TeamUsersStory.png]]


== Deployment ==
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.
Please note that all of our work will be under the /test folder, which means they will not show any change on the view.  
 
To see the result of tests, run
* Auto_complete_for_user_name:
rake test TEST=test/functional/student_team_controller.rb
** Test auto_complete_for_user_name with valid user name
and
** Test auto_complete_for_user_name with invalid user name
rake test TEST=test/functional/teams_controller
 
* List
** Test List with valid team id
** Test List with invalid team id
 
* New
** Test New with valid team id
** Test New with invalid team id
 
* Create
** Test Create with valid team id
*** Test Create with valid user id and maximum member number is not reached
*** Test Create with invalid user id and maximum member number is not reached
*** Test Create with valid user id and maximum member number is reached
*** Test Create with invalid user id and maximum member number is reached
** Test Create with invalid team id
*** Test Create with valid user id and maximum member number is not reached
*** Test Create with invalid user id and maximum member number is not reached
*** Test Create with valid user id and maximum member number is reached
*** Test Create with invalid user id and maximum member number is reached
 
* Delete
** Test Delete with valid user id
** Test Delete with invalid user id
 
* Delete_select
** Test Delete_select with valid item id
** Test Delete_select with invalid item id
 
=== teams_users.rb ===
 
* Delete
** Test Delete to check if it could delete the team node and the team user
 
* Remove_team
** Test Remove_team with valid user_id and valid team_id
** Test Remove_team with valid user_id and invalid team_id
** Test Remove_team with invalid user_id and valid team_id
** Test Remove_team with invalid user_id and invalid team_id
 
* Is_team_empty
** Test Is_team_empty with empty team
** Test Is_team_empty with non-empty team
 
* Add_member_to_invited_team
** Test Add_member_to_invited_team with valid user_id and valid team_id
** Test Add_member_to_invited_team with valid user_id and invalid team_id
** Test Add_member_to_invited_team with invalid user_id and valid team_id
** Test Add_member_to_invited_team with invalid user_id and invalid team_id
 
=== teams_participant.rb ===
 
* delete
** Test delete to check if team node and the team user decreases by one
 
=== teams_participant_controller.rb ===
* auto_complete_for_user_name
** Test auto_complete_for_user_name with invalid user name
* list
** Test list with invalid team id
* new
** Test new with invalid team id
* create
** Test create with invalid team id
** Test create to check if the number of participant increases by one
** Test create with invalid user id and maximum member number is not reached
** Test create with valid user id and maximum member number is reached
** Test create with invalid user id and maximum member number is not reached
* delete
** Test delete with invalid id
** Test delete to check the number of participant decreases
* delete_select
** Test delete_select with invalid item id
** Test delete_select to check if the number of participant decreases by one
 
=== advertise_for_partner_controller.rb ===
* remove
** test remove with valid user id
** test remove with invalid user id
 
* create
** test create with valid user id
** test create with invalid user id
 
* update
** test update with invalid id
** test update success
** test update fail (should remain the same)
 
* edit
** test edit
=== team.rb ===
* get participants
** test get participants
 
* delete
** test delete with team node
** test delete without team node
 
* get_node_type
** test get node type
 
* get_author_name
** test author name
 
* generate_team_name()
** test generate team name from zero
** test generate team name from one
 
* get_possible_team_members(name)
** test get possible team members by exact name
** test get possible team members by similar name
** test get possible team members by name in other team
 
* has_user(user)
** test has user with valid user
** test has user with invalid user
 
* add_member(user, assignment_id)
** test add member with valid user
** test add member already in team
** test add member without assignment id
** test add member when max team size reached
 
* copy_members(new_team)
** test copy members to empty new team
** test copy members to nonempty new team
** test copy members with no member in current team
 
* create_node_object(name, parent_id)
** ‘’there is a TODO on this method indicated that this is not working’’
 
* check_for_exisiting(parent, name, team_type)
** test check for exisiting with exisited name
** test check for exisiting with nonexisted name
 
* delete_all_by_parent(parent)
** test delete with valid parents
** test delete with invalid parents
 
* randomize_all_by_parent(parent, team_type, team_size)
** test randomize all by parent with exact number
** test randomize all by parent without enough people
** test randomize all by parent with remainder


running the whole test suite with <code>rake test</code> is not recommended, as the schema change overtime has broke some of the previous tests.
* generate_team_name(teamnameprefix)
** test generate prefix team name with valid name
** test generate prefix team name with duplicated name


==Testing==
* import_team_members(starting_index, row)
** test import team members with valid index and row
** test import team members with invalid index and row


;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]
== Possible Refacotring ==
;Sample data : Fixtures (under /test/fixtures)
=== advertise_for_team_controller.rb ===
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]
* ''update'' should be ''edit'' (this is mentioned in the comments of code)
;Total Number of Tests : 37
* ''edit'' should be reexamined since it is only retrieving the team object
;Previous Coverage : 22.32%
* ''new'' is empty, so it should be removed
;Current Coverage : 24.08%


===Testing Scenarios===
=== team.rb ===
====student_team_controller====
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.
Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller
* View student team (GET #view)
* Edit team (GET #edit)
* Create team with valid name (POST #create)
* Create team with name in use (POST #create)
* Update valid team name (POST #update)
* Update team name in use (POST #update)
* Update with current team name (POST #update)
* Advertise (GET #advertise)
''This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. ''
The <code>advertise</code> method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name.  


* Remove advertisement (GET #remove_advertisement )
== Running Tests ==
The <code>remove_advertisement</code> method was previously named remove, but renamed to avoid ambiguity
Please note that all of our work will be under the /test folder, which means they will not show any change on the view.  
This method is never called as well, but it is functional as it do not require any template.
To see the result of tests, run
* Leave student team (GET #leave)
rake test TEST=test/unit/<filename> # for models
''This is currently commented out in the committed code, because it will raise error every time when called.''
and
It seems like problem happens on
rake test TEST=test/functional/<filename> # for controllers
  line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first
  line 97: if other_members.length == 0
This will raise error due to the calling length of other_members, which is a single object but not an array.
Also, the related record seems to be remain undeleted in the database.


====teams_controller====
running the whole test suite with <code>rake test</code> is not recommended, as the schema change overtime has broke some of the previous tests.
Current test cases are as following.
* Create team should increase the number of teams by 1(GET #create)
* Create team should increase the number of team nodes by 1(GET #create)
* Create team with existing name (POST #create)
* Create team should redirect to list assignments (POST #create)
* Delete all teams (GET #delete_all)
* Delete all teams should redirect to list (GET #delete_all)
* List should receive assignment (GET #list)
* List should receive course (GET #list)
* New should assign parent (GET #new)
* Update team should redirect (POST #update)
* Update team should have validate name (POST #update)
* Edit team should have time (POST #edit)
* Delete team should redirect (POST #delete)
* Delete team should decrease the number of teams by 1(GET #delete)
* Delete team should decrease the number of team nodes by 1(GET #delete)
* Inherit team should redirect (POST #inherit)
* Bequeath team should redirect (POST #bequeath)
The methods in the following are ignored in testing since they are never used in current codes.
* create_teams_view
* create_teams


==Sample Test Code==
==Sample Test Code==
We show two pieces of test code for two controllers to explain how our test works
We show two pieces of test code for two controllers from our previous work to explain how our test works


     test "create_student team with name in use" do
     test "create_student team with name in use" do
Line 146: Line 310:
As we can see from the code, when we want to use <code>post</code> or <code>get</code>, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.
As we can see from the code, when we want to use <code>post</code> or <code>get</code>, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.


When we run the command <code>rake test TEST=test/functional/your_test_file.rb</code>, you will see if the test is passed or not.
When we run the command <code>rake test TEST=test/functional/your_test_file.rb</code>, you will see if the test is passed or not.
 
==Result==
 
 
 
==Future Works==
===student_team_controller===
''Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late''
 
There are several error raised from ''leave'' method need to be fixed, as mentioned above. Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team.
 
Also, methods that seems like not being used, such as <code>advertise</code> and <code>remove_advertisement</code> may need to be double checked and see if they are redundant.
===teams_controller===
The method <code>create_teams_view</code> does not be used at all. So it is safe to delete it.
 
The method <code>create_teams</code> calls the method <code>randomize_all_by_parent</code>, which is not correct. The developer may want to fix these bugs.
 
It's possible that we can write more testing cases if we improve the fixture.


==References==
==References==

Latest revision as of 00:41, 10 April 2014

E1414: Testing classes related to teams

Please be advised that we do not have deployment link, since our work are all back-end tests

Introduction

This project will be an extension of our previous E1406 project. For the previous project, we did some refactoring and testing for the controllers related to teams. This time, we are going to reuse most of our test environment, but extend the tests to other team-related classes. We also expect to examine and report the code that may require refactoring.

Test Environment

Framework
Rails default test framework
Sample data
Fixtures (under /test/fixtures)
Coverage tool
SimpleCov

Background

teams_users.rb & teams_users_controller.rb

  • Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.
  • There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.

teams_participant.rb & teams_participant_controller.rb

  • teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.
  • There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.

  • This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful.
  • It seems like there has been a functional test, but the class name and set up looks like the other class. It may be necessary to re-run, and even re-write the test

team.rb

  • This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation
  • There exists a unit test for team model, but there are only two test cases. Also, some of the methods under team.rb are duplicated, or either marked as not working. Further research may be required before starting to do the test.

Classes

app/models/teams_users.rb

The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.

app/controllers/teams_users_controller.rb

The teams_users_controller support team member management for instructor/TA accounts Instruction/TA can:

  • get a user name by inputting part of the name
  • list team members of a team
  • add a user to a team
  • remove a team member from a team
  • remove all members belonging to an item

app/controllers/advertise_for_partners_controller.rb

The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.

A student can:

  • create a new advertisement for the team
  • edit the advertisement content
  • remove advertisement record from the table for the specific team

app/models/teams_participant.rb

The teams_participant.rb is a model belonging to both users and teams. It is used when a team participant is created, listed or deleted.

app/controllers/teams_participant_controller.rb

The teams_participant_controller support team participants management so the team participant:

  • get a participant name by inputting part of the name
  • list team participants of a team
  • add a participant to a team
  • remove a selected team participant from a team
  • remove all team participants belonging to an item

app/models/team.rb

The “team” object represents a team that consists students who are either participants of course or assignment. a team will response to the request on:

get_participants
get participant in the team
delete
delete a team member in the team
get_node_type
will return “TeamNode”
get_author_name
will return team’s name
generate_team_name()
serialize the automatically generated team name (e.g. team 1, team 2, etc.)
get_possible_team_members(name)
find a team member by name
has_user(user
find a team member by user object
add_member(user, assignment_id)
add a user to an assignment team
copy_members(new_team)
copy current member in the team to the new team
create_node_object(name, parent_id)
‘’there is a TODO on this method indicated that this is not working’’
check_for_exisiting(parent, name, team_type)
check if the team name under the same assignment or course is in use.
Delete_all_by_parent(parent)
delete all teams under the same course/assignment
Randomize_all_by_parent(parent, team_type, team_size)
randomly assign team members
generate_team_name(teamnameprefix)
generate team name with prefix (e.g. prefix_Team1)
import_team_members(starting_index, row)
import user from specific index of users and length

Setup

To set up our testing for the models and controllers, we need some fixtures to support. Fixtures needed for corresponding classes are listed below

fixtures use in common

  • teams.yml
  • users.yml
  • teams_users.yml
  • courses.yml
  • assignments.yml

teams_participant.rb & teams_participant_controller.rb

Besides the above fixtures, we also need the following fixrure

  • teams_participant.yml

teams.rb

  • teams_participant.yml
  • join_team_requests.yml
  • participants.yml
  • nodes.yml

Use Case Diagram

teams_participant_controller.rb

Testing Scenarios

teams_users_controller.rb

Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.

  • Auto_complete_for_user_name:
    • Test auto_complete_for_user_name with valid user name
    • Test auto_complete_for_user_name with invalid user name
  • List
    • Test List with valid team id
    • Test List with invalid team id
  • New
    • Test New with valid team id
    • Test New with invalid team id
  • Create
    • Test Create with valid team id
      • Test Create with valid user id and maximum member number is not reached
      • Test Create with invalid user id and maximum member number is not reached
      • Test Create with valid user id and maximum member number is reached
      • Test Create with invalid user id and maximum member number is reached
    • Test Create with invalid team id
      • Test Create with valid user id and maximum member number is not reached
      • Test Create with invalid user id and maximum member number is not reached
      • Test Create with valid user id and maximum member number is reached
      • Test Create with invalid user id and maximum member number is reached
  • Delete
    • Test Delete with valid user id
    • Test Delete with invalid user id
  • Delete_select
    • Test Delete_select with valid item id
    • Test Delete_select with invalid item id

teams_users.rb

  • Delete
    • Test Delete to check if it could delete the team node and the team user
  • Remove_team
    • Test Remove_team with valid user_id and valid team_id
    • Test Remove_team with valid user_id and invalid team_id
    • Test Remove_team with invalid user_id and valid team_id
    • Test Remove_team with invalid user_id and invalid team_id
  • Is_team_empty
    • Test Is_team_empty with empty team
    • Test Is_team_empty with non-empty team
  • Add_member_to_invited_team
    • Test Add_member_to_invited_team with valid user_id and valid team_id
    • Test Add_member_to_invited_team with valid user_id and invalid team_id
    • Test Add_member_to_invited_team with invalid user_id and valid team_id
    • Test Add_member_to_invited_team with invalid user_id and invalid team_id

teams_participant.rb

  • delete
    • Test delete to check if team node and the team user decreases by one

teams_participant_controller.rb

  • auto_complete_for_user_name
    • Test auto_complete_for_user_name with invalid user name
  • list
    • Test list with invalid team id
  • new
    • Test new with invalid team id
  • create
    • Test create with invalid team id
    • Test create to check if the number of participant increases by one
    • Test create with invalid user id and maximum member number is not reached
    • Test create with valid user id and maximum member number is reached
    • Test create with invalid user id and maximum member number is not reached
  • delete
    • Test delete with invalid id
    • Test delete to check the number of participant decreases
  • delete_select
    • Test delete_select with invalid item id
    • Test delete_select to check if the number of participant decreases by one

  • remove
    • test remove with valid user id
    • test remove with invalid user id
  • create
    • test create with valid user id
    • test create with invalid user id
  • update
    • test update with invalid id
    • test update success
    • test update fail (should remain the same)
  • edit
    • test edit

team.rb

  • get participants
    • test get participants
  • delete
    • test delete with team node
    • test delete without team node
  • get_node_type
    • test get node type
  • get_author_name
    • test author name
  • generate_team_name()
    • test generate team name from zero
    • test generate team name from one
  • get_possible_team_members(name)
    • test get possible team members by exact name
    • test get possible team members by similar name
    • test get possible team members by name in other team
  • has_user(user)
    • test has user with valid user
    • test has user with invalid user
  • add_member(user, assignment_id)
    • test add member with valid user
    • test add member already in team
    • test add member without assignment id
    • test add member when max team size reached
  • copy_members(new_team)
    • test copy members to empty new team
    • test copy members to nonempty new team
    • test copy members with no member in current team
  • create_node_object(name, parent_id)
    • ‘’there is a TODO on this method indicated that this is not working’’
  • check_for_exisiting(parent, name, team_type)
    • test check for exisiting with exisited name
    • test check for exisiting with nonexisted name
  • delete_all_by_parent(parent)
    • test delete with valid parents
    • test delete with invalid parents
  • randomize_all_by_parent(parent, team_type, team_size)
    • test randomize all by parent with exact number
    • test randomize all by parent without enough people
    • test randomize all by parent with remainder
  • generate_team_name(teamnameprefix)
    • test generate prefix team name with valid name
    • test generate prefix team name with duplicated name
  • import_team_members(starting_index, row)
    • test import team members with valid index and row
    • test import team members with invalid index and row

Possible Refacotring

  • update should be edit (this is mentioned in the comments of code)
  • edit should be reexamined since it is only retrieving the team object
  • new is empty, so it should be removed

team.rb

  • There are two def get_participants, the second one overwritten the first one, so the first one should be deleted.

Running Tests

Please note that all of our work will be under the /test folder, which means they will not show any change on the view. To see the result of tests, run

rake test TEST=test/unit/<filename> # for models

and

rake test TEST=test/functional/<filename> # for controllers

running the whole test suite with rake test is not recommended, as the schema change overtime has broke some of the previous tests.

Sample Test Code

We show two pieces of test code for two controllers from our previous work to explain how our test works

   test "create_student team with name in use" do
       sessionVars = session_for(users(:student8))
       post(:create, {'team' => { 'name' => 'IntelligentTeam2'}, 'id' => participants(:par21).id, "commit" => "Create Team"}, sessionVars, nil)
       assert_equal 'Team name is already in use.', flash[:notice]
       assert_redirected_to :controller => 'student_team', :action => 'view', :id => participants(:par21).id
   end
   test "create_should_increase_number_of_teams_course" do
       sessionVars = session_for(users(:instructor1))
       sessionVars[:team_type] = "Course"
       assert_difference 'Team.count' do
         get :create, {'id' => @testCourse,'team' => {'name' => "Random"}},sessionVars
       end
   end

The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.

As we can see from the code, when we want to use post or get, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.

When we run the command rake test TEST=test/functional/your_test_file.rb, you will see if the test is passed or not.

References

<references/>