CSC/ECE 517 Spring 2014/oss E1414 st: Difference between revisions
Line 90: | Line 90: | ||
=== app/controllers/teams_participant_controller.rb === | === app/controllers/teams_participant_controller.rb === | ||
[[File:Usercase.jpg]] | [[File:Usercase.jpg]] | ||
hey, just to let you know, usually the squares should be ovals. | |||
== Testing Scenarios == | == Testing Scenarios == |
Revision as of 20:28, 9 April 2014
Please be advised that we do not have deployment link, since our work are all back-end tests
Introduction
This project will be an extension of our previous E1406 project. For the previous project, we did some refactoring and testing for the controllers related to teams. This time, we are going to reuse most of our test environment, but extend the tests to other team-related classes. We also expect to examine and report the code that may require refactoring.
Test Environment
- Framework
- Rails default test framework
- Sample data
- Fixtures (under /test/fixtures)
- Coverage tool
- SimpleCov
Classes
app/models/teams_users.rb
The teams_users.rb is a model belonging to both users and teams. It is used when a user is added to a team.
app/controllers/teams_users_controller.rb
The teams_users_controller support team member management for instructor/TA accounts Instruction/TA can:
- get a user name by inputting part of the name
- list team members of a team
- add a user to a team
- remove a team member from a team
- remove all members belonging to an item
app/controllers/advertise_for_partners_controller.rb
The advertise_for_partners_controller work with the student_team_controllers, allowing student manage advertisement for their teams.
A student can:
- create a new advertisement for the team
- edit the advertisement content
- remove advertisement record from the table for the specific team
app/models/teams_participant.rb
The teams_participant.rb is a model belonging to both users and teams. It is used when a team participant is created, listed or deleted.
app/controllers/teams_participant_controller.rb
The teams_participant_controller support team participants management so the team participant:
- get a participant name by inputting part of the name
- list team participants of a team
- add a participant to a team
- remove a selected team participant from a team
- remove all team participants belonging to an item
app/models/team.rb
The “team” object represents a team that consists students who are either participants of course or assignment. a team will response to the request on:
- get_participants
- get participant in the team
- delete
- delete a team member in the team
- get_node_type
- will return “TeamNode”
- get_author_name
- will return team’s name
- generate_team_name()
- serialize the automatically generated team name (e.g. team 1, team 2, etc.)
- get_possible_team_members(name)
- find a team member by name
- has_user(user
- find a team member by user object
- add_member(user, assignment_id)
- add a user to an assignment team
- copy_members(new_team)
- copy current member in the team to the new team
- create_node_object(name, parent_id)
- ‘’there is a TODO on this method indicated that this is not working’’
- check_for_exisiting(parent, name, team_type)
- check if the team name under the same assignment or course is in use.
- Delete_all_by_parent(parent)
- delete all teams under the same course/assignment
- Randomize_all_by_parent(parent, team_type, team_size)
- randomly assign team members
- generate_team_name(teamnameprefix)
- generate team name with prefix (e.g. prefix_Team1)
- import_team_members(starting_index, row)
- import user from specific index of users and length
Background
teams_users.rb & teams_users_controller.rb
- Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.
- There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.
teams_participant.rb & teams_participant_controller.rb
- teams_participant.rb and teams_participant_controller.rb are used to manage the participants of teams.
- There is no functional test for teams_participant_controller.rb and unit test for teams_participant.rb in the current version of expertiza codes.
Setup
To set up our testing for the models and controllers, we need some fixtures to support. Fixtures needed for corresponding classes are listed below
app/models/teams_users.rb & app/controllers/teams_users_controller.rb
- teams.yml
- users.yml
- teams_users.yml
- courses.yml
- assignments.yml
app/models/teams_participant.rb & app/controllers/teams_participant_controller.rb
Besides the above fixtures, we also need the following fixrure
- teams_participant.yml
Use Case Diagram
app/controllers/teams_participant_controller.rb
hey, just to let you know, usually the squares should be ovals.
Testing Scenarios
app/models/teams_users.rb & app/controllers/teams_users_controller.rb
Based on the user story of the teams_users_controller.rb, there are also several sub-scenarios for each method in the user story.
- Auto_complete_for_user_name:
- Test auto_complete_for_user_name with valid user name
- Test auto_complete_for_user_name with invalid user name
- List
- Test List with valid team id
- Test List with invalid team id
- New
- Test New with valid team id
- Test New with invalid team id
- Create
- Test Create with valid team id
- Test Create with valid user id and maximum member number is not reached
- Test Create with invalid user id and maximum member number is not reached
- Test Create with valid user id and maximum member number is reached
- Test Create with invalid user id and maximum member number is reached
- Test Create with invalid team id
- Test Create with valid user id and maximum member number is not reached
- Test Create with invalid user id and maximum member number is not reached
- Test Create with valid user id and maximum member number is reached
- Test Create with invalid user id and maximum member number is reached
- Test Create with valid team id
- Delete
- Test Delete with valid user id
- Test Delete with invalid user id
- Delete_select
- Test Delete_select with valid item id
- Test Delete_select with invalid item id
app/models/teams_participant.rb & app/controllers/teams_participant_controller.rb
- Auto_complete_for_user_name:
- Test auto_complete_for_user_name with valid user name
- Test auto_complete_for_user_name with invalid user name
- List
- Test List with valid team id
- Test List with invalid team id
- New
- Test New with valid team id
- Test New with invalid team id
- Create
- Test Create with valid team id
- Test Create with valid user id and maximum member number is not reached
- Test Create with invalid user id and maximum member number is not reached
- Test Create with valid user id and maximum member number is reached
- Test Create with invalid user id and maximum member number is reached
- Test Create with invalid team id
- Test Create with valid user id and maximum member number is not reached
- Test Create with invalid user id and maximum member number is not reached
- Test Create with valid user id and maximum member number is reached
- Test Create with invalid user id and maximum member number is reached
- Test Create with valid team id
- Delete
- Test Delete with valid user id
- Test Delete with invalid user id
- Delete_select
- Test Delete_select with valid item id
- Test Delete_select with invalid item id
Possible Refacotring
advertise_for_team_controller
- update should be edit (this is mentioned in the comments of code)
- edit should be reexamined since it is only retrieving the team object
- new is empty, so it should be removed
team
- There are two def get_participants, the second one overwritten the first one, so the first one should be deleted.
Deployment
Please note that all of our work will be under the /test folder, which means they will not show any change on the view. To see the result of tests, run
rake test TEST=test/functional/student_team_controller.rb
and
rake test TEST=test/functional/teams_controller
running the whole test suite with rake test
is not recommended, as the schema change overtime has broke some of the previous tests.
Sample Test Code
We show two pieces of test code for two controllers to explain how our test works
test "create_student team with name in use" do sessionVars = session_for(users(:student8)) post(:create, {'team' => { 'name' => 'IntelligentTeam2'}, 'id' => participants(:par21).id, "commit" => "Create Team"}, sessionVars, nil) assert_equal 'Team name is already in use.', flash[:notice] assert_redirected_to :controller => 'student_team', :action => 'view', :id => participants(:par21).id end
test "create_should_increase_number_of_teams_course" do sessionVars = session_for(users(:instructor1)) sessionVars[:team_type] = "Course" assert_difference 'Team.count' do get :create, {'id' => @testCourse,'team' => {'name' => "Random"}},sessionVars end end
The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.
As we can see from the code, when we want to use post
or get
, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.
When we run the command rake test TEST=test/functional/your_test_file.rb
, you will see if the test is passed or not.
References
<references/>