<?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=Yhong3</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=Yhong3"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Yhong3"/>
	<updated>2026-09-30T15:26:26Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84762</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84762"/>
		<updated>2014-04-25T20:12:58Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Summary of Class Issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
=== Statistics ===&lt;br /&gt;
''Please note that the coverage generate by SimpleCov may be lower than expect due to the added fixtures.''&lt;br /&gt;
&lt;br /&gt;
; Overall (set of 6 tests) : 105 tests, 156 assertions, 2 failures, 3060 / 13457 LOC (22.74%) covered.&lt;br /&gt;
; Unit tests : 18 tests, 18 assertions, 0 failures&lt;br /&gt;
; Functional tests : 87 tests, 138 assertions, 2 failures&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
Run &lt;br /&gt;
 rake test:prepare&lt;br /&gt;
before each action.&lt;br /&gt;
To run unit tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/unit/team_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
To run functional tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/advertise_for_partner_controller_test.rb test/functional/teams_users_controller_test.rb&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Found Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
==== team.rb ====&lt;br /&gt;
* def add_member(user, assignment_id) allow nil to be passed&lt;br /&gt;
** rails always raise runtime error when nil is passed. [[#unit/team_test.rb|Test: &amp;quot;add member for course should create teams user&amp;quot; ]]&lt;br /&gt;
* def randomize_all_by_parent passing wrong arguments&lt;br /&gt;
** The code is passing wrong arguments in line 124 for add_member, there should be 2 arguments. [[#unit/team_test.rb|Test: &amp;quot;randomize_all_by_parent&amp;quot; ]]&lt;br /&gt;
* def import_team_members passing wrong arguments&lt;br /&gt;
** it is calling add_member and passing nil for assignment_id, which will make rails raise error.[[#unit/team_test.rb|Test: &amp;quot;import team members successfully&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment_id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84761</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84761"/>
		<updated>2014-04-25T20:11:11Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* E1414: Testing classes related to teams */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
=== Statistics ===&lt;br /&gt;
''Please note that the coverage generate by SimpleCov may be lower than expect due to the added fixtures.''&lt;br /&gt;
&lt;br /&gt;
; Overall (set of 6 tests) : 105 tests, 156 assertions, 2 failures, 3060 / 13457 LOC (22.74%) covered.&lt;br /&gt;
; Unit tests : 18 tests, 18 assertions, 0 failures&lt;br /&gt;
; Functional tests : 87 tests, 138 assertions, 2 failures&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
Run &lt;br /&gt;
 rake test:prepare&lt;br /&gt;
before each action.&lt;br /&gt;
To run unit tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/unit/team_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
To run functional tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/advertise_for_partner_controller_test.rb test/functional/teams_users_controller_test.rb&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Class Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
==== team.rb ====&lt;br /&gt;
* def add_member(user, assignment_id) allow nil to be passed&lt;br /&gt;
** rails always raise runtime error when nil is passed. [[#unit/team_test.rb|Test: &amp;quot;add member for course should create teams user&amp;quot; ]]&lt;br /&gt;
* def randomize_all_by_parent passing wrong arguments&lt;br /&gt;
** The code is passing wrong arguments in line 124 for add_member, there should be 2 arguments. [[#unit/team_test.rb|Test: &amp;quot;randomize_all_by_parent&amp;quot; ]]&lt;br /&gt;
* def import_team_members passing wrong arguments&lt;br /&gt;
** it is calling add_member and passing nil for assignment_id, which will make rails raise error.[[#unit/team_test.rb|Test: &amp;quot;import team members successfully&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment_id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84760</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84760"/>
		<updated>2014-04-25T20:10:21Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
Run &lt;br /&gt;
 rake test:prepare&lt;br /&gt;
before each action.&lt;br /&gt;
To run unit tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/unit/team_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
To run functional tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/advertise_for_partner_controller_test.rb test/functional/teams_users_controller_test.rb&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
=== Statistics ===&lt;br /&gt;
''Please note that the coverage generate by SimpleCov may be lower than expect due to the added fixtures.''&lt;br /&gt;
&lt;br /&gt;
; Overall (set of 6 tests) : 105 tests, 156 assertions, 2 failures, 3060 / 13457 LOC (22.74%) covered.&lt;br /&gt;
; Unit tests : 18 tests, 18 assertions, 0 failures&lt;br /&gt;
; Functional tests : 87 tests, 138 assertions, 2 failures&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Class Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
==== team.rb ====&lt;br /&gt;
* def add_member(user, assignment_id) allow nil to be passed&lt;br /&gt;
** rails always raise runtime error when nil is passed. [[#unit/team_test.rb|Test: &amp;quot;add member for course should create teams user&amp;quot; ]]&lt;br /&gt;
* def randomize_all_by_parent passing wrong arguments&lt;br /&gt;
** The code is passing wrong arguments in line 124 for add_member, there should be 2 arguments. [[#unit/team_test.rb|Test: &amp;quot;randomize_all_by_parent&amp;quot; ]]&lt;br /&gt;
* def import_team_members passing wrong arguments&lt;br /&gt;
** it is calling add_member and passing nil for assignment_id, which will make rails raise error.[[#unit/team_test.rb|Test: &amp;quot;import team members successfully&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment_id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84759</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84759"/>
		<updated>2014-04-25T20:10:11Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Running Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
=== Statistics ===&lt;br /&gt;
''Please note that the coverage generate by SimpleCov may be lower than expect due to the added fixtures.''&lt;br /&gt;
&lt;br /&gt;
; Overall (set of 6 tests) : 105 tests, 156 assertions, 2 failures, 3060 / 13457 LOC (22.74%) covered.&lt;br /&gt;
; Unit tests : 18 tests, 18 assertions, 0 failures&lt;br /&gt;
; Functional tests : 87 tests, 138 assertions, 2 failures&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Class Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
==== team.rb ====&lt;br /&gt;
* def add_member(user, assignment_id) allow nil to be passed&lt;br /&gt;
** rails always raise runtime error when nil is passed. [[#unit/team_test.rb|Test: &amp;quot;add member for course should create teams user&amp;quot; ]]&lt;br /&gt;
* def randomize_all_by_parent passing wrong arguments&lt;br /&gt;
** The code is passing wrong arguments in line 124 for add_member, there should be 2 arguments. [[#unit/team_test.rb|Test: &amp;quot;randomize_all_by_parent&amp;quot; ]]&lt;br /&gt;
* def import_team_members passing wrong arguments&lt;br /&gt;
** it is calling add_member and passing nil for assignment_id, which will make rails raise error.[[#unit/team_test.rb|Test: &amp;quot;import team members successfully&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment_id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84758</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84758"/>
		<updated>2014-04-25T20:09:53Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Running Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
=== Statistics ===&lt;br /&gt;
''Please note that the coverage generate by SimpleCov may be lower than expect due to the added fixtures.''&lt;br /&gt;
&lt;br /&gt;
; Overall (set of 6 tests) : 105 tests, 156 assertions, 2 failures, 3060 / 13457 LOC (22.74%) covered.&lt;br /&gt;
; Unit tests : 18 tests, 18 assertions, 0 failures&lt;br /&gt;
; Functional tests : 87 tests, 138 assertions, 2 failures&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Class Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
==== team.rb ====&lt;br /&gt;
* def add_member(user, assignment_id) allow nil to be passed&lt;br /&gt;
** rails always raise runtime error when nil is passed. [[#unit/team_test.rb|Test: &amp;quot;add member for course should create teams user&amp;quot; ]]&lt;br /&gt;
* def randomize_all_by_parent passing wrong arguments&lt;br /&gt;
** The code is passing wrong arguments in line 124 for add_member, there should be 2 arguments. [[#unit/team_test.rb|Test: &amp;quot;randomize_all_by_parent&amp;quot; ]]&lt;br /&gt;
* def import_team_members passing wrong arguments&lt;br /&gt;
** it is calling add_member and passing nil for assignment_id, which will make rails raise error.[[#unit/team_test.rb|Test: &amp;quot;import team members successfully&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment_id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
Run &lt;br /&gt;
 rake test:prepare&lt;br /&gt;
before each action.&lt;br /&gt;
To run unit tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/unit/team_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
To run functional tests&lt;br /&gt;
 bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/advertise_for_partner_controller_test.rb test/functional/teams_users_controller_test.rb&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84757</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84757"/>
		<updated>2014-04-25T20:08:13Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Test Environment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
=== Statistics ===&lt;br /&gt;
''Please note that the coverage generate by SimpleCov may be lower than expect due to the added fixtures.''&lt;br /&gt;
&lt;br /&gt;
; Overall (set of 6 tests) : 105 tests, 156 assertions, 2 failures, 3060 / 13457 LOC (22.74%) covered.&lt;br /&gt;
; Unit tests : 18 tests, 18 assertions, 0 failures&lt;br /&gt;
; Functional tests : 87 tests, 138 assertions, 2 failures&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Class Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
==== team.rb ====&lt;br /&gt;
* def add_member(user, assignment_id) allow nil to be passed&lt;br /&gt;
** rails always raise runtime error when nil is passed. [[#unit/team_test.rb|Test: &amp;quot;add member for course should create teams user&amp;quot; ]]&lt;br /&gt;
* def randomize_all_by_parent passing wrong arguments&lt;br /&gt;
** The code is passing wrong arguments in line 124 for add_member, there should be 2 arguments. [[#unit/team_test.rb|Test: &amp;quot;randomize_all_by_parent&amp;quot; ]]&lt;br /&gt;
* def import_team_members passing wrong arguments&lt;br /&gt;
** it is calling add_member and passing nil for assignment_id, which will make rails raise error.[[#unit/team_test.rb|Test: &amp;quot;import team members successfully&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment_id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84756</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84756"/>
		<updated>2014-04-25T19:50:33Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* unit/team_test.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Class Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
==== team.rb ====&lt;br /&gt;
* def add_member(user, assignment_id) allow nil to be passed&lt;br /&gt;
** rails always raise runtime error when nil is passed. [[#unit/team_test.rb|Test: &amp;quot;add member for course should create teams user&amp;quot; ]]&lt;br /&gt;
* def randomize_all_by_parent passing wrong arguments&lt;br /&gt;
** The code is passing wrong arguments in line 124 for add_member, there should be 2 arguments. [[#unit/team_test.rb|Test: &amp;quot;randomize_all_by_parent&amp;quot; ]]&lt;br /&gt;
* def import_team_members passing wrong arguments&lt;br /&gt;
** it is calling add_member and passing nil for assignment_id, which will make rails raise error.[[#unit/team_test.rb|Test: &amp;quot;import team members successfully&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment_id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84755</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84755"/>
		<updated>2014-04-25T19:50:15Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Possible Bugs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Class Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
==== team.rb ====&lt;br /&gt;
* def add_member(user, assignment_id) allow nil to be passed&lt;br /&gt;
** rails always raise runtime error when nil is passed. [[#unit/team_test.rb|Test: &amp;quot;add member for course should create teams user&amp;quot; ]]&lt;br /&gt;
* def randomize_all_by_parent passing wrong arguments&lt;br /&gt;
** The code is passing wrong arguments in line 124 for add_member, there should be 2 arguments. [[#unit/team_test.rb|Test: &amp;quot;randomize_all_by_parent&amp;quot; ]]&lt;br /&gt;
* def import_team_members passing wrong arguments&lt;br /&gt;
** it is calling add_member and passing nil for assignment_id, which will make rails raise error.[[#unit/team_test.rb|Test: &amp;quot;import team members successfully&amp;quot; ]]&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment_id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84754</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84754"/>
		<updated>2014-04-25T19:37:50Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* unit/team_test.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Class Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment_id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84753</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84753"/>
		<updated>2014-04-25T19:28:17Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Summary of Class Issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Class Issues ==&lt;br /&gt;
=== Changes made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Bugs ===&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84752</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84752"/>
		<updated>2014-04-25T19:23:11Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Summary about issues found for classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary of Class Issues ==&lt;br /&gt;
=== Change made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84751</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84751"/>
		<updated>2014-04-25T19:21:18Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Summary about change can made and changed already made */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary about issues found for classes ==&lt;br /&gt;
=== Change made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84750</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84750"/>
		<updated>2014-04-25T19:20:29Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Testing Scenarios */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary about change can made and changed already made ==&lt;br /&gt;
=== Change made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Concerns for Test Cases ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84749</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84749"/>
		<updated>2014-04-25T19:19:50Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* functional/advertise_for_partner_controller_test.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary about change can made and changed already made ==&lt;br /&gt;
=== Change made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84748</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84748"/>
		<updated>2014-04-25T19:19:39Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* advertise_for_team_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary about change can made and changed already made ==&lt;br /&gt;
=== Change made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only assigning the team object&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84747</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84747"/>
		<updated>2014-04-25T19:15:59Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* advertise_for_team_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary about change can made and changed already made ==&lt;br /&gt;
=== Change made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84746</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84746"/>
		<updated>2014-04-25T19:15:16Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Summary about change can made and changed already made */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary about change can made and changed already made ==&lt;br /&gt;
=== Change made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* def new was removed&lt;br /&gt;
** since it's empty, there is no need to keep the code there&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84745</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84745"/>
		<updated>2014-04-25T19:12:54Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* advertise_for_team_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary about change can made and changed already made ==&lt;br /&gt;
=== Change made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84744</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84744"/>
		<updated>2014-04-25T19:11:15Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Test Classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary about change can made and changed already made ==&lt;br /&gt;
=== Change made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84743</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84743"/>
		<updated>2014-04-25T19:09:15Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Changes made to original classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Summary about change can made and changed already made ==&lt;br /&gt;
=== Change made to the class===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
''Based on the discussion from the demo, the duplicated method was deleted instead of commented out''&lt;br /&gt;
* duplicated def get_participants was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 20&lt;br /&gt;
* duplicated def self.generate_team_name() was removed&lt;br /&gt;
** This is removed because the same method is defined again at line 131&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Possible Refactoring ===&lt;br /&gt;
==== team.rb ==== &lt;br /&gt;
* line 81 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 80, the method will not work.&lt;br /&gt;
&lt;br /&gt;
== Test Classes ==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84742</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84742"/>
		<updated>2014-04-25T18:58:13Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* team.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Changes made to original classes ==&lt;br /&gt;
=== team.rb === &lt;br /&gt;
* line 10 def get_participants removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 26&lt;br /&gt;
* line 38 def self.generate_team_name() removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 150&lt;br /&gt;
* line 100 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 99, the method will not work.&lt;br /&gt;
&lt;br /&gt;
== Test Classes ==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84741</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84741"/>
		<updated>2014-04-25T18:56:57Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* functional/advertise_for_partner_controller_test.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Changes made to original classes ==&lt;br /&gt;
=== team.rb === &lt;br /&gt;
* line 10 def get_participants removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 26&lt;br /&gt;
* line 38 def self.generate_team_name() removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 150&lt;br /&gt;
* line 100 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 99, the method will not work.&lt;br /&gt;
&lt;br /&gt;
== Test Classes ==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84740</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84740"/>
		<updated>2014-04-25T18:56:12Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* app/models/team.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Changes made to original classes ==&lt;br /&gt;
=== team.rb === &lt;br /&gt;
* line 10 def get_participants removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 26&lt;br /&gt;
* line 38 def self.generate_team_name() removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 150&lt;br /&gt;
* line 100 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 99, the method will not work.&lt;br /&gt;
&lt;br /&gt;
== Test Classes ==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
* test &amp;quot;test remove advertisement should set advertise_for_partner false&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should remove advertisement comments&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should redirect to view&amp;quot; do&lt;br /&gt;
* test &amp;quot;test create advertisement should set advertise_for_partner true&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should set comment for advertisement&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should redirect to view&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should show notice&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should change comment&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should redirect to view&amp;quot; do&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84739</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84739"/>
		<updated>2014-04-25T17:59:56Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Possible Refacotring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Changes made to original classes ==&lt;br /&gt;
=== team.rb === &lt;br /&gt;
* line 10 def get_participants removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 26&lt;br /&gt;
* line 38 def self.generate_team_name() removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 150&lt;br /&gt;
* line 100 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 99, the method will not work.&lt;br /&gt;
&lt;br /&gt;
== Test Classes ==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
* get_participants : get participant in the team&lt;br /&gt;
* delete : delete a team member in the team&lt;br /&gt;
* get_node_type : will return “TeamNode”&lt;br /&gt;
* get_author_name : will return team’s name&lt;br /&gt;
* generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
* get_possible_team_members(name) : find a team member by name&lt;br /&gt;
* has_user(user : find a team member by user object&lt;br /&gt;
* add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
* copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
* create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
* check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
* delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
* generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
* import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
* test &amp;quot;test remove advertisement should set advertise_for_partner false&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should remove advertisement comments&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should redirect to view&amp;quot; do&lt;br /&gt;
* test &amp;quot;test create advertisement should set advertise_for_partner true&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should set comment for advertisement&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should redirect to view&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should show notice&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should change comment&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should redirect to view&amp;quot; do&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refactoring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84738</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84738"/>
		<updated>2014-04-25T17:58:57Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* unit/team_test.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Changes made to original classes ==&lt;br /&gt;
=== team.rb === &lt;br /&gt;
* line 10 def get_participants removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 26&lt;br /&gt;
* line 38 def self.generate_team_name() removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 150&lt;br /&gt;
* line 100 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 99, the method will not work.&lt;br /&gt;
&lt;br /&gt;
== Test Classes ==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
* get_participants : get participant in the team&lt;br /&gt;
* delete : delete a team member in the team&lt;br /&gt;
* get_node_type : will return “TeamNode”&lt;br /&gt;
* get_author_name : will return team’s name&lt;br /&gt;
* generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
* get_possible_team_members(name) : find a team member by name&lt;br /&gt;
* has_user(user : find a team member by user object&lt;br /&gt;
* add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
* copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
* create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
* check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
* delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
* generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
* import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
* test &amp;quot;test remove advertisement should set advertise_for_partner false&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should remove advertisement comments&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should redirect to view&amp;quot; do&lt;br /&gt;
* test &amp;quot;test create advertisement should set advertise_for_partner true&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should set comment for advertisement&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should redirect to view&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should show notice&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should change comment&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should redirect to view&amp;quot; do&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
Most of test should be straightforward, so only the test with concerns will be listed below&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84737</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84737"/>
		<updated>2014-04-25T17:58:11Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* unit/team_test.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Changes made to original classes ==&lt;br /&gt;
=== team.rb === &lt;br /&gt;
* line 10 def get_participants removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 26&lt;br /&gt;
* line 38 def self.generate_team_name() removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 150&lt;br /&gt;
* line 100 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 99, the method will not work.&lt;br /&gt;
&lt;br /&gt;
== Test Classes ==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
* get_participants : get participant in the team&lt;br /&gt;
* delete : delete a team member in the team&lt;br /&gt;
* get_node_type : will return “TeamNode”&lt;br /&gt;
* get_author_name : will return team’s name&lt;br /&gt;
* generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
* get_possible_team_members(name) : find a team member by name&lt;br /&gt;
* has_user(user : find a team member by user object&lt;br /&gt;
* add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
* copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
* create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
* check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
* delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
* generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
* import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
* test &amp;quot;test remove advertisement should set advertise_for_partner false&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should remove advertisement comments&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should redirect to view&amp;quot; do&lt;br /&gt;
* test &amp;quot;test create advertisement should set advertise_for_partner true&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should set comment for advertisement&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should redirect to view&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should show notice&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should change comment&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should redirect to view&amp;quot; do&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participants_controller.rb ===&lt;br /&gt;
* These two files are never used, no tests will cover them.&lt;br /&gt;
&lt;br /&gt;
=== teams_user.rb ===&lt;br /&gt;
* In ''delete'' method, the statements about ''team.delete'' should be commented out due to the recursion it causes.&lt;br /&gt;
* ''elf.is_team_empty'' method is rewritten since the original code will cause fatal error.&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
* ''delete_select'' method will not work since the params are not in accordance with the method called inside.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84735</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84735"/>
		<updated>2014-04-24T21:21:15Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Change made to original classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Changes made to original classes ==&lt;br /&gt;
=== team.rb === &lt;br /&gt;
* line 10 def get_participants removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 26&lt;br /&gt;
* line 38 def self.generate_team_name() removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 150&lt;br /&gt;
* line 100 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 99, the method will not work.&lt;br /&gt;
&lt;br /&gt;
== Test Classes ==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
* get_participants : get participant in the team&lt;br /&gt;
* delete : delete a team member in the team&lt;br /&gt;
* get_node_type : will return “TeamNode”&lt;br /&gt;
* get_author_name : will return team’s name&lt;br /&gt;
* generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
* get_possible_team_members(name) : find a team member by name&lt;br /&gt;
* has_user(user : find a team member by user object&lt;br /&gt;
* add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
* copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
* create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
* check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
* delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
* generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
* import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
* test &amp;quot;test remove advertisement should set advertise_for_partner false&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should remove advertisement comments&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should redirect to view&amp;quot; do&lt;br /&gt;
* test &amp;quot;test create advertisement should set advertise_for_partner true&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should set comment for advertisement&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should redirect to view&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should show notice&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should change comment&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should redirect to view&amp;quot; do&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
*  test &amp;quot;add_team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should destroy the team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should remove all teams user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should remove all team node&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
*  test &amp;quot;get_participants from course team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_node_type&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_author_name&amp;quot; do&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
*  test &amp;quot;generate_team_name for existed prefix&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_possible_team_members&amp;quot; do&lt;br /&gt;
*  test &amp;quot;has_user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;do not has_user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member already in team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user node&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member to assignment team successfully&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member to full assignment team should fail&amp;quot; do&lt;br /&gt;
*  test &amp;quot;copy_members from assignment team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;copy_members from course team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;check_for_existing for AssignmentTeam&amp;quot; do&lt;br /&gt;
*  test &amp;quot;check_for_existing for existed AssignmentTeam should raise error&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete all by parent should delete teams&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete all by parent will not fail when no teams found&amp;quot; do&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
*  test &amp;quot;import team members for user not existed should raise error&amp;quot; do&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84734</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84734"/>
		<updated>2014-04-24T21:21:05Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Change made to original classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Change made to original classes ==&lt;br /&gt;
=== team.rb === &lt;br /&gt;
* line 10 def get_participants removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 26&lt;br /&gt;
* line 38 def self.generate_team_name() removed&lt;br /&gt;
** This is commented out because the same method is defined again at line 150&lt;br /&gt;
* line 100 def self.create_node_object(name, parent_id)&lt;br /&gt;
** see the TODO at line 99, the method will not work.&lt;br /&gt;
&lt;br /&gt;
== Test Classes ==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
* get_participants : get participant in the team&lt;br /&gt;
* delete : delete a team member in the team&lt;br /&gt;
* get_node_type : will return “TeamNode”&lt;br /&gt;
* get_author_name : will return team’s name&lt;br /&gt;
* generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
* get_possible_team_members(name) : find a team member by name&lt;br /&gt;
* has_user(user : find a team member by user object&lt;br /&gt;
* add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
* copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
* create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
* check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
* delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
* generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
* import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
* test &amp;quot;test remove advertisement should set advertise_for_partner false&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should remove advertisement comments&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should redirect to view&amp;quot; do&lt;br /&gt;
* test &amp;quot;test create advertisement should set advertise_for_partner true&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should set comment for advertisement&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should redirect to view&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should show notice&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should change comment&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should redirect to view&amp;quot; do&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
*  test &amp;quot;add_team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should destroy the team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should remove all teams user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should remove all team node&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
*  test &amp;quot;get_participants from course team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_node_type&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_author_name&amp;quot; do&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
*  test &amp;quot;generate_team_name for existed prefix&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_possible_team_members&amp;quot; do&lt;br /&gt;
*  test &amp;quot;has_user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;do not has_user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member already in team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user node&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member to assignment team successfully&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member to full assignment team should fail&amp;quot; do&lt;br /&gt;
*  test &amp;quot;copy_members from assignment team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;copy_members from course team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;check_for_existing for AssignmentTeam&amp;quot; do&lt;br /&gt;
*  test &amp;quot;check_for_existing for existed AssignmentTeam should raise error&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete all by parent should delete teams&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete all by parent will not fail when no teams found&amp;quot; do&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
*  test &amp;quot;import team members for user not existed should raise error&amp;quot; do&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84733</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84733"/>
		<updated>2014-04-24T21:17:58Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Test Classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Change made to original classes ==&lt;br /&gt;
== Test Classes ==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
* get_participants : get participant in the team&lt;br /&gt;
* delete : delete a team member in the team&lt;br /&gt;
* get_node_type : will return “TeamNode”&lt;br /&gt;
* get_author_name : will return team’s name&lt;br /&gt;
* generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
* get_possible_team_members(name) : find a team member by name&lt;br /&gt;
* has_user(user : find a team member by user object&lt;br /&gt;
* add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
* copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
* create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
* check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
* delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
* generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
* import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
* test &amp;quot;test remove advertisement should set advertise_for_partner false&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should remove advertisement comments&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should redirect to view&amp;quot; do&lt;br /&gt;
* test &amp;quot;test create advertisement should set advertise_for_partner true&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should set comment for advertisement&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should redirect to view&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should show notice&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should change comment&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should redirect to view&amp;quot; do&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
*  test &amp;quot;add_team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should destroy the team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should remove all teams user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should remove all team node&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
*  test &amp;quot;get_participants from course team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_node_type&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_author_name&amp;quot; do&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
*  test &amp;quot;generate_team_name for existed prefix&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_possible_team_members&amp;quot; do&lt;br /&gt;
*  test &amp;quot;has_user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;do not has_user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member already in team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user node&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member to assignment team successfully&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member to full assignment team should fail&amp;quot; do&lt;br /&gt;
*  test &amp;quot;copy_members from assignment team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;copy_members from course team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;check_for_existing for AssignmentTeam&amp;quot; do&lt;br /&gt;
*  test &amp;quot;check_for_existing for existed AssignmentTeam should raise error&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete all by parent should delete teams&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete all by parent will not fail when no teams found&amp;quot; do&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
*  test &amp;quot;import team members for user not existed should raise error&amp;quot; do&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84732</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84732"/>
		<updated>2014-04-24T21:17:36Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
== Test Classes ==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
* get_participants : get participant in the team&lt;br /&gt;
* delete : delete a team member in the team&lt;br /&gt;
* get_node_type : will return “TeamNode”&lt;br /&gt;
* get_author_name : will return team’s name&lt;br /&gt;
* generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
* get_possible_team_members(name) : find a team member by name&lt;br /&gt;
* has_user(user : find a team member by user object&lt;br /&gt;
* add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
* copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
* create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
* check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
* delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
* generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
* import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
* test &amp;quot;test remove advertisement should set advertise_for_partner false&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should remove advertisement comments&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should redirect to view&amp;quot; do&lt;br /&gt;
* test &amp;quot;test create advertisement should set advertise_for_partner true&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should set comment for advertisement&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should redirect to view&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should show notice&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should change comment&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should redirect to view&amp;quot; do&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
*  test &amp;quot;add_team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should destroy the team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should remove all teams user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should remove all team node&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
*  test &amp;quot;get_participants from course team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_node_type&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_author_name&amp;quot; do&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
*  test &amp;quot;generate_team_name for existed prefix&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_possible_team_members&amp;quot; do&lt;br /&gt;
*  test &amp;quot;has_user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;do not has_user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member already in team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user node&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member to assignment team successfully&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member to full assignment team should fail&amp;quot; do&lt;br /&gt;
*  test &amp;quot;copy_members from assignment team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;copy_members from course team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;check_for_existing for AssignmentTeam&amp;quot; do&lt;br /&gt;
*  test &amp;quot;check_for_existing for existed AssignmentTeam should raise error&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete all by parent should delete teams&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete all by parent will not fail when no teams found&amp;quot; do&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
*  test &amp;quot;import team members for user not existed should raise error&amp;quot; do&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84731</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84731"/>
		<updated>2014-04-24T21:17:09Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Testing Scenarios */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
* get_participants : get participant in the team&lt;br /&gt;
* delete : delete a team member in the team&lt;br /&gt;
* get_node_type : will return “TeamNode”&lt;br /&gt;
* get_author_name : will return team’s name&lt;br /&gt;
* generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
* get_possible_team_members(name) : find a team member by name&lt;br /&gt;
* has_user(user : find a team member by user object&lt;br /&gt;
* add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
* copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
* create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
* check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
* delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
* generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
* import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== functional/teams_users_controller_test.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== unit/teams_users_test.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== functional/advertise_for_partner_controller_test.rb ===&lt;br /&gt;
* test &amp;quot;test remove advertisement should set advertise_for_partner false&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should remove advertisement comments&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should redirect to view&amp;quot; do&lt;br /&gt;
* test &amp;quot;test create advertisement should set advertise_for_partner true&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should set comment for advertisement&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should redirect to view&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should show notice&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should change comment&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should redirect to view&amp;quot; do&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
*  test &amp;quot;add_team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should destroy the team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should remove all teams user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should remove all team node&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
*  test &amp;quot;get_participants from course team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_node_type&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_author_name&amp;quot; do&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
*  test &amp;quot;generate_team_name for existed prefix&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_possible_team_members&amp;quot; do&lt;br /&gt;
*  test &amp;quot;has_user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;do not has_user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member already in team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user node&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member to assignment team successfully&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member to full assignment team should fail&amp;quot; do&lt;br /&gt;
*  test &amp;quot;copy_members from assignment team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;copy_members from course team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;check_for_existing for AssignmentTeam&amp;quot; do&lt;br /&gt;
*  test &amp;quot;check_for_existing for existed AssignmentTeam should raise error&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete all by parent should delete teams&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete all by parent will not fail when no teams found&amp;quot; do&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
*  test &amp;quot;import team members for user not existed should raise error&amp;quot; do&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== unit/assignment_team_test.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== unit/course_team_test.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84730</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84730"/>
		<updated>2014-04-24T21:16:06Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* team.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
* get_participants : get participant in the team&lt;br /&gt;
* delete : delete a team member in the team&lt;br /&gt;
* get_node_type : will return “TeamNode”&lt;br /&gt;
* get_author_name : will return team’s name&lt;br /&gt;
* generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
* get_possible_team_members(name) : find a team member by name&lt;br /&gt;
* has_user(user : find a team member by user object&lt;br /&gt;
* add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
* copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
* create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
* check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
* delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
* generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
* import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* test &amp;quot;test remove advertisement should set advertise_for_partner false&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should remove advertisement comments&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should redirect to view&amp;quot; do&lt;br /&gt;
* test &amp;quot;test create advertisement should set advertise_for_partner true&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should set comment for advertisement&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should redirect to view&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should show notice&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should change comment&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should redirect to view&amp;quot; do&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== unit/team_test.rb ===&lt;br /&gt;
*  test &amp;quot;add_team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should destroy the team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should remove all teams user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete should remove all team node&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_participants from assignment team&amp;quot; do&lt;br /&gt;
** Please notice that this will actually call the get_participants under AssignmentTeam&lt;br /&gt;
*  test &amp;quot;get_participants from course team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_node_type&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_author_name&amp;quot; do&lt;br /&gt;
*  test &amp;quot;generate_team_name&amp;quot; do&lt;br /&gt;
** Please notice that this method (self.generate_team_name)is modified&lt;br /&gt;
*  test &amp;quot;generate_team_name for existed prefix&amp;quot; do&lt;br /&gt;
*  test &amp;quot;get_possible_team_members&amp;quot; do&lt;br /&gt;
*  test &amp;quot;has_user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;do not has_user&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member already in team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user&amp;quot; do&lt;br /&gt;
** In the original code, it allow nil to be passed as parameter, and checks for assignment.id = nil, but rails will actually raise runtime error when nil is passed.&lt;br /&gt;
*  test &amp;quot;add member for course should create teams user node&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member to assignment team successfully&amp;quot; do&lt;br /&gt;
*  test &amp;quot;add member to full assignment team should fail&amp;quot; do&lt;br /&gt;
*  test &amp;quot;copy_members from assignment team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;copy_members from course team&amp;quot; do&lt;br /&gt;
*  test &amp;quot;check_for_existing for AssignmentTeam&amp;quot; do&lt;br /&gt;
*  test &amp;quot;check_for_existing for existed AssignmentTeam should raise error&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete all by parent should delete teams&amp;quot; do&lt;br /&gt;
*  test &amp;quot;delete all by parent will not fail when no teams found&amp;quot; do&lt;br /&gt;
*  #test &amp;quot;randomize_all_by_parent&amp;quot; do&lt;br /&gt;
** Commented out because the bug in the code make it raise error because assignment id not passed. (wrong argument)&lt;br /&gt;
*  test &amp;quot;import team members for user not existed should raise error&amp;quot; do&lt;br /&gt;
*  #test &amp;quot;import team members successfully&amp;quot; do&lt;br /&gt;
** problem: add_member are not passing correct assignment id at line 169 in team.rb&lt;br /&gt;
&lt;br /&gt;
=== assignment_team.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== course_team.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84729</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84729"/>
		<updated>2014-04-24T21:03:29Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* advertise_for_partner_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
* get_participants : get participant in the team&lt;br /&gt;
* delete : delete a team member in the team&lt;br /&gt;
* get_node_type : will return “TeamNode”&lt;br /&gt;
* get_author_name : will return team’s name&lt;br /&gt;
* generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
* get_possible_team_members(name) : find a team member by name&lt;br /&gt;
* has_user(user : find a team member by user object&lt;br /&gt;
* add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
* copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
* create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
* check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
* delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
* generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
* import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* test &amp;quot;test remove advertisement should set advertise_for_partner false&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should remove advertisement comments&amp;quot; do&lt;br /&gt;
* test &amp;quot;test remove advertisement should redirect to view&amp;quot; do&lt;br /&gt;
* test &amp;quot;test create advertisement should set advertise_for_partner true&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should set comment for advertisement&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test create advertisement should redirect to view&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should show notice&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should change comment&amp;quot; do&lt;br /&gt;
*  test &amp;quot;test update advertisement successfully should redirect to view&amp;quot; do&lt;br /&gt;
*  # test &amp;quot;test update advertisement fail&amp;quot; do&lt;br /&gt;
** should show flash for fail message when team.save fail, but there is no really a good way to fail team.save, so this is not implemented&lt;br /&gt;
*  test &amp;quot;test edit advertisement&amp;quot; do&lt;br /&gt;
** only assign team&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
=== assignment_team.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== course_team.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84728</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84728"/>
		<updated>2014-04-24T20:56:33Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Running Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
* get_participants : get participant in the team&lt;br /&gt;
* delete : delete a team member in the team&lt;br /&gt;
* get_node_type : will return “TeamNode”&lt;br /&gt;
* get_author_name : will return team’s name&lt;br /&gt;
* generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
* get_possible_team_members(name) : find a team member by name&lt;br /&gt;
* has_user(user : find a team member by user object&lt;br /&gt;
* add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
* copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
* create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
* check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
* delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
* generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
* import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
=== assignment_team.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== course_team.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
You can also run multiple tests&lt;br /&gt;
  rake test:prepare&lt;br /&gt;
  bundle exec ruby -I.:test -e &amp;quot;ARGV.each{|f| require f}&amp;quot; test/functional/teams_users_controller_test.rb test/functional/advertise_for_partner_controller_test.rb test/unit/course_team_test.rb test/unit/assignment_team_test.rb test/unit/team_test.rb test/unit/team_user_test.rb&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84727</id>
		<title>CSC/ECE 517 Spring 2014/final doc updated qyx</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/final_doc_updated_qyx&amp;diff=84727"/>
		<updated>2014-04-24T20:49:16Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
=== assignment_team.rb &amp;amp; course_team.rb ===&lt;br /&gt;
* Both assignment_team class and course_team class are inherited from team class.&lt;br /&gt;
* These two classes have similar methods, which could be used to manage teams for assignment and course more effectively.&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
* get_participants : get participant in the team&lt;br /&gt;
* delete : delete a team member in the team&lt;br /&gt;
* get_node_type : will return “TeamNode”&lt;br /&gt;
* get_author_name : will return team’s name&lt;br /&gt;
* generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
* get_possible_team_members(name) : find a team member by name&lt;br /&gt;
* has_user(user : find a team member by user object&lt;br /&gt;
* add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
* copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
* create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
* check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
* delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
* generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
* import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
=== app/unit/assignment_team.rb ===&lt;br /&gt;
* includes?(participant): check if this assignment team include this participant&lt;br /&gt;
* assign_reviewer(reviewer): assign a reviewer for this assignment team&lt;br /&gt;
* reviewed_by?(reviewer)：check if this assignment team is reviewed by this reviewer&lt;br /&gt;
* topic: get the topic picked up by this team&lt;br /&gt;
* has_submissions?: check if this team submitted work or not&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
* participants: get all the participants&lt;br /&gt;
* delete: delete the signed up users&lt;br /&gt;
* self.get_first_member(team_id): get the first participant&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
* get_path&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
* get_review_map_type: return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* email： get fist team user's email&lt;br /&gt;
* get_participant_type: return AssignmentParticipant&lt;br /&gt;
* get_parent_model：return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
* get_participants&lt;br /&gt;
* copy(course_id): copy a team from course team&lt;br /&gt;
* add_participant(assignment_id, user): add participant to AssignmentParticipant&lt;br /&gt;
* assignment&lt;br /&gt;
* get_scores(questions): return a hash of scores that the team has received for the questions&lt;br /&gt;
* self.get_team(participant): get this participant's team&lt;br /&gt;
* self.export(csv, parent_id, options): export assignment and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
* self.remove_team_by_id(id): Remove a team given the team id&lt;br /&gt;
&lt;br /&gt;
=== app/unit/course_team.rb ===&lt;br /&gt;
* get_participant_type: return CourseParticipant&lt;br /&gt;
* get_parent_model：return Course&lt;br /&gt;
* get_node_type: return TeamNode&lt;br /&gt;
* assignment_id: return nil&lt;br /&gt;
* copy(assignment_id): copy a team from assignment team&lt;br /&gt;
* add_participant(course_id, user): add a user to a course. Note: this is deprecated because the functionality belongs to course&lt;br /&gt;
* export_participants: export the participants of a course team&lt;br /&gt;
* export(team_name_only): export team name, participants and course&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates): handle duplicate team in different cases&lt;br /&gt;
* self.import(row,session,assignment_id,options): import team members to a exist team or a new team&lt;br /&gt;
* self.export(csv, parent_id, options): export course and team members&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options): this method is deprecated&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
'''However, all of the fixtures are required to be in the fixutre folder, otherwise it will raise error.'''&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
* questions.yml&lt;br /&gt;
* signed_up_users.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb ===&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete to check if it could delete the team node and the team user&lt;br /&gt;
&lt;br /&gt;
* Remove_team&lt;br /&gt;
** Test Remove_team with valid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Remove_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
* Is_team_empty&lt;br /&gt;
** Test Is_team_empty with empty team&lt;br /&gt;
** Test Is_team_empty with non-empty team&lt;br /&gt;
&lt;br /&gt;
* Add_member_to_invited_team&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with valid user_id and invalid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and valid team_id&lt;br /&gt;
** Test Add_member_to_invited_team with invalid user_id and invalid team_id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
=== assignment_team.rb ===&lt;br /&gt;
* includes?(participant)&lt;br /&gt;
** test one assignment team include a participant return true&lt;br /&gt;
* assign_reviewer(reviewer)&lt;br /&gt;
** assign a reviewer for this assignment team, and TeamReviewResponseMap.count increases&lt;br /&gt;
* reviewed_by?(reviewer)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* has_submissions?&lt;br /&gt;
** test one team has a submission return true&lt;br /&gt;
* reviewed_contributor?(contributor)&lt;br /&gt;
** TeamReviewResponseMap is empty, so test this method will return false&lt;br /&gt;
* participants&lt;br /&gt;
** participants are not nil&lt;br /&gt;
* delete&lt;br /&gt;
** this method has bug. No test&lt;br /&gt;
* self.get_first_member(team_id)&lt;br /&gt;
** test first menber not nil&lt;br /&gt;
* get_hyperlinks&lt;br /&gt;
** test hyperlinks are not nil&lt;br /&gt;
* get_path&lt;br /&gt;
** test path is not nil&lt;br /&gt;
* get_submitted_files&lt;br /&gt;
** submitted_file must be empty, expect nil&lt;br /&gt;
* get_review_map_type&lt;br /&gt;
** return TeamReviewResponseMap&lt;br /&gt;
* self.handle_duplicate(team, name, assignment_id, handle_duplicates)&lt;br /&gt;
** test in different cases(team is nil, option is &amp;quot;ignore&amp;quot;, option is &amp;quot;rename&amp;quot;)&lt;br /&gt;
* self.import(row,session,assignment_id,options)&lt;br /&gt;
** test in different cases(argument error, has_column_name is true, has_column_name is false)&lt;br /&gt;
* email&lt;br /&gt;
** this method has bug because there is no method named get_team_users. No test&lt;br /&gt;
* get_participant_type&lt;br /&gt;
** return AssignmentParticipant&lt;br /&gt;
* get_parent_model&lt;br /&gt;
** return Assignment&lt;br /&gt;
* fullname&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_participants&lt;br /&gt;
** test the participants are not nil&lt;br /&gt;
* copy(course_id)&lt;br /&gt;
** TeamUserNode.count and TeamsUser.count increase&lt;br /&gt;
* add_participant(assignment_id, user)&lt;br /&gt;
** AssignmentParticipant.count increases&lt;br /&gt;
* assignment&lt;br /&gt;
** return value should equal what we expect&lt;br /&gt;
* get_scores(questions)&lt;br /&gt;
** return output's total score is not nil and the assignment team is what we expect&lt;br /&gt;
* self.get_team(participant)&lt;br /&gt;
** return team is what we expect&lt;br /&gt;
* self.export(csv, parent_id, options)&lt;br /&gt;
** test in different cases(team_name is true, team_name is false)&lt;br /&gt;
* self.get_export_fields(options)&lt;br /&gt;
** test if the fields' name is right&lt;br /&gt;
* self.create_team_and_node(assignment_id)&lt;br /&gt;
** assignent team and team node are not nil&lt;br /&gt;
* self.remove_team_by_id(id)&lt;br /&gt;
** check the removed team cannot be found in AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=== course_team.rb ===&lt;br /&gt;
Because most of the methods in course_team.rb are similar with that in assignment_team.rb if they have the same name. So I skip the same name method. Take the test/unit/course_team_test.rb as a reference.&lt;br /&gt;
* self.export_all_assignment_team_related_to_course(csv, parent_id, options)&lt;br /&gt;
** this method should be deleted here. No test&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84371</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84371"/>
		<updated>2014-04-09T23:15:12Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* app/controllers/advertise_for_partner_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84370</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84370"/>
		<updated>2014-04-09T23:15:01Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* app/controllers/teams_participant_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84369</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84369"/>
		<updated>2014-04-09T23:11:41Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* app/controllers/teams_participant_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84368</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84368"/>
		<updated>2014-04-09T23:10:00Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Sample Test Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
hey, just to let you know, usually the squares should be ovals.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers from our previous work to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84367</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84367"/>
		<updated>2014-04-09T23:09:07Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* team */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
hey, just to let you know, usually the squares should be ovals.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84366</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84366"/>
		<updated>2014-04-09T23:08:50Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* advertise_for_team_controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
hey, just to let you know, usually the squares should be ovals.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller.rb ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
&lt;br /&gt;
=== team ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84365</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84365"/>
		<updated>2014-04-09T23:08:19Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
hey, just to let you know, usually the squares should be ovals.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
=== team ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84364</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84364"/>
		<updated>2014-04-09T23:08:01Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
hey, just to let you know, usually the squares should be ovals.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
=== team ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84363</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84363"/>
		<updated>2014-04-09T23:06:46Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
hey, just to let you know, usually the squares should be ovals.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
=== team ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84362</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84362"/>
		<updated>2014-04-09T23:02:10Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Test Environment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
hey, just to let you know, usually the squares should be ovals.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
=== team ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84361</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84361"/>
		<updated>2014-04-09T23:02:01Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
hey, just to let you know, usually the squares should be ovals.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
=== team ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84360</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84360"/>
		<updated>2014-04-09T22:00:26Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* Background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
=== advertise_for_partner.rb ===&lt;br /&gt;
* This controller takes over the advertisement function from the student_team_controller, and make the class more RESTful. &lt;br /&gt;
* 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&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* This model defines the relationship between team object and other objects. It also has other methods to handle related functions about team operation&lt;br /&gt;
* 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.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
hey, just to let you know, usually the squares should be ovals.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
=== team ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84359</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84359"/>
		<updated>2014-04-09T21:46:55Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* team.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
hey, just to let you know, usually the squares should be ovals.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
=== team ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84358</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84358"/>
		<updated>2014-04-09T21:46:41Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* team.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
hey, just to let you know, usually the squares should be ovals.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* get participants&lt;br /&gt;
** test get participants&lt;br /&gt;
&lt;br /&gt;
* delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id)&lt;br /&gt;
** ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* delete_all_by_parent(parent)&lt;br /&gt;
** test delete with valid parents&lt;br /&gt;
** test delete with invalid parents&lt;br /&gt;
&lt;br /&gt;
* randomize_all_by_parent(parent, team_type, team_size)&lt;br /&gt;
** test randomize all by parent with exact number&lt;br /&gt;
** test randomize all by parent without enough people&lt;br /&gt;
** test randomize all by parent with remainder&lt;br /&gt;
&lt;br /&gt;
* generate_team_name(teamnameprefix)&lt;br /&gt;
** test generate prefix team name with valid name&lt;br /&gt;
** test generate prefix team name with duplicated name&lt;br /&gt;
&lt;br /&gt;
* import_team_members(starting_index, row) &lt;br /&gt;
** test import team members with valid index and row&lt;br /&gt;
** test import team members with invalid index and row&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
=== team ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84357</id>
		<title>CSC/ECE 517 Spring 2014/oss E1414 st</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1414_st&amp;diff=84357"/>
		<updated>2014-04-09T21:30:56Z</updated>

		<summary type="html">&lt;p&gt;Yhong3: /* advertise_for_partner_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1414: Testing classes related to teams=&lt;br /&gt;
''Please be advised that we do not have deployment link, since our work are all back-end tests''&lt;br /&gt;
__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
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.&lt;br /&gt;
== Test Environment ==&lt;br /&gt;
&lt;br /&gt;
;Framework : [http://guides.rubyonrails.org/testing.html Rails default test framework]&lt;br /&gt;
;Sample data : Fixtures (under /test/fixtures)&lt;br /&gt;
;Coverage tool: [https://rubygems.org/gems/simplecov SimpleCov]&lt;br /&gt;
&lt;br /&gt;
==Classes==&lt;br /&gt;
=== app/models/teams_users.rb===&lt;br /&gt;
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_users_controller.rb===&lt;br /&gt;
The teams_users_controller support team member management for instructor/TA accounts&lt;br /&gt;
Instruction/TA can:&lt;br /&gt;
* get a user name by inputting part of the name&lt;br /&gt;
* list team members of a team &lt;br /&gt;
* add a user to a team&lt;br /&gt;
* remove a team member from a team&lt;br /&gt;
* remove all members belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partners_controller.rb ===&lt;br /&gt;
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.&lt;br /&gt;
&lt;br /&gt;
A student can:&lt;br /&gt;
* create a new advertisement for the team&lt;br /&gt;
* edit the advertisement content&lt;br /&gt;
* remove advertisement record from the table for the specific team&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb===&lt;br /&gt;
The teams_participant_controller support team participants management so the team participant:&lt;br /&gt;
* get a participant name by inputting part of the name&lt;br /&gt;
* list team participants of a team &lt;br /&gt;
* add a participant to a team&lt;br /&gt;
* remove a selected team participant from a team&lt;br /&gt;
* remove all team participants belonging to an item&lt;br /&gt;
&lt;br /&gt;
=== app/models/team.rb ===&lt;br /&gt;
The “team” object represents a team that consists students who are either participants of course or assignment.&lt;br /&gt;
a team will response to the request on: &lt;br /&gt;
&lt;br /&gt;
;get_participants : get participant in the team&lt;br /&gt;
;delete : delete a team member in the team&lt;br /&gt;
;get_node_type : will return “TeamNode”&lt;br /&gt;
;get_author_name : will return team’s name&lt;br /&gt;
;generate_team_name() : serialize the automatically generated team name (e.g. team 1, team 2, etc.)&lt;br /&gt;
;get_possible_team_members(name) : find a team member by name&lt;br /&gt;
;has_user(user : find a team member by user object&lt;br /&gt;
;add_member(user, assignment_id) : add a user to an assignment team&lt;br /&gt;
;copy_members(new_team) : copy current member in the team to the new team&lt;br /&gt;
;create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
;check_for_exisiting(parent, name, team_type) : check if the team name under the same assignment or course is in use.&lt;br /&gt;
;Delete_all_by_parent(parent) : delete all teams under the same course/assignment&lt;br /&gt;
;Randomize_all_by_parent(parent, team_type, team_size) : randomly assign team members&lt;br /&gt;
;generate_team_name(teamnameprefix) : generate team name with prefix (e.g. prefix_Team1) &lt;br /&gt;
;import_team_members(starting_index, row) : import user from specific index of users and length&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
=== teams_users.rb &amp;amp; teams_users_controller.rb===&lt;br /&gt;
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.&lt;br /&gt;
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.&lt;br /&gt;
=== teams_participant.rb &amp;amp; teams_participant_controller.rb===&lt;br /&gt;
* teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.&lt;br /&gt;
* There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To set up our testing for the models and controllers, we need some fixtures to support. &lt;br /&gt;
Fixtures needed for corresponding classes are listed below&lt;br /&gt;
&lt;br /&gt;
=== fixtures use in common ===&lt;br /&gt;
* teams.yml&lt;br /&gt;
* users.yml &lt;br /&gt;
* teams_users.yml&lt;br /&gt;
* courses.yml&lt;br /&gt;
* assignments.yml&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
Besides the above fixtures, we also need the following fixrure&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
&lt;br /&gt;
=== teams.rb ===&lt;br /&gt;
* teams_participant.yml&lt;br /&gt;
* join_team_requests.yml&lt;br /&gt;
* participants.yml&lt;br /&gt;
* nodes.yml&lt;br /&gt;
&lt;br /&gt;
== Use Case Diagram ==&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
[[File:Usercase.jpg]]&lt;br /&gt;
&lt;br /&gt;
hey, just to let you know, usually the squares should be ovals.&lt;br /&gt;
&lt;br /&gt;
=== app/controllers/advertise_for_partner_controller.rb ===&lt;br /&gt;
[[File:Usecase_E1414_advertise.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Testing Scenarios ==&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_users.rb &amp;amp; app/controllers/teams_users_controller.rb ===&lt;br /&gt;
[[File:TeamUsersStory.png]]&lt;br /&gt;
&lt;br /&gt;
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== app/models/teams_participant.rb &amp;amp; app/controllers/teams_participant_controller.rb ===&lt;br /&gt;
&lt;br /&gt;
* Auto_complete_for_user_name:&lt;br /&gt;
** Test auto_complete_for_user_name with valid user name&lt;br /&gt;
** Test auto_complete_for_user_name with invalid user name&lt;br /&gt;
&lt;br /&gt;
* List&lt;br /&gt;
** Test List with valid team id&lt;br /&gt;
** Test List with invalid team id&lt;br /&gt;
&lt;br /&gt;
* New&lt;br /&gt;
** Test New with valid team id&lt;br /&gt;
** Test New with invalid team id&lt;br /&gt;
&lt;br /&gt;
* Create&lt;br /&gt;
** Test Create with valid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
** Test Create with invalid team id&lt;br /&gt;
*** Test Create with valid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is not reached&lt;br /&gt;
*** Test Create with valid user id and maximum member number is reached&lt;br /&gt;
*** Test Create with invalid user id and maximum member number is reached&lt;br /&gt;
&lt;br /&gt;
* Delete&lt;br /&gt;
** Test Delete with valid user id&lt;br /&gt;
** Test Delete with invalid user id&lt;br /&gt;
&lt;br /&gt;
* Delete_select&lt;br /&gt;
** Test Delete_select with valid item id&lt;br /&gt;
** Test Delete_select with invalid item id&lt;br /&gt;
&lt;br /&gt;
=== advertise_for_partner_controller.rb ===&lt;br /&gt;
* remove&lt;br /&gt;
** test remove with valid user id&lt;br /&gt;
** test remove with invalid user id&lt;br /&gt;
&lt;br /&gt;
* create&lt;br /&gt;
** test create with valid user id&lt;br /&gt;
** test create with invalid user id&lt;br /&gt;
&lt;br /&gt;
* update&lt;br /&gt;
** test update with invalid id&lt;br /&gt;
** test update success&lt;br /&gt;
** test update fail (should remain the same)&lt;br /&gt;
&lt;br /&gt;
* edit&lt;br /&gt;
** test edit&lt;br /&gt;
=== team.rb ===&lt;br /&gt;
* test get participants&lt;br /&gt;
* test delete&lt;br /&gt;
** test delete with team node&lt;br /&gt;
** test delete without team node&lt;br /&gt;
* get_node_type &lt;br /&gt;
** test get node type&lt;br /&gt;
* get_author_name&lt;br /&gt;
** test author name&lt;br /&gt;
* generate_team_name() &lt;br /&gt;
** test generate team name from zero&lt;br /&gt;
** test generate team name from one&lt;br /&gt;
* get_possible_team_members(name)&lt;br /&gt;
** test get possible team members by exact name&lt;br /&gt;
** test get possible team members by similar name&lt;br /&gt;
** test get possible team members by name in other team&lt;br /&gt;
* has_user(user)&lt;br /&gt;
** test has user with valid user&lt;br /&gt;
** test has user with invalid user&lt;br /&gt;
* add_member(user, assignment_id)&lt;br /&gt;
** test add member with valid user&lt;br /&gt;
** test add member already in team&lt;br /&gt;
** test add member without assignment id&lt;br /&gt;
** test add member when max team size reached&lt;br /&gt;
* copy_members(new_team)&lt;br /&gt;
** test copy members to empty new team&lt;br /&gt;
** test copy members to nonempty new team&lt;br /&gt;
** test copy members with no member in current team&lt;br /&gt;
&lt;br /&gt;
* create_node_object(name, parent_id) : ‘’there is a TODO on this method indicated that this is not working’’ &lt;br /&gt;
&lt;br /&gt;
* check_for_exisiting(parent, name, team_type)&lt;br /&gt;
** test check for exisiting with exisited name&lt;br /&gt;
** test check for exisiting with nonexisted name&lt;br /&gt;
&lt;br /&gt;
== Possible Refacotring ==&lt;br /&gt;
=== advertise_for_team_controller ===&lt;br /&gt;
* ''update'' should be ''edit'' (this is mentioned in the comments of code)&lt;br /&gt;
* ''edit'' should be reexamined since it is only retrieving the team object&lt;br /&gt;
* ''new'' is empty, so it should be removed&lt;br /&gt;
=== team ===&lt;br /&gt;
* There are two ''def get_participants'', the second one overwritten the first one, so the first one should be deleted.&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. &lt;br /&gt;
To see the result of tests, run &lt;br /&gt;
 rake test TEST=test/unit/&amp;lt;filename&amp;gt; # for models&lt;br /&gt;
and &lt;br /&gt;
 rake test TEST=test/functional/&amp;lt;filename&amp;gt; # for controllers&lt;br /&gt;
&lt;br /&gt;
running the whole test suite with &amp;lt;code&amp;gt;rake test&amp;lt;/code&amp;gt; is not recommended, as the schema change overtime has broke some of the previous tests.&lt;br /&gt;
&lt;br /&gt;
==Sample Test Code==&lt;br /&gt;
We show two pieces of test code for two controllers to explain how our test works&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_student team with name in use&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:student8))&lt;br /&gt;
        post(:create, {'team' =&amp;gt; { 'name' =&amp;gt; 'IntelligentTeam2'}, 'id' =&amp;gt; participants(:par21).id, &amp;quot;commit&amp;quot; =&amp;gt; &amp;quot;Create Team&amp;quot;}, sessionVars, nil)&lt;br /&gt;
        assert_equal 'Team name is already in use.', flash[:notice]&lt;br /&gt;
        assert_redirected_to :controller =&amp;gt; 'student_team', :action =&amp;gt; 'view', :id =&amp;gt; participants(:par21).id&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    test &amp;quot;create_should_increase_number_of_teams_course&amp;quot; do&lt;br /&gt;
        sessionVars = session_for(users(:instructor1))&lt;br /&gt;
        sessionVars[:team_type] = &amp;quot;Course&amp;quot;&lt;br /&gt;
        assert_difference 'Team.count' do&lt;br /&gt;
          get :create, {'id' =&amp;gt; @testCourse,'team' =&amp;gt; {'name' =&amp;gt; &amp;quot;Random&amp;quot;}},sessionVars&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
As we can see from the code, when we want to use &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt;, 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.&lt;br /&gt;
&lt;br /&gt;
When we run the command &amp;lt;code&amp;gt;rake test TEST=test/functional/your_test_file.rb&amp;lt;/code&amp;gt;, you will see if the test is passed or not. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
* http://guides.rubyonrails.org/testing.html&lt;br /&gt;
* https://github.com/colszowka/simplecov&lt;/div&gt;</summary>
		<author><name>Yhong3</name></author>
	</entry>
</feed>