<?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=Srajend</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=Srajend"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Srajend"/>
	<updated>2026-05-12T22:06:54Z</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_2018/E1823_Write_integration_tests_for_users_controller.rb&amp;diff=116899</id>
		<title>CSC/ECE 517 Spring 2018/E1823 Write integration tests for users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1823_Write_integration_tests_for_users_controller.rb&amp;diff=116899"/>
		<updated>2018-04-25T01:54:24Z</updated>

		<summary type="html">&lt;p&gt;Srajend: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is a description of E1813 final project for Spring 2018, CSC/ECE 517.&lt;br /&gt;
== Project Statement ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction ===&lt;br /&gt;
&lt;br /&gt;
users_controller.rb is a file under app/controllers that manages different kinds of methods related to users. This project is to write integration tests for users_controller.rb by using rspec, so our goal is to create a file named users_controller_spec.rb under spec/controllers folder and write integration tests to make the path coverage of users_controller.rb more than 90% and achieve the highest possible branch coverage.&lt;br /&gt;
&lt;br /&gt;
All methods used in this file that can render or redirect to one or more user-related views will be thoroughly tested.(16 in total) We do not need to test private or protected methods directly because these methods should be tested when testing other public methods in the same file.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
Newly-created file:&lt;br /&gt;
&lt;br /&gt;
  spec/users_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
Tested file:&lt;br /&gt;
&lt;br /&gt;
  app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
Related view files:&lt;br /&gt;
&lt;br /&gt;
  app/views/users/edit.html.erb&lt;br /&gt;
  app/views/users/keys.html.erb&lt;br /&gt;
  app/views/users/list.html.erb&lt;br /&gt;
  app/views/users/list_pending_requested.erb&lt;br /&gt;
  app/views/users/new.html.erb&lt;br /&gt;
  app/views/users/request_new.html.erb&lt;br /&gt;
  app/views/users/show.html.erb&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
1. Sandeep Rajendran(srajend@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
2. Xiao Ma(xma21@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
3. Zekun Zhang(zzhang56@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
4. Zhiyu Chen(zchen45@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
== Functionality of the Controller ==&lt;br /&gt;
=== Table ===&lt;br /&gt;
&lt;br /&gt;
Table corresponding to User model has the following attributes: (The unexplained attributes are easy to understand or doesn't make sense here)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;1. name&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. crypted_password&amp;lt;/b&amp;gt; - It is the password after encrypting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3. password_salt&amp;lt;/b&amp;gt; - It stores the information of the encryption for the password verification.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. role_id&amp;lt;/b&amp;gt; - It is used to distinguish the users as super-administrator, administrator, instructor or student.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;5. fullname&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;6. email&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;7. parent_id&amp;lt;/b&amp;gt; - For an instructor, reference to an entry in administrator table, referring the administrator who accepts for the instructor; otherwise, empty.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;8. private_by_default&amp;lt;/b&amp;gt; - It is a boolean. Assignments and questionnaire created by the instructor should be private (not visible by others) by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;9. mru_directory_path&amp;lt;/b&amp;gt; - For an instructor, the directory that (s)he was working in the previous time he used the system. This is the path-name relative to the home_directory_path. Empty for a non-instructor.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;10. email_on_review&amp;lt;/b&amp;gt; - It is a boolean value used to check whether someone else is reviewing my work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;11. email_on_submission&amp;lt;/b&amp;gt; - It is a boolean value used to check whether someone else submits work I am assigned to review.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;12. email_on_review_of_review&amp;lt;/b&amp;gt; - It is a boolean value used to check whether someone else reviews one of my reviews.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;13. is_new_user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;14. master_permission_granted&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;15. handle&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;16. digital_certificate&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;17. persistence_token&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;18. timezonepref&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;19. public_key&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;20. copy_of_emails&amp;lt;/b&amp;gt; - It is a boolean value used to check whether the system will send me copies of emails sent for assignments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;21. institution_id&amp;lt;/b&amp;gt; - Reference to an entry in institutions table, referring to the institution at which this user is registered&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&amp;lt;b&amp;gt;1. index&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to list all the users in the database. A permissions check is done first to verify that the current user has permission to view the list of users. If the user is a student, he is redirected away from the page. All other user roles have access to the page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. auto_complete_for_user_name&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The method finds all users who have names similar to the one being typed and displays only those that have a lower role than the current user. The page is rendered again showing all these suggestions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3. set_anonymized_view&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to anonymize the usernames in the views for demo purposes. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. list&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method calls the get_user_list method in the user model which returns a list of users according to the role of the user that calls the method. This list is stored in the @users instance variable which is used by the view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;5. list_pending_requested&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called to show all the requests which need to be reviewed. It first obtains all the request users and the roles. Then It will show those request_users who is under review and their details with a selection window--&amp;quot;status&amp;quot; which is used to determine if this request will be approved or rejected.   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;6. show_selection&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to show the users. It first detects if this user is valid or not. if this user is nil, it will redirect to the &amp;quot;list&amp;quot; page. If this user is valid, it will call the get_role method to get the role information of this user. and then use the role information to determine if this user is available for editing. For users available for editing, this method will render show &amp;quot;page&amp;quot;, otherwise, this method will redirect to &amp;quot;list&amp;quot; page. In summary, this method will direct to &amp;quot;show&amp;quot; page, when the user is able to be edited, otherwise, it will go to &amp;quot;list&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;7. show&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to show the details of a user. It first detect is the user is valid. There two condition for an  invalid user: 1) the id of user is nil; 2) current user role is not student and the session id doesn't equal to the user id. Otherwise this user is valid. For a valid user, it will show his/her detailed information including name, email, password, prefs, institution and self_introduction.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;8. new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when method create is used to create a new user. &lt;br /&gt;
&lt;br /&gt;
[[File:Request3.png]]&lt;br /&gt;
&lt;br /&gt;
(This image will be helpful for the next 4 methods)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;9. request_new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when a TA or instructor requests an Expertiza account. To register to use the Expertiza, one needs to be either a course TA or Instructor and then sends a request to Expertiza administrator to get approved. This function only serves TAs and instructors, and the students account will be created by instructors or TAs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;10. create&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when the user wants to create accounts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;11. create_requested_user_record&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called after the guest sending a request for the account to Expertiza administrator. After the guest sending a request for the account using request_new method, this method will store the request in the database and list all the requests on the pending_request page waiting for the administrator to operate.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;12. create_approved_user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when the Expertiza administrator deals with the guests' pending requests. By this method, the administrator can approve or decline the pending requests. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;13. edit&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;resources :users&amp;quot; in routing rule maps /users/1/edit (assuming user's id is 1) to edit action in UsersController.&lt;br /&gt;
&lt;br /&gt;
Thus, this edit method is called when accessing user's edit page and will pull the relevant user out of the database via user's id that stored in params[:id].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;14. update&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;resources :users&amp;quot; in routing rule makes update action get called when the form in user's edit page is submitted.&lt;br /&gt;
&lt;br /&gt;
This method will first find the relevant user by user's id that stored in params[:id] and then updates the user's information in the database based on the submitted params hash. If the update is successful it shows a success flash and redirects to user's show page otherwise it renders user's edit page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;15. destroy&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;resources :users&amp;quot; in routing rule makes destroy action response to the delete method and thus accomplishing the user deletion. &lt;br /&gt;
&lt;br /&gt;
When this method is called, it will first find the relevant user via user's id that stored in params[:id] and then delete related AssignmentParticipant, TeamsUser and AssignmentQuestionnaire models if any (These models are found through their foregin key: user_id). Finally, the user is deleted from the database and it will show a success flash. If any of the above steps fails, it will throw an error flash.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;16. keys&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;get :keys&amp;quot; under the collection block of &amp;quot;resources :users&amp;quot; will enable Rails to recognize paths such as /users/keys with GET, and route to the key action of UsersController.&lt;br /&gt;
&lt;br /&gt;
When this method is called, if no current user or current user is a student but is not the user stored in session, it will redirect to home page of the user stored in session. Otherwise generate_keys (a method of user model) will be called on the current user and the return value will be assigned to an instance variable @private_key defined in UsersController.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
This project aims to writing an integration test for users_controller.rb. There is no this Rspec file exist for this test, so a new test file shall be created and built from scratch. And before writing this test file, some prerequisites must be done.&lt;br /&gt;
1. Download and set the Expertiza environment&lt;br /&gt;
2. Determine which methods should be tested&lt;br /&gt;
3. Define all the conditions needed to be tested for each method&lt;br /&gt;
&lt;br /&gt;
The methods have already been introduced on above, here are the test plan for each method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;1. index&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
1.1 &amp;quot;If the user is student, we check if proper redirection is taking place&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
1.2 &amp;quot;Else, the appropriate list of users should be rendered according to the role of the current user&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. auto_complete_for_user_name&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
2.1 &amp;quot;The page should render suggestions only of those user names that are similar to the one being typed and not all user names&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3. set_anonymized_view&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
3.1 &amp;quot;The method should add the session ip to the list of anonymized ip's and redirect to the previous page &amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. list&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
4.1 &amp;quot;The @users instance variable should contain all the users that are permitted to be viewed by the current user. This is tested by the same test for index&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;5. list_pending_requested&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
5.1 &amp;quot;check if it will render users/list_pending_requested page&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;6. show_selection&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
6.1 &amp;quot;check if the user is nil, will the page redirect to users/list page&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
6.2 &amp;quot;check if the user is not available for editing, will it redirect to users/list page&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
6.3 &amp;quot;check if the user is available for editing, will it render users/show page&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;7. show&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
7.1 &amp;quot;check if the user id is nil or if the role is student and session id equals to id, will it redirect to home&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
7.2 &amp;quot;if the user is valid, check the return value&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;8. new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
8.1 &amp;quot;check if this will render users/new page&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;9. request_new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
9.1 &amp;quot;Here isn't any conditional sentence. So only need to check whether the return value is expected.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;10. create&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
10.1 &amp;quot;Is the name new? If yes, good. Otherwise, register the user by email address.&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
10.2 &amp;quot;Is the user's information valid? If yes, good. Otherwise, fail&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;11. create_requested_user_record&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
11.1 &amp;quot;does the user belong to any institution? If yes, good. Otherwise, set a new institution.&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
11.2 &amp;quot;is the user already existed and valid? If both yes, good. If the user already exist, send notification. If the information is not valid, fail.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;12. create_approved_user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
12.1 &amp;quot;does the request have one status? if yes and the parameters of the request are completed, good. Otherwise, submit a status, approve or reject.&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
12.2 &amp;quot;is the status Approved or Rejected?&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
12.2.1 &amp;quot;if the status is Approved, is the information valid? if yes, good. Otherwise fail&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
12.2.2 &amp;quot;if the status is Rejected, is the processing correctly? if yes, reject successfully. Otherwise, error processing request.&amp;quot;    &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;13. edit&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
13.1 &amp;quot;Here isn't any conditional sentence, so we just need to check if it renders users#edit page.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;14. update&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
14.1 &amp;quot;When user is updated successfully, it shows correct flash and redirects to users/show page.&amp;lt;br&amp;gt;&lt;br /&gt;
14.2 &amp;quot;When user is not updated successfully, it redirects to users/edit page.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;15. destroy&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
15.1 &amp;quot;When user is not deleted successfully, it shows an error and redirects to users/list page.&amp;quot; &lt;br /&gt;
     (This also covers the condition that user is deleted successfully.)&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;16. keys&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
16.1 &amp;quot;When params[:id] is not nil, @private_key gets correct value.&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
16.2 &amp;quot;When params[:id] is nil, it redirects to /tree_display/drill page.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Result ==&lt;/div&gt;</summary>
		<author><name>Srajend</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1823_Write_integration_tests_for_users_controller.rb&amp;diff=116898</id>
		<title>CSC/ECE 517 Spring 2018/E1823 Write integration tests for users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1823_Write_integration_tests_for_users_controller.rb&amp;diff=116898"/>
		<updated>2018-04-25T01:53:37Z</updated>

		<summary type="html">&lt;p&gt;Srajend: /* Methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is a description of E1813 final project for Spring 2018, CSC/ECE 517.&lt;br /&gt;
== Project Statement ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction ===&lt;br /&gt;
&lt;br /&gt;
users_controller.rb is a file under app/controllers that manages different kinds of methods related to users. This project is to write integration tests for users_controller.rb by using rspec, so our goal is to create a file named users_controller_spec.rb under spec/controllers folder and write integration tests to make the path coverage of users_controller.rb more than 90% and achieve the highest possible branch coverage.&lt;br /&gt;
&lt;br /&gt;
All methods used in this file that can render or redirect to one or more user-related views will be thoroughly tested.(16 in total) We do not need to test private or protected methods directly because these methods should be tested when testing other public methods in the same file.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
Newly-created file:&lt;br /&gt;
&lt;br /&gt;
  spec/users_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
Tested file:&lt;br /&gt;
&lt;br /&gt;
  app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
Related view files:&lt;br /&gt;
&lt;br /&gt;
  app/views/users/edit.html.erb&lt;br /&gt;
  app/views/users/keys.html.erb&lt;br /&gt;
  app/views/users/list.html.erb&lt;br /&gt;
  app/views/users/list_pending_requested.erb&lt;br /&gt;
  app/views/users/new.html.erb&lt;br /&gt;
  app/views/users/request_new.html.erb&lt;br /&gt;
  app/views/users/show.html.erb&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
1. Sandeep Rajendran(srajend@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
2. Xiao Ma(xma21@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
3. Zekun Zhang(zzhang56@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
4. Zhiyu Chen(zchen45@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
== Functionality of the Controller ==&lt;br /&gt;
=== Table ===&lt;br /&gt;
&lt;br /&gt;
Table corresponding to User model has the following attributes: (The unexplained attributes are easy to understand or doesn't make sense here)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;1. name&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. crypted_password&amp;lt;/b&amp;gt; - It is the password after encrypting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3. password_salt&amp;lt;/b&amp;gt; - It stores the information of the encryption for the password verification.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. role_id&amp;lt;/b&amp;gt; - It is used to distinguish the users as super-administrator, administrator, instructor or student.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;5. fullname&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;6. email&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;7. parent_id&amp;lt;/b&amp;gt; - For an instructor, reference to an entry in administrator table, referring the administrator who accepts for the instructor; otherwise, empty.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;8. private_by_default&amp;lt;/b&amp;gt; - It is a boolean. Assignments and questionnaire created by the instructor should be private (not visible by others) by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;9. mru_directory_path&amp;lt;/b&amp;gt; - For an instructor, the directory that (s)he was working in the previous time he used the system. This is the path-name relative to the home_directory_path. Empty for a non-instructor.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;10. email_on_review&amp;lt;/b&amp;gt; - It is a boolean value used to check whether someone else is reviewing my work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;11. email_on_submission&amp;lt;/b&amp;gt; - It is a boolean value used to check whether someone else submits work I am assigned to review.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;12. email_on_review_of_review&amp;lt;/b&amp;gt; - It is a boolean value used to check whether someone else reviews one of my reviews.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;13. is_new_user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;14. master_permission_granted&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;15. handle&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;16. digital_certificate&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;17. persistence_token&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;18. timezonepref&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;19. public_key&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;20. copy_of_emails&amp;lt;/b&amp;gt; - It is a boolean value used to check whether the system will send me copies of emails sent for assignments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;21. institution_id&amp;lt;/b&amp;gt; - Reference to an entry in institutions table, referring to the institution at which this user is registered&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&amp;lt;b&amp;gt;1. index&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to list all the users in the database. A permissions check is done first to verify that the current user has permission to view the list of users. If the user is a student, he is redirected away from the page. All other user roles have access to the page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. auto_complete_for_user_name&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The method finds all users who have names similar to the one being typed and displays only those that have a lower role than the current user. The page is rendered again showing all these suggestions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3. set_anonymized_view&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to anonymize the usernames in the views for demo purposes. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. list&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method calls the get_user_list method in the user model which returns a list of users according to the role of the user that calls the method. This list is stored in the @users instance variable which is used by the view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;5. list_pending_requested&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called to show all the requests which need to be reviewed. It first obtains all the request users and the roles. Then It will show those request_users who is under review and their details with a selection window--&amp;quot;status&amp;quot; which is used to determine if this request will be approved or rejected.   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;6. show_selection&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to show the users. It first detects if this user is valid or not. if this user is nil, it will redirect to the &amp;quot;list&amp;quot; page. If this user is valid, it will call the get_role method to get the role information of this user. and then use the role information to determine if this user is available for editing. For users available for editing, this method will render show &amp;quot;page&amp;quot;, otherwise, this method will redirect to &amp;quot;list&amp;quot; page. In summary, this method will direct to &amp;quot;show&amp;quot; page, when the user is able to be edited, otherwise, it will go to &amp;quot;list&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;7. show&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to show the details of a user. It first detect is the user is valid. There two condition for an  invalid user: 1) the id of user is nil; 2) current user role is not student and the session id doesn't equal to the user id. Otherwise this user is valid. For a valid user, it will show his/her detailed information including name, email, password, prefs, institution and self_introduction.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;8. new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when method create is used to create a new user. &lt;br /&gt;
&lt;br /&gt;
[[File:Request3.png]]&lt;br /&gt;
&lt;br /&gt;
(This image will be helpful for the next 4 methods)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;9. request_new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when a TA or instructor requests an Expertiza account. To register to use the Expertiza, one needs to be either a course TA or Instructor and then sends a request to Expertiza administrator to get approved. This function only serves TAs and instructors, and the students account will be created by instructors or TAs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;10. create&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when the user wants to create accounts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;11. create_requested_user_record&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called after the guest sending a request for the account to Expertiza administrator. After the guest sending a request for the account using request_new method, this method will store the request in the database and list all the requests on the pending_request page waiting for the administrator to operate.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;12. create_approved_user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when the Expertiza administrator deals with the guests' pending requests. By this method, the administrator can approve or decline the pending requests. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;13. edit&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;resources :users&amp;quot; in routing rule maps /users/1/edit (assuming user's id is 1) to edit action in UsersController.&lt;br /&gt;
&lt;br /&gt;
Thus, this edit method is called when accessing user's edit page and will pull the relevant user out of the database via user's id that stored in params[:id].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;14. update&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;resources :users&amp;quot; in routing rule makes update action get called when the form in user's edit page is submitted.&lt;br /&gt;
&lt;br /&gt;
This method will first find the relevant user by user's id that stored in params[:id] and then updates the user's information in the database based on the submitted params hash. If the update is successful it shows a success flash and redirects to user's show page otherwise it renders user's edit page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;15. destroy&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;resources :users&amp;quot; in routing rule makes destroy action response to the delete method and thus accomplishing the user deletion. &lt;br /&gt;
&lt;br /&gt;
When this method is called, it will first find the relevant user via user's id that stored in params[:id] and then delete related AssignmentParticipant, TeamsUser and AssignmentQuestionnaire models if any (These models are found through their foregin key: user_id). Finally, the user is deleted from the database and it will show a success flash. If any of the above steps fails, it will throw an error flash.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;16. keys&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;get :keys&amp;quot; under the collection block of &amp;quot;resources :users&amp;quot; will enable Rails to recognize paths such as /users/keys with GET, and route to the key action of UsersController.&lt;br /&gt;
&lt;br /&gt;
When this method is called, if no current user or current user is a student but is not the user stored in session, it will redirect to home page of the user stored in session. Otherwise generate_keys (a method of user model) will be called on the current user and the return value will be assigned to an instance variable @private_key defined in UsersController.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
This project aims to writing an integration test for users_controller.rb. There is no this Rspec file exist for this test, so a new test file shall be created and built from scratch. And before writing this test file, some prerequisites must be done.&lt;br /&gt;
1. Download and set the Expertiza environment&lt;br /&gt;
2. Determine which methods should be tested&lt;br /&gt;
3. Define all the conditions needed to be tested for each method&lt;br /&gt;
&lt;br /&gt;
The methods have already been introduced on above, here are the test plan for each method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;1. index&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
1.1 &amp;quot;If the user is student, we check if proper redirection is taking place&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
1.2 &amp;quot;Else, the appropriate list of users should be rendered according to the role of the current user&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. auto_complete_for_user_name&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
2.1 &amp;quot;The page should render suggestions only of those user names that are similar to the one being typed and not all user names&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3. set_anonymized_view&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
3.1 &amp;quot;The method should add the session ip to the list of anonymized ip's and redirect to the previous page &amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. list&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
4.1 &amp;quot;The @users instance variable should contain all the users that are permitted to be viewed by the current user. This will be checked for all the different user types&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;5. list_pending_requested&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
5.1 &amp;quot;check if it will render users/list_pending_requested page&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;6. show_selection&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
6.1 &amp;quot;check if the user is nil, will the page redirect to users/list page&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
6.2 &amp;quot;check if the user is not available for editing, will it redirect to users/list page&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
6.3 &amp;quot;check if the user is available for editing, will it render users/show page&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;7. show&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
7.1 &amp;quot;check if the user id is nil or if the role is student and session id equals to id, will it redirect to home&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
7.2 &amp;quot;if the user is valid, check the return value&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;8. new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
8.1 &amp;quot;check if this will render users/new page&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;9. request_new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
9.1 &amp;quot;Here isn't any conditional sentence. So only need to check whether the return value is expected.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;10. create&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
10.1 &amp;quot;Is the name new? If yes, good. Otherwise, register the user by email address.&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
10.2 &amp;quot;Is the user's information valid? If yes, good. Otherwise, fail&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;11. create_requested_user_record&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
11.1 &amp;quot;does the user belong to any institution? If yes, good. Otherwise, set a new institution.&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
11.2 &amp;quot;is the user already existed and valid? If both yes, good. If the user already exist, send notification. If the information is not valid, fail.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;12. create_approved_user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
12.1 &amp;quot;does the request have one status? if yes and the parameters of the request are completed, good. Otherwise, submit a status, approve or reject.&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
12.2 &amp;quot;is the status Approved or Rejected?&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
12.2.1 &amp;quot;if the status is Approved, is the information valid? if yes, good. Otherwise fail&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
12.2.2 &amp;quot;if the status is Rejected, is the processing correctly? if yes, reject successfully. Otherwise, error processing request.&amp;quot;    &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;13. edit&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
13.1 &amp;quot;Here isn't any conditional sentence, so we just need to check if it renders users#edit page.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;14. update&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
14.1 &amp;quot;When user is updated successfully, it shows correct flash and redirects to users/show page.&amp;lt;br&amp;gt;&lt;br /&gt;
14.2 &amp;quot;When user is not updated successfully, it redirects to users/edit page.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;15. destroy&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
15.1 &amp;quot;When user is not deleted successfully, it shows an error and redirects to users/list page.&amp;quot; &lt;br /&gt;
     (This also covers the condition that user is deleted successfully.)&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;16. keys&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
16.1 &amp;quot;When params[:id] is not nil, @private_key gets correct value.&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
16.2 &amp;quot;When params[:id] is nil, it redirects to /tree_display/drill page.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Result ==&lt;/div&gt;</summary>
		<author><name>Srajend</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1823_Write_integration_tests_for_users_controller.rb&amp;diff=116897</id>
		<title>CSC/ECE 517 Spring 2018/E1823 Write integration tests for users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1823_Write_integration_tests_for_users_controller.rb&amp;diff=116897"/>
		<updated>2018-04-25T01:52:14Z</updated>

		<summary type="html">&lt;p&gt;Srajend: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is a description of E1813 final project for Spring 2018, CSC/ECE 517.&lt;br /&gt;
== Project Statement ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction ===&lt;br /&gt;
&lt;br /&gt;
users_controller.rb is a file under app/controllers that manages different kinds of methods related to users. This project is to write integration tests for users_controller.rb by using rspec, so our goal is to create a file named users_controller_spec.rb under spec/controllers folder and write integration tests to make the path coverage of users_controller.rb more than 90% and achieve the highest possible branch coverage.&lt;br /&gt;
&lt;br /&gt;
All methods used in this file that can render or redirect to one or more user-related views will be thoroughly tested.(16 in total) We do not need to test private or protected methods directly because these methods should be tested when testing other public methods in the same file.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
Newly-created file:&lt;br /&gt;
&lt;br /&gt;
  spec/users_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
Tested file:&lt;br /&gt;
&lt;br /&gt;
  app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
Related view files:&lt;br /&gt;
&lt;br /&gt;
  app/views/users/edit.html.erb&lt;br /&gt;
  app/views/users/keys.html.erb&lt;br /&gt;
  app/views/users/list.html.erb&lt;br /&gt;
  app/views/users/list_pending_requested.erb&lt;br /&gt;
  app/views/users/new.html.erb&lt;br /&gt;
  app/views/users/request_new.html.erb&lt;br /&gt;
  app/views/users/show.html.erb&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
1. Sandeep Rajendran(srajend@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
2. Xiao Ma(xma21@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
3. Zekun Zhang(zzhang56@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
4. Zhiyu Chen(zchen45@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
== Functionality of the Controller ==&lt;br /&gt;
=== Table ===&lt;br /&gt;
&lt;br /&gt;
Table corresponding to User model has the following attributes: (The unexplained attributes are easy to understand or doesn't make sense here)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;1. name&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. crypted_password&amp;lt;/b&amp;gt; - It is the password after encrypting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3. password_salt&amp;lt;/b&amp;gt; - It stores the information of the encryption for the password verification.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. role_id&amp;lt;/b&amp;gt; - It is used to distinguish the users as super-administrator, administrator, instructor or student.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;5. fullname&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;6. email&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;7. parent_id&amp;lt;/b&amp;gt; - For an instructor, reference to an entry in administrator table, referring the administrator who accepts for the instructor; otherwise, empty.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;8. private_by_default&amp;lt;/b&amp;gt; - It is a boolean. Assignments and questionnaire created by the instructor should be private (not visible by others) by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;9. mru_directory_path&amp;lt;/b&amp;gt; - For an instructor, the directory that (s)he was working in the previous time he used the system. This is the path-name relative to the home_directory_path. Empty for a non-instructor.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;10. email_on_review&amp;lt;/b&amp;gt; - It is a boolean value used to check whether someone else is reviewing my work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;11. email_on_submission&amp;lt;/b&amp;gt; - It is a boolean value used to check whether someone else submits work I am assigned to review.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;12. email_on_review_of_review&amp;lt;/b&amp;gt; - It is a boolean value used to check whether someone else reviews one of my reviews.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;13. is_new_user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;14. master_permission_granted&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;15. handle&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;16. digital_certificate&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;17. persistence_token&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;18. timezonepref&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;19. public_key&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;20. copy_of_emails&amp;lt;/b&amp;gt; - It is a boolean value used to check whether the system will send me copies of emails sent for assignments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;21. institution_id&amp;lt;/b&amp;gt; - Reference to an entry in institutions table, referring to the institution at which this user is registered&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&amp;lt;b&amp;gt;1. index&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to list all the users in the database. A permissions check is done first to verify that the current user has permission to view the list of users. If the user is a student, he is redirected away from the page. All other user roles have access to the page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. auto_complete_for_user_name&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The method finds all users who have names similar to the one being typed and displays only those that have a lower role than the current user. The page is rendered again showing all these suggestions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. list&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method calls the get_user_list method in the user model which returns a list of users according to the role of the user that calls the method. This list is stored in the @users instance variable which is used by the view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;5. list_pending_requested&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called to show all the requests which need to be reviewed. It first obtains all the request users and the roles. Then It will show those request_users who is under review and their details with a selection window--&amp;quot;status&amp;quot; which is used to determine if this request will be approved or rejected.   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;6. show_selection&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to show the users. It first detects if this user is valid or not. if this user is nil, it will redirect to the &amp;quot;list&amp;quot; page. If this user is valid, it will call the get_role method to get the role information of this user. and then use the role information to determine if this user is available for editing. For users available for editing, this method will render show &amp;quot;page&amp;quot;, otherwise, this method will redirect to &amp;quot;list&amp;quot; page. In summary, this method will direct to &amp;quot;show&amp;quot; page, when the user is able to be edited, otherwise, it will go to &amp;quot;list&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;7. show&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to show the details of a user. It first detect is the user is valid. There two condition for an  invalid user: 1) the id of user is nil; 2) current user role is not student and the session id doesn't equal to the user id. Otherwise this user is valid. For a valid user, it will show his/her detailed information including name, email, password, prefs, institution and self_introduction.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;8. new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when method create is used to create a new user. &lt;br /&gt;
&lt;br /&gt;
[[File:Request3.png]]&lt;br /&gt;
&lt;br /&gt;
(This image will be helpful for the next 4 methods)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;9. request_new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when a TA or instructor requests an Expertiza account. To register to use the Expertiza, one needs to be either a course TA or Instructor and then sends a request to Expertiza administrator to get approved. This function only serves TAs and instructors, and the students account will be created by instructors or TAs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;10. create&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when the user wants to create accounts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;11. create_requested_user_record&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called after the guest sending a request for the account to Expertiza administrator. After the guest sending a request for the account using request_new method, this method will store the request in the database and list all the requests on the pending_request page waiting for the administrator to operate.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;12. create_approved_user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when the Expertiza administrator deals with the guests' pending requests. By this method, the administrator can approve or decline the pending requests. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;13. edit&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;resources :users&amp;quot; in routing rule maps /users/1/edit (assuming user's id is 1) to edit action in UsersController.&lt;br /&gt;
&lt;br /&gt;
Thus, this edit method is called when accessing user's edit page and will pull the relevant user out of the database via user's id that stored in params[:id].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;14. update&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;resources :users&amp;quot; in routing rule makes update action get called when the form in user's edit page is submitted.&lt;br /&gt;
&lt;br /&gt;
This method will first find the relevant user by user's id that stored in params[:id] and then updates the user's information in the database based on the submitted params hash. If the update is successful it shows a success flash and redirects to user's show page otherwise it renders user's edit page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;15. destroy&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;resources :users&amp;quot; in routing rule makes destroy action response to the delete method and thus accomplishing the user deletion. &lt;br /&gt;
&lt;br /&gt;
When this method is called, it will first find the relevant user via user's id that stored in params[:id] and then delete related AssignmentParticipant, TeamsUser and AssignmentQuestionnaire models if any (These models are found through their foregin key: user_id). Finally, the user is deleted from the database and it will show a success flash. If any of the above steps fails, it will throw an error flash.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;16. keys&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;get :keys&amp;quot; under the collection block of &amp;quot;resources :users&amp;quot; will enable Rails to recognize paths such as /users/keys with GET, and route to the key action of UsersController.&lt;br /&gt;
&lt;br /&gt;
When this method is called, if no current user or current user is a student but is not the user stored in session, it will redirect to home page of the user stored in session. Otherwise generate_keys (a method of user model) will be called on the current user and the return value will be assigned to an instance variable @private_key defined in UsersController.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
This project aims to writing an integration test for users_controller.rb. There is no this Rspec file exist for this test, so a new test file shall be created and built from scratch. And before writing this test file, some prerequisites must be done.&lt;br /&gt;
1. Download and set the Expertiza environment&lt;br /&gt;
2. Determine which methods should be tested&lt;br /&gt;
3. Define all the conditions needed to be tested for each method&lt;br /&gt;
&lt;br /&gt;
The methods have already been introduced on above, here are the test plan for each method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;1. index&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
1.1 &amp;quot;If the user is student, we check if proper redirection is taking place&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
1.2 &amp;quot;Else, the appropriate list of users should be rendered according to the role of the current user&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. auto_complete_for_user_name&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
2.1 &amp;quot;The page should render suggestions only of those user names that are similar to the one being typed and not all user names&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3. set_anonymized_view&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
3.1 &amp;quot;The method should add the session ip to the list of anonymized ip's and redirect to the previous page &amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. list&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
4.1 &amp;quot;The @users instance variable should contain all the users that are permitted to be viewed by the current user. This will be checked for all the different user types&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;5. list_pending_requested&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
5.1 &amp;quot;check if it will render users/list_pending_requested page&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;6. show_selection&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
6.1 &amp;quot;check if the user is nil, will the page redirect to users/list page&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
6.2 &amp;quot;check if the user is not available for editing, will it redirect to users/list page&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
6.3 &amp;quot;check if the user is available for editing, will it render users/show page&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;7. show&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
7.1 &amp;quot;check if the user id is nil or if the role is student and session id equals to id, will it redirect to home&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
7.2 &amp;quot;if the user is valid, check the return value&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;8. new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
8.1 &amp;quot;check if this will render users/new page&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;9. request_new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
9.1 &amp;quot;Here isn't any conditional sentence. So only need to check whether the return value is expected.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;10. create&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
10.1 &amp;quot;Is the name new? If yes, good. Otherwise, register the user by email address.&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
10.2 &amp;quot;Is the user's information valid? If yes, good. Otherwise, fail&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;11. create_requested_user_record&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
11.1 &amp;quot;does the user belong to any institution? If yes, good. Otherwise, set a new institution.&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
11.2 &amp;quot;is the user already existed and valid? If both yes, good. If the user already exist, send notification. If the information is not valid, fail.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;12. create_approved_user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
12.1 &amp;quot;does the request have one status? if yes and the parameters of the request are completed, good. Otherwise, submit a status, approve or reject.&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
12.2 &amp;quot;is the status Approved or Rejected?&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
12.2.1 &amp;quot;if the status is Approved, is the information valid? if yes, good. Otherwise fail&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
12.2.2 &amp;quot;if the status is Rejected, is the processing correctly? if yes, reject successfully. Otherwise, error processing request.&amp;quot;    &lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;13. edit&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
13.1 &amp;quot;Here isn't any conditional sentence, so we just need to check if it renders users#edit page.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;14. update&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
14.1 &amp;quot;When user is updated successfully, it shows correct flash and redirects to users/show page.&amp;lt;br&amp;gt;&lt;br /&gt;
14.2 &amp;quot;When user is not updated successfully, it redirects to users/edit page.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;15. destroy&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
15.1 &amp;quot;When user is not deleted successfully, it shows an error and redirects to users/list page.&amp;quot; &lt;br /&gt;
     (This also covers the condition that user is deleted successfully.)&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;16. keys&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
16.1 &amp;quot;When params[:id] is not nil, @private_key gets correct value.&amp;quot;&amp;lt;br&amp;gt; &lt;br /&gt;
16.2 &amp;quot;When params[:id] is nil, it redirects to /tree_display/drill page.&amp;quot;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Result ==&lt;/div&gt;</summary>
		<author><name>Srajend</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1823_Write_integration_tests_for_users_controller.rb&amp;diff=116423</id>
		<title>CSC/ECE 517 Spring 2018/E1823 Write integration tests for users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1823_Write_integration_tests_for_users_controller.rb&amp;diff=116423"/>
		<updated>2018-04-09T02:29:42Z</updated>

		<summary type="html">&lt;p&gt;Srajend: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is a description of E1813 final project for Spring 2018, CSC/ECE 517.&lt;br /&gt;
== Project Statement ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction ===&lt;br /&gt;
&lt;br /&gt;
users_controller.rb is a file under app/controllers that manages different kinds of methods related to users. This project is to write integration tests for users_controller.rb by using rspec, so our goal is to create a file named users_controller_spec.rb under spec/controllers folder and write integration tests to make the path coverage of users_controller.rb more than 90% and achieve the highest possible branch coverage.&lt;br /&gt;
&lt;br /&gt;
All methods used in this file that can render or redirect to one or more user-related views will be thoroughly tested.(16 in total) We do not need to test private or protected methods directly because these methods should be tested when testing other public methods in the same file.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
Newly-created file:&lt;br /&gt;
&lt;br /&gt;
  spec/users_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
Tested file:&lt;br /&gt;
&lt;br /&gt;
  app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
Related view files:&lt;br /&gt;
&lt;br /&gt;
  app/views/users/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
  app/views/users/keys.html.erb&lt;br /&gt;
&lt;br /&gt;
  app/views/users/list.html.erb&lt;br /&gt;
&lt;br /&gt;
  app/views/users/list_pending_requested.erb&lt;br /&gt;
&lt;br /&gt;
  app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
  app/views/users/request_new.html.erb&lt;br /&gt;
&lt;br /&gt;
  app/views/users/show.html.erb&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
1. Sandeep Rajendran(srajend@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
2. Xiao Ma(xma21@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
3. Zekun Zhang(zzhang56@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
4. Zhiyu Chen(zchen45@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
== Functionality of the Controller ==&lt;br /&gt;
=== Table ===&lt;br /&gt;
&lt;br /&gt;
Table corresponding to User model has the following attributes: (The unexplained attributes are easy to understand or doesn't make sense here)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;1. name&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. crypted_password&amp;lt;/b&amp;gt; - It is the password after encrypting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3. password_salt&amp;lt;/b&amp;gt; - It stores the information of the encryption for the password verification.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. role_id&amp;lt;/b&amp;gt; - It is used to distinguish the users as super-administrator, administrator, instructor or student.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;5. fullname&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;6. email&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;7. parent_id&amp;lt;/b&amp;gt; - For an instructor, reference to an entry in administrator table, referring the administrator who accepts for the instructor; otherwise, empty.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;8. private_by_default&amp;lt;/b&amp;gt; - It is a boolean. Assignments and questionnaire created by the instructor should be private (not visible by others) by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;9. mru_directory_path&amp;lt;/b&amp;gt; - For an instructor, the directory that (s)he was working in the previous time he used the system. This is the path-name relative to the home_directory_path. Empty for a non-instructor.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;10. email_on_review&amp;lt;/b&amp;gt; - It is a boolean value used to check whether someone else is reviewing my work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;11. email_on_submission&amp;lt;/b&amp;gt; - It is a boolean value used to check whether someone else submits work I am assigned to review.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;12. email_on_review_of_review&amp;lt;/b&amp;gt; - It is a boolean value used to check whether someone else reviews one of my reviews.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;13. is_new_user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;14. master_permission_granted&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;15. handle&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;16. digital_certificate&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;17. persistence_token&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;18. timezonepref&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;19. public_key&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;20. copy_of_emails&amp;lt;/b&amp;gt; - It is a boolean value used to check whether the system will send me copies of emails sent for assignments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;21. institution_id&amp;lt;/b&amp;gt; - Reference to an entry in institutions table, referring to the institution at which this user is registered&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&amp;lt;b&amp;gt;1. index&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to list all the users in the database. A permissions check is done first to verify that the current user has permission to view the list of users. If the user is a student, he is redirected away from the page. All other user roles have access to the page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. auto_complete_for_user_name&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The method finds all users who have names similar to the one being typed and displays only those that have a lower role than the current user. The page is rendered again showing all these suggestions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. list&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method calls the get_user_list method in the user model which returns a list of users according to the role of the user that calls the method. This list is stored in the @users instance variable which is used by the view.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;5. list_pending_requested&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called to show all the requests which need to be reviewed. It first obtains all the request users and the roles. Then It will show those request_users who is under review and their details with a selection window--&amp;quot;status&amp;quot; which is used to determine if this request will be approved or rejected.   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;6. show_selection&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to show the users. It first detects if this user is valid or not. if this user is nil, it will redirect to the &amp;quot;list&amp;quot; page. If this user is valid, it will call the get_role method to get the role information of this user. and then use the role information to determine if this user is available for editing. For users available for editing, this method will render show &amp;quot;page&amp;quot;, otherwise, this method will redirect to &amp;quot;list&amp;quot; page. In summary, this method will direct to &amp;quot;show&amp;quot; page, when the user is able to be edited, otherwise, it will go to &amp;quot;list&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;7. show&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to show the details of a user. It first detect is the user is valid. There two condition for an  invalid user: 1) the id of user is nil; 2) current user role is not student and the session id doesn't equal to the user id. Otherwise this user is valid. For a valid user, it will show his/her detailed information including name, email, password, prefs, institution and self_introduction.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;8. new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when method create is used to create a new user. &lt;br /&gt;
&lt;br /&gt;
[[File:Request_frame.png]]&lt;br /&gt;
&lt;br /&gt;
(This image will be helpful for the next 4 methods)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;9. request_new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when a TA or instructor requests an Expertiza account. To register to use the Expertiza, one needs to be either a course TA or Instructor and then sends a request to Expertiza administrator to get approved. This function only serves TAs and instructors, and the students account will be created by instructors or TAs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;10. create&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when the user wants to create accounts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;11. create_requested_user_record&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called after the guest sending a request for the account to Expertiza administrator. After the guest sending a request for the account using request_new method, this method will store the request in the database and list all the requests on the pending_request page waiting for the administrator to operate.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;12. create_approved_user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is called when the Expertiza administrator deals with the guests' pending requests. By this method, the administrator can approve or decline the pending requests. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;13. edit&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;resources :users&amp;quot; in routing rule maps /users/1/edit (assuming user's id is 1) to edit action in UsersController.&lt;br /&gt;
&lt;br /&gt;
Thus, this edit method is called when accessing user's edit page and will pull the relevant user out of the database via user's id that stored in params[:id].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;14. update&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;resources :users&amp;quot; in routing rule makes update action get called when the form in user's edit page is submitted.&lt;br /&gt;
&lt;br /&gt;
This method will first find the relevant user by user's id that stored in params[:id] and then updates the user's information in the database based on the submitted params hash. If the update is successful it shows a success flash and redirects to user's show page otherwise it renders user's edit page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;15. destroy&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;resources :users&amp;quot; in routing rule makes destroy action response to the delete method and thus accomplishing the user deletion. &lt;br /&gt;
&lt;br /&gt;
When this method is called, it will first find the relevant user via user's id that stored in params[:id] and then delete related AssignmentParticipant, TeamsUser and AssignmentQuestionnaire models if any (These models are found through their foregin key: user_id). Finally, the user is deleted from the database and it will show a success flash. If any of the above steps fails, it will throw an error flash.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;16. keys&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;get :keys&amp;quot; under the collection block of &amp;quot;resources :users&amp;quot; will enable Rails to recognize paths such as /users/keys with GET, and route to the key action of UsersController.&lt;br /&gt;
&lt;br /&gt;
When this method is called, if no current user or current user is a student but is not the user stored in session, it will redirect to home page of the user stored in session. Otherwise generate_keys (a method of user model) will be called on the current user and the return value will be assigned to an instance variable @private_key defined in UsersController.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
This project aims to writing an integration test for users_controller.rb. There is no this Rspec file exist for this test, so a new test file shall be created and built from scratch. And before writing this test file, some prerequisites must be done.&lt;br /&gt;
1. Download and set the Expertiza environment&lt;br /&gt;
2. Determine which methods should be tested&lt;br /&gt;
3. Define all the conditions needed to be tested for each method&lt;br /&gt;
&lt;br /&gt;
The methods have already been introduced on above, here are the test plan for each method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;1. index&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1.1 &amp;quot;If the user is student, we check if proper redirection is taking place&amp;quot;&lt;br /&gt;
1.2 &amp;quot;Else, the appropriate list of users should be rendered according to the role of the current user&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. auto_complete_for_user_name&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
2.1 &amp;quot;The page should render suggestions only of those user names that are similar to the one being typed and not all user names&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. list&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
4.1 &amp;quot;The @users instance variable should contain all the users that are permitted to be viewed by the current user. This will be checked for all the different user types&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;9. request_new&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
9.1 &amp;quot;Here isn't any conditional sentence. So only need to check whether the return value is expected.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;10. create&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
10.1 &amp;quot;Is the name new? If yes, good. Otherwise, register the user by email address.&amp;quot;&lt;br /&gt;
10.2 &amp;quot;Is the user's information valid? If yes, good. Otherwise, fail&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;11. create_requested_user_record&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
11.1 &amp;quot;does the user belong to any institution? If yes, good. Otherwise, set a new institution.&amp;quot;&lt;br /&gt;
11.2 &amp;quot;is the user already existed and valid? If both yes, good. If the user already exist, send notification. If the information is not valid, fail.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;12. create_approved_user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
12.1 &amp;quot;does the request have one status? if yes and the parameters of the request are completed, good. Otherwise, submit a status, approve or reject.&amp;quot;&lt;br /&gt;
12.2 &amp;quot;is the status Approved or Rejected?&amp;quot;&lt;br /&gt;
12.2.1 &amp;quot;if the status is Approved, is the information valid? if yes, good. Otherwise fail&amp;quot;&lt;br /&gt;
12.2.2 &amp;quot;if the status is Rejected, is the processing correctly? if yes, reject successfully. Otherwise, error processing request.&amp;quot;    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;13. edit&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
13.1 &amp;quot;Here isn't any conditional sentence, so we just need to check if it renders users#edit page.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;14. update&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
14.1 &amp;quot;If the attributes of users are successfully updated, check whether it shows the correct flash and redirects to users#show page after updating.&amp;quot;&lt;br /&gt;
14.2 &amp;quot;If the attributes of users are not successfully updated, check whether it renders users#edit page.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Srajend</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1823_Write_integration_tests_for_users_controller.rb&amp;diff=116177</id>
		<title>CSC/ECE 517 Spring 2018/E1823 Write integration tests for users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1823_Write_integration_tests_for_users_controller.rb&amp;diff=116177"/>
		<updated>2018-04-06T16:58:25Z</updated>

		<summary type="html">&lt;p&gt;Srajend: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is a description of E1813 final project for Spring 2018, CSC/ECE 517.&lt;br /&gt;
== Project Statement ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction ===&lt;br /&gt;
&lt;br /&gt;
users_controller.rb is a file under app/controllers that manages different kinds of methods related to users. This project is to write integration tests for users_controller.rb by using rspec, so our goal is to create a file named users_controller_spec.rb under spec/controllers folder and write integration tests to make the path coverage of users_controller.rb more than 90% and achieve the highest possible branch coverage.&lt;br /&gt;
&lt;br /&gt;
All methods used in this file that can render or redirect to one or more user-related views will be thoroughly tested.(16 in total) We do not need to test private or protected methods directly because these methods should be tested when testing other public methods in the same file.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
Newly-created file:&lt;br /&gt;
&lt;br /&gt;
  spec/users_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
Tested file:&lt;br /&gt;
&lt;br /&gt;
  app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
Related view files:&lt;br /&gt;
&lt;br /&gt;
  app/views/users/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
  app/views/users/keys.html.erb&lt;br /&gt;
&lt;br /&gt;
  app/views/users/list.html.erb&lt;br /&gt;
&lt;br /&gt;
  app/views/users/list_pending_requested.erb&lt;br /&gt;
&lt;br /&gt;
  app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
  app/views/users/request_new.html.erb&lt;br /&gt;
&lt;br /&gt;
  app/views/users/show.html.erb&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
1. Sandeep Rajendran(srajend@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
2. Xiao Ma(xma21@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
3. Zekun Zhang(zzhang56@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
4. Zhiyu Chen(zchen45@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
== Functionality of the Controller ==&lt;br /&gt;
=== Table ===&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&amp;lt;b&amp;gt;1. index&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method is used to list all the users in the database. A permissions check is done first to verify that the current user has permission to view the list of users. If the user is a student, he is redirected away from the page. All other user roles have access to the page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. auto_complete_for_user_name&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The method finds all users who have names similar to the one being typed and displays only those that have a lower role than the current user. The page is rendered again showing all these suggestions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3. set_anonymized_view&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. list&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;13. edit&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
resources :users in routing rule maps /users/1/edit (assuming user's id is 1) to edit action in UsersController.&lt;br /&gt;
&lt;br /&gt;
Thus, this edit method is called when accessing user's edit page and will pull the relevant user out of the database via user's id that stored in params[:id].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;14. update&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
resources :users in routing rule makes update action get called when the form in user's edit page is submitted.&lt;br /&gt;
&lt;br /&gt;
This method will first find the relevant user by user's id that stored in params[:id] and then updates the user's information in the database based on the submitted params hash. If the update is successful it shows a success flash and redirects to user's show page otherwise it renders user's edit page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;15. destroy&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
resources :users in routing rule makes destroy action response to the delete method and thus accomplishing the user deletion. &lt;br /&gt;
&lt;br /&gt;
When this method is called, it will first find the relevant user via user's id that stored in params[:id] and then delete related AssignmentParticipant, TeamsUser and AssignmentQuestionnaire models if any (These models are found through their foregin key: user_id). Finally, the user is deleted from the database and it will show a success flash. If any of the above steps fails, it will throw an error flash.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;16. keys&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Conditions ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Srajend</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1813_Test_Menu_Items_Model&amp;diff=115756</id>
		<title>CSC/ECE 517 Spring 2018/E1813 Test Menu Items Model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1813_Test_Menu_Items_Model&amp;diff=115756"/>
		<updated>2018-04-03T01:03:09Z</updated>

		<summary type="html">&lt;p&gt;Srajend: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1813 OSS Assignment for Spring 2018, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===Expertiza===&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source web application based on [http://rubyonrails.org/ Ruby on Rails] framework,  supported by the National Science Foundation. &lt;br /&gt;
It is a place where students can submit and peer-review learning objects (assignments, codes, write ups, websites, etc). For an instructor, expertiza allows to create and customize new or existing assignments. For students, it allows to create and work on various projects and assignments. It provides a platform to peer review other students' submissions across various document types, including the URLs and wiki pages.&lt;br /&gt;
===Test Driven-Development===&lt;br /&gt;
Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: Requirements are turned into very specific test cases, then the software is improved to pass the new tests, only. This is opposed to software development that allows software to be added that is not proven to meet requirements.&lt;br /&gt;
Test-driven development is related to the test-first programming concepts of extreme programming, begun in 1999,but more recently has created more general interest in its own right.&lt;br /&gt;
The TDD sequence can be can be summarized in following steps.&lt;br /&gt;
&lt;br /&gt;
1.Add a Test:&lt;br /&gt;
&lt;br /&gt;
TDD begins by writing succinct test cases to test each of the features. This is opposite to traditional software development paradigm where code is written first and then test cases are later written to test the application.&lt;br /&gt;
&lt;br /&gt;
2.Run all tests and see if the new test fails:&lt;br /&gt;
&lt;br /&gt;
This step validates that the test harness is working correctly, shows that the new test does not pass without requiring new code because the required behavior already exists, and it rules out the possibility that the new test is flawed and will always pass. The new test should fail for the expected reason. This step increases the developer's confidence in the new test.&lt;br /&gt;
&lt;br /&gt;
3.Write the code:&lt;br /&gt;
&lt;br /&gt;
The next step is to write the minimum amount of code that causes the test case to pass.&lt;br /&gt;
&lt;br /&gt;
4.Run tests:&lt;br /&gt;
&lt;br /&gt;
In this steps the test cases are run.If all test cases now pass, the programmer can be confident that the new code meets the test requirements, and does not break or degrade any existing features. If they do not, the new code must be adjusted until they do.&lt;br /&gt;
&lt;br /&gt;
5. Refactor code:&lt;br /&gt;
&lt;br /&gt;
In this step, refactoring of code is performed by following good design principles like removal of duplicate code, improving the readability and maintainability of the code.&lt;br /&gt;
&lt;br /&gt;
6. Repeat:&lt;br /&gt;
&lt;br /&gt;
Starting with another new test,the next step is to repeat the cycle to push the functionality forward. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Advantages of using TDD:&lt;br /&gt;
*Narrowing Problem Focus&lt;br /&gt;
*Tidier Code&lt;br /&gt;
*Not worrying about dependencies&lt;br /&gt;
*Easier refactoring&lt;br /&gt;
*Better Test coverage and fewer bugs&lt;br /&gt;
&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Unit_testing Unit Testing] is a software testing method by which individual units of source code are tested to catch errors early in the development process. For a model it involves testing the interface and on how it responds to commands and queries from outside. Model testing is bounded to the functionality of only the model under test and doesn't test how its collaborating models get affected based on this query.&lt;br /&gt;
&lt;br /&gt;
Unit Testing provides several benefits which can be summarized in the below points.&lt;br /&gt;
&lt;br /&gt;
1. Finds problems early:&lt;br /&gt;
&lt;br /&gt;
Unit testing finds problems early in the development cycle. This includes both bugs in the programmer's implementation and flaws or missing parts of the specification for the unit.&lt;br /&gt;
In test-driven development (TDD), which is frequently used in both extreme programming and scrum, unit tests are created before the code itself is written. When the tests pass, that code is considered complete.&lt;br /&gt;
&lt;br /&gt;
2. Facilitates change:&lt;br /&gt;
&lt;br /&gt;
Unit testing allows the programmer to refactor code or upgrade system libraries at a later date, and make sure the module still works correctly (e.g., in regression testing). The procedure is to write test cases for all functions and methods so that whenever a change causes a fault, it can be quickly identified. Unit tests detect changes which may break a design contract.&lt;br /&gt;
&lt;br /&gt;
3. Simplifies Integration:&lt;br /&gt;
&lt;br /&gt;
Unit testing may reduce uncertainty in the units themselves and can be used in a bottom-up testing style approach. By testing the parts of a program first and then testing the sum of its parts, integration testing becomes much easier.&lt;br /&gt;
&lt;br /&gt;
4. Documentation:&lt;br /&gt;
&lt;br /&gt;
Developers looking to learn what functionality is provided by a unit, and how to use it, can look at the unit tests to gain a basic understanding of the unit's interface's API.&lt;br /&gt;
&lt;br /&gt;
5. Design:&lt;br /&gt;
&lt;br /&gt;
When software is developed using a test-driven approach, the combination of writing the unit test to specify the interface plus the refactoring activities performed after the test is passing, may take the place of formal design. Each unit test can be seen as a design element specifying classes, methods, and observable behavior.&lt;br /&gt;
&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
&lt;br /&gt;
This project is to write unit tests using rspec for menu_items.rb model. It is to test all class and instance methods used in this file. The unit tests are to be written to make the path coverage of menu_item.rb more than 90% and achieve the highest possible branch coverage.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
The files to be understood and created are:&lt;br /&gt;
&lt;br /&gt;
1. app/models/menu_items.rb&lt;br /&gt;
&lt;br /&gt;
2. spec/models/menu_items_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
Students who collaborated to work on this problem statement are :&lt;br /&gt;
&lt;br /&gt;
1. Harish Pullagurla ( hpullag@ncsu.edu )&lt;br /&gt;
&lt;br /&gt;
2. Kalyan Ghosh (kghosh@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
3. Sandeep Rajendran(srajend@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
== Plan Of Work ==&lt;br /&gt;
&lt;br /&gt;
The task in hand was to write test cases for testing the menu_items model file. No Rspec file for the corresponding model exists so there was a need to create a new file and build tests from scratch. &lt;br /&gt;
For this purposes different sub tasks involved&lt;br /&gt;
&lt;br /&gt;
1. Setting up the Expertiza environment &lt;br /&gt;
&lt;br /&gt;
2. Understand the functionality of model file in menu_items.rb &lt;br /&gt;
&lt;br /&gt;
3. Understand the linked data attributes being used, like controller_actions, content_page, permissions_id&lt;br /&gt;
&lt;br /&gt;
4. Creating dummy entries for testing different functionalities. &lt;br /&gt;
&lt;br /&gt;
5. Writing testing conditions for different functions and cross checking with the expected outputs.&lt;br /&gt;
&lt;br /&gt;
== Implementation Steps==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza Environment Setup ===&lt;br /&gt;
The steps that we followed to set up the Expertiza environment are as follows:&lt;br /&gt;
&lt;br /&gt;
1. In the first step we installed the Virtual Box free software from Oracle in our local machines.&lt;br /&gt;
&lt;br /&gt;
2. Then we downloaded the lightweight Lubuntu image file and imported the image file into the virtualbox ubuntu environment.&lt;br /&gt;
&lt;br /&gt;
3. Then we executed the following set up commands in the terminal to set up the application in our local machine.&lt;br /&gt;
&lt;br /&gt;
Setup commands:&lt;br /&gt;
&lt;br /&gt;
*sudo su&lt;br /&gt;
*gem install bundler&lt;br /&gt;
*exit&lt;br /&gt;
*git clone [Your forked Expertiza repo url]&lt;br /&gt;
*cd expertiza&lt;br /&gt;
*bash setup.sh&lt;br /&gt;
(change config/database.yml, there is no MySQL password by default)&lt;br /&gt;
*bundle install&lt;br /&gt;
*rails server&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After successfully setting up the environment, we could LogIn to the Expertiza application using our credentials.&lt;br /&gt;
&lt;br /&gt;
To navigate to the menu_item.rb file we performed the following steps.&lt;br /&gt;
&lt;br /&gt;
1. Open terminal inside the virtual environment.&lt;br /&gt;
&lt;br /&gt;
2. Navigate to the model folder of the application by typing the following command in the terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;cd/expetiza/app/models&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Menu_item.jpg]]&lt;br /&gt;
&lt;br /&gt;
The menu_item_spec.rb test file is present in this directory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;expertiza/spec/models/&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The menu_item_spec.rb is the main file where test cases have been written.&lt;br /&gt;
&lt;br /&gt;
To navigate to the menu_item.rb file we performed the following steps.&lt;br /&gt;
&lt;br /&gt;
1. Open terminal inside the virtual environment.&lt;br /&gt;
&lt;br /&gt;
2. Navigate to the model folder of the application by typing the following command in the terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;cd/expertiza/spec/models&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Menu_item_spec.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Functionality of Menu Items model ===&lt;br /&gt;
Menu Items is a model which gives the functionality to the top menu bar in the Expertiza website. It controls the display of drop down menus and its sub menus. It directs how these drop downs are displayed with regards to different users which have different permission attributes.&lt;br /&gt;
A super admin has the permission to edit the menu bar, by adding or deleting menu item blocks from it. Upon adding each item, he gets to position it either in the main menu bar or into different sub categories.&lt;br /&gt;
&lt;br /&gt;
====Sample Views====&lt;br /&gt;
&lt;br /&gt;
Sample view of menu bar item for instructor ans student are shown below.   &lt;br /&gt;
&lt;br /&gt;
[[File:E1813 memu bar instructor.png]]&lt;br /&gt;
&lt;br /&gt;
View from a student account. &lt;br /&gt;
[[File:E1813menu bar expertiza.png]]&lt;br /&gt;
&lt;br /&gt;
====Table ====&lt;br /&gt;
Table corresponding to menu item model has the following attributes:- &lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;b&amp;gt;Label&amp;lt;/b&amp;gt; :- These attributes talk about the labeling being given to the attributes &lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;b&amp;gt;Parent id&amp;lt;/b&amp;gt; :- It tells about under which attribute does this particular attribute fall . If it is set has &amp;lt;null&amp;gt; it is the base category. &lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;b&amp;gt;Sequence id&amp;lt;/b&amp;gt; :- It gives sequence numbering for determining the way the attributes are ordered within a parent. &lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;b&amp;gt;controller action id&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
6. &amp;lt;b&amp;gt;Content page id&amp;lt;/b&amp;gt; :- These attributes tell, to which direction/ page, this selection directs the user onto.&lt;br /&gt;
&lt;br /&gt;
====Methods in the Model====&lt;br /&gt;
&lt;br /&gt;
Different instance methods and class methods exist in this models . Brief description of each of them are : - &lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;b&amp;gt;find_or_create_by_name(params)&amp;lt;/b&amp;gt; :- Class Method &lt;br /&gt;
This method finds or creates a new entry with the given name obtained in params &lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;b&amp;gt;delete&amp;lt;/b&amp;gt; :- Instance Method&lt;br /&gt;
This methods deletes the entry and all the child entries ( entries having the same parent id ) lined to it &lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;b&amp;gt;above&amp;lt;/b&amp;gt; :- Instance Method&lt;br /&gt;
It returns the entry that is above a present sequence number for a given parent id &lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;b&amp;gt;below&amp;lt;/b&amp;gt; :- Instance Method &lt;br /&gt;
It returns the entry that is below a present sequence number for a given parent id &lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;b&amp;gt;repack(repack_id)&amp;lt;/b&amp;gt; :- Class Method &lt;br /&gt;
It modifies the sequence numbers, making them in order, removing the skip entries present in it. It is performed after certain sequences have been deleted. repack_id tells the parent id under which these changes are to be made&lt;br /&gt;
&lt;br /&gt;
6. &amp;lt;b&amp;gt;next_seq(parent id)&amp;lt;/b&amp;gt; :- Class Method&lt;br /&gt;
It returns the next possible sequence id corresponding to a given parent id entries. This function would be helpful if we wish to add a new entry and find out which sequence id is to be given to it. &lt;br /&gt;
&lt;br /&gt;
7. &amp;lt;b&amp;gt;items_for_permission&amp;lt;/b&amp;gt; :- Class Method&lt;br /&gt;
It returns the set of items that are possible to be displayed for a given permission id and also based on controller action id and page id being present for it.&lt;br /&gt;
&lt;br /&gt;
=== Test Entries Creation ===&lt;br /&gt;
Mock/dummy objects are needed to be created for any unit testing criteria.These objects are loaded freshly and deleted after every testing condition. &lt;br /&gt;
&lt;br /&gt;
Several methods exist for creating such a objects, whose parameters need to be designed to satisfy the conditions under test. Using 'factories' is one such method where few of the attributes are filled in with predefined values when an created. Here, for this specific case, we haven't used, factories method as, the number of attributes were limited in menu_items model and could be filled in completely with the required values each time. &lt;br /&gt;
&lt;br /&gt;
For testing menu_items, we created required entries into the database using &amp;quot;MenuItem.new()&amp;quot; method, giving different values for each of the test inputs to cover the required testing conditions.&lt;br /&gt;
&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    @test1 = MenuItem.new(name: &amp;quot;home1&amp;quot;, parent_id: nil, seq: 1, controller_action_id: nil, content_page_id: nil, label: &amp;quot;newlabel&amp;quot;)&lt;br /&gt;
    @test1.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
The above is an example entry used for creating objects. 6 such test objects were created with entries giving combinations of parent_id and sequence numbers. &lt;br /&gt;
&lt;br /&gt;
Before each test, all the objects are created, which is done using &amp;quot;before(:each)&amp;quot; key word.&lt;br /&gt;
Also several objects of 'ControllerAction' and 'ContentPage' had to be created for testing one of the methods which acted based on those values.&lt;br /&gt;
&lt;br /&gt;
=== Testing Conditions ===&lt;br /&gt;
A total of 16 testing conditions were required to be performed for testing all the functions in menu items model file.&lt;br /&gt;
&lt;br /&gt;
The conditions that needed to be tested are as below:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;b&amp;gt;.find_or_create_by_name&amp;lt;/b&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 In this we had write unit test cases to test if the method returned a menu_item corresponding to a name.&lt;br /&gt;
 Here we expect that if the method find_or_create_by_name() is passed the parameter &amp;quot;home&amp;quot;, then it should return a value equal to &amp;quot;home&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;b&amp;gt;#delete&amp;lt;/b&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 In this test cases were written to check if the method deletes current menu items and all child menu items.&lt;br /&gt;
 In this case, if the parent menu item is deleted, all its child record should should be deleted.&lt;br /&gt;
 For our specific case, the parent and its 3 child menu_items are expected to be deleted.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;b&amp;gt;#above&amp;lt;/b&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 3.1 &amp;quot;When current menu item has parent_id, the method returns the first parent menu item by querying the parent_id and current sequence number minus one&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method above() on the active record test4, the method should return a value equal to the active record test3.&lt;br /&gt;
&lt;br /&gt;
 3.2 &amp;quot;When current menu item does not have parent_id, the method returns the first parent menu item by querying the current sequence number minus one&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method above() on the active record test5, the method should return a value equal to the active record test1.&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;b&amp;gt;#below&amp;lt;/b&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 4.1 &amp;quot;When current menu item has parent_id,the method returns the first parent menu item by querying the parent_id and current sequence number plus one&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method below() on the active record test3, the method should return a value equal to the active record test4&lt;br /&gt;
      &lt;br /&gt;
 4.2 &amp;quot;When current menu item does not have parent_id, the method returns the first parent menu item by querying the current sequence number plus one&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method below() on the active record test1, the method should return a value equal to the active record test5.&lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;b&amp;gt;.repack:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 5.1 &amp;quot;When current menu item has repack_id, the method finds all menus items with parent_id equal to repack_id and repacks the sequence number&amp;quot;.&lt;br /&gt;
      Here we expect that if the method repack() is invoked on the MenuItem and passed the value 1, &lt;br /&gt;
      then, it will repack the sequence ids and returns the list of repacked seq_ids.&lt;br /&gt;
 5.2 &amp;quot;When current menu item does not have repack_id, the method finds all menus items with parent_id null and repacks the sequence number&amp;quot;.&lt;br /&gt;
      Here we expect that if the method repack() is invoked on the MenuItem and passed the value Null, &lt;br /&gt;
      it will match all the values with parent_id = Null and returns the list of repacked seq_ids.&lt;br /&gt;
&lt;br /&gt;
6. &amp;lt;b&amp;gt;.next_seq:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 6.1 &amp;quot;When parent_id is bigger than 0, the method selects corresponding menu items with inputted parent_id and returns the next sequence number&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method next_seq() on the MenuItem and pass the value 1, the method should return a value equal to 5.&lt;br /&gt;
      &lt;br /&gt;
 6.2 &amp;quot;When parent_id is smaller than or equal to 0, the method selects corresponding menu items with parent_id null and returns the next sequence number&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method next_seq() on the MenuItem and pass the value nil, the method should return a value equal to 6.&lt;br /&gt;
&lt;br /&gt;
7. &amp;lt;b&amp;gt;.items_for_permissions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 7.1 &amp;quot;When inputted variable (permission_ids) is nil and when the controller_action_id of current item is bigger than 0 and when perms does not exist, &lt;br /&gt;
     the method returns the corresponding items&amp;quot;.&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems, &lt;br /&gt;
     then the method should return a list of active_records which satisfy the condition.&lt;br /&gt;
 7.2 &amp;quot;When the controller_action_id of current item is smaller than or equal to 0 and the content_page_id of current item is bigger than 0 and when perms does not exist, &lt;br /&gt;
     the method returns the corresponding items&amp;quot;.&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems, &lt;br /&gt;
     then the method should return a list of active_records which satisfy the condition.&lt;br /&gt;
 7.3 &amp;quot;When the controller_action_id and content_page_id of current item is smaller than or equal to 0, &lt;br /&gt;
     the method returns the corresponding items&amp;quot;.&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems, &lt;br /&gt;
     the method should return an empty list.&lt;br /&gt;
 7.4 &amp;quot;When inputted variable (permission_ids) is not nil and when the controller_action_id of current item is bigger than 0 and when perms exists, &lt;br /&gt;
     the method returns the corresponding items&amp;quot;.&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems and passed the value 1 as parameter, &lt;br /&gt;
     then the method should return a list of active_records &lt;br /&gt;
     which satisfy the condition.&lt;br /&gt;
 7.5 &amp;quot;When the controller_action_id of current item is smaller than or equal to 0 and the content_page_id of current item is bigger than 0, and when perms exists, &lt;br /&gt;
     the method returns corresponding items.&amp;quot;&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems and passed the value 1 as parameter, &lt;br /&gt;
     then the method should return a list of active_records which satisfy the condition.&lt;br /&gt;
 7.6 &amp;quot;When the controller_action_id and content_page_id of current item is smaller than or equal to 0, &lt;br /&gt;
     the method returns the corresponding items.&amp;quot;&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems and passed the value 1 as a parameter, &lt;br /&gt;
     the method should return an empty list.&lt;br /&gt;
&lt;br /&gt;
The screenshot of the actual &amp;lt;b&amp;gt;menu_item_spec.rb&amp;lt;/b&amp;gt; file is give below and the pull request can be found here[https://github.com/expertiza/expertiza/pull/1152]:&lt;br /&gt;
[[File:Menu item spec code.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Test Runs ==&lt;br /&gt;
&lt;br /&gt;
A screenshot of the tests passing is shown here&lt;br /&gt;
[[File:RunTest.jpg]]&lt;br /&gt;
&lt;br /&gt;
Screencast of a test run can be found here[https://www.youtube.com/watch?v=Acywhk_IjDY&amp;amp;feature=youtu.be]&lt;br /&gt;
&lt;br /&gt;
== Conclusion and Learning Outcomes ==&lt;br /&gt;
&lt;br /&gt;
After writing the test cases we used SimpleCov to measure the C0 coverage of our rails application.&lt;br /&gt;
In our case we did not have to install SimpleCov explicitly since it was already installed earlier.&lt;br /&gt;
After running rake spec to run the test cases, SimpleCov creates a directory called coverage in our rails application folder.&lt;br /&gt;
This folder called coverage contains an index.html file which when opened in a browser renders an html page which gives the C0 coverage of each of the files in the Controllers, Models, Helpers in the app directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The learning outcomes after performing this project can be summarized in the following points:&lt;br /&gt;
&lt;br /&gt;
1. We got an hands on experience about how to write tests following the Test Driven Development approach.&lt;br /&gt;
&lt;br /&gt;
2. We learned about how to write units tests for models and controllers in RSpec.&lt;br /&gt;
&lt;br /&gt;
3. We also learned how to understand the functionality of an already developed application.For our case, before writing the test cases for the menu_items.rb we had the understand how different models interacted with each other and how each action by different users would make changes in the database schema.&lt;br /&gt;
&lt;br /&gt;
4. We also gained a better understanding about how different tables, columns of a large applications in structured in the database schema.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/sandeep993/expertiza/tree/menu_item_branch GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;/div&gt;</summary>
		<author><name>Srajend</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1813_Test_Menu_Items_Model&amp;diff=115715</id>
		<title>CSC/ECE 517 Spring 2018/E1813 Test Menu Items Model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1813_Test_Menu_Items_Model&amp;diff=115715"/>
		<updated>2018-04-03T00:17:28Z</updated>

		<summary type="html">&lt;p&gt;Srajend: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1813 OSS Assignment for Spring 2018, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===Expertiza===&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source web application based on [http://rubyonrails.org/ Ruby on Rails] framework,  supported by the National Science Foundation. &lt;br /&gt;
It is a place where students can submit and peer-review learning objects (assignments, codes, write ups, websites, etc). For an instructor, expertiza allows to create and customize new or existing assignments. For students, it allows to create and work on various projects and assignments. It provides a platform to peer review other students' submissions across various document types, including the URLs and wiki pages.&lt;br /&gt;
===Test Driven-Development===&lt;br /&gt;
Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: Requirements are turned into very specific test cases, then the software is improved to pass the new tests, only. This is opposed to software development that allows software to be added that is not proven to meet requirements.&lt;br /&gt;
Test-driven development is related to the test-first programming concepts of extreme programming, begun in 1999,but more recently has created more general interest in its own right.&lt;br /&gt;
The TDD sequence can be can be summarized in following steps.&lt;br /&gt;
&lt;br /&gt;
1.Add a Test:&lt;br /&gt;
&lt;br /&gt;
TDD begins by writing succinct test cases to test each of the features. This is opposite to traditional software development paradigm where code is written first and then test cases are later written to test the application.&lt;br /&gt;
&lt;br /&gt;
2.Run all tests and see if the new test fails:&lt;br /&gt;
&lt;br /&gt;
This step validates that the test harness is working correctly, shows that the new test does not pass without requiring new code because the required behavior already exists, and it rules out the possibility that the new test is flawed and will always pass. The new test should fail for the expected reason. This step increases the developer's confidence in the new test.&lt;br /&gt;
&lt;br /&gt;
3.Write the code:&lt;br /&gt;
&lt;br /&gt;
The next step is to write the minimum amount of code that causes the test case to pass.&lt;br /&gt;
&lt;br /&gt;
4.Run tests:&lt;br /&gt;
&lt;br /&gt;
In this steps the test cases are run.If all test cases now pass, the programmer can be confident that the new code meets the test requirements, and does not break or degrade any existing features. If they do not, the new code must be adjusted until they do.&lt;br /&gt;
&lt;br /&gt;
5. Refactor code:&lt;br /&gt;
&lt;br /&gt;
In this step, refactoring of code is performed by following good design principles like removal of duplicate code, improving the readability and maintainability of the code.&lt;br /&gt;
&lt;br /&gt;
6. Repeat:&lt;br /&gt;
&lt;br /&gt;
Starting with another new test,the next step is to repeat the cycle to push the functionality forward. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Advantages of using TDD:&lt;br /&gt;
*Narrowing Problem Focus&lt;br /&gt;
*Tidier Code&lt;br /&gt;
*Not worrying about dependencies&lt;br /&gt;
*Easier refactoring&lt;br /&gt;
*Better Test coverage and fewer bugs&lt;br /&gt;
&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Unit_testing Unit Testing] is a software testing method by which individual units of source code are tested to catch errors early in the development process. For a model it involves testing the interface and on how it responds to commands and queries from outside. Model testing is bounded to the functionality of only the model under test and doesn't test how its collaborating models get affected based on this query.&lt;br /&gt;
&lt;br /&gt;
Unit Testing provides several benefits which can be summarized in the below points.&lt;br /&gt;
&lt;br /&gt;
1. Finds problems early:&lt;br /&gt;
&lt;br /&gt;
Unit testing finds problems early in the development cycle. This includes both bugs in the programmer's implementation and flaws or missing parts of the specification for the unit.&lt;br /&gt;
In test-driven development (TDD), which is frequently used in both extreme programming and scrum, unit tests are created before the code itself is written. When the tests pass, that code is considered complete.&lt;br /&gt;
&lt;br /&gt;
2. Facilitates change:&lt;br /&gt;
&lt;br /&gt;
Unit testing allows the programmer to refactor code or upgrade system libraries at a later date, and make sure the module still works correctly (e.g., in regression testing). The procedure is to write test cases for all functions and methods so that whenever a change causes a fault, it can be quickly identified. Unit tests detect changes which may break a design contract.&lt;br /&gt;
&lt;br /&gt;
3. Simplifies Integration:&lt;br /&gt;
&lt;br /&gt;
Unit testing may reduce uncertainty in the units themselves and can be used in a bottom-up testing style approach. By testing the parts of a program first and then testing the sum of its parts, integration testing becomes much easier.&lt;br /&gt;
&lt;br /&gt;
4. Documentation:&lt;br /&gt;
&lt;br /&gt;
Developers looking to learn what functionality is provided by a unit, and how to use it, can look at the unit tests to gain a basic understanding of the unit's interface's API.&lt;br /&gt;
&lt;br /&gt;
5. Design:&lt;br /&gt;
&lt;br /&gt;
When software is developed using a test-driven approach, the combination of writing the unit test to specify the interface plus the refactoring activities performed after the test is passing, may take the place of formal design. Each unit test can be seen as a design element specifying classes, methods, and observable behavior.&lt;br /&gt;
&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
&lt;br /&gt;
This project is to write unit tests using rspec for menu_items.rb model. It is to test all class and instance methods used in this file. The unit tests are to be written to make the path coverage of menu_item.rb more than 90% and achieve the highest possible branch coverage.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
The files to be understood and created are:&lt;br /&gt;
&lt;br /&gt;
1. app/models/menu_items.rb&lt;br /&gt;
&lt;br /&gt;
2. spec/models/menu_items_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
Students who collaborated to work on this problem statement are :&lt;br /&gt;
&lt;br /&gt;
1. Harish Pullagurla ( hpullag@ncsu.edu )&lt;br /&gt;
&lt;br /&gt;
2. Kalyan Ghosh (kghosh@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
3. Sandeep Rajendran(srajend@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
== Plan Of Work ==&lt;br /&gt;
&lt;br /&gt;
The task in hand was to write test cases for testing the menu_items model file. No Rspec file for the corresponding model exists so there was a need to create a new file and build tests from scratch. &lt;br /&gt;
For this purposes different sub tasks involved&lt;br /&gt;
&lt;br /&gt;
1. Setting up the Expertiza environment &lt;br /&gt;
&lt;br /&gt;
2. Understand the functionality of model file in menu_items.rb &lt;br /&gt;
&lt;br /&gt;
3. Understand the linked data attributes being used, like controller_actions, content_page, permissions_id&lt;br /&gt;
&lt;br /&gt;
4. Creating dummy entries for testing different functionalities. &lt;br /&gt;
&lt;br /&gt;
5. Writing testing conditions for different functions and cross checking with the expected outputs.&lt;br /&gt;
&lt;br /&gt;
== Implementation Steps==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza Environment Setup ===&lt;br /&gt;
The steps that we followed to set up the Expertiza environment are as follows:&lt;br /&gt;
&lt;br /&gt;
1. In the first step we installed the Virtual Box free software from Oracle in our local machines.&lt;br /&gt;
&lt;br /&gt;
2. Then we downloaded the lightweight Lubuntu image file and imported the image file into the virtualbox ubuntu environment.&lt;br /&gt;
&lt;br /&gt;
3. Then we executed the following set up commands in the terminal to set up the application in our local machine.&lt;br /&gt;
&lt;br /&gt;
Setup commands:&lt;br /&gt;
&lt;br /&gt;
*sudo su&lt;br /&gt;
*gem install bundler&lt;br /&gt;
*exit&lt;br /&gt;
*git clone [Your forked Expertiza repo url]&lt;br /&gt;
*cd expertiza&lt;br /&gt;
*bash setup.sh&lt;br /&gt;
(change config/database.yml, there is no MySQL password by default)&lt;br /&gt;
*bundle install&lt;br /&gt;
*rails server&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After successfully setting up the environment, we could LogIn to the Expertiza application using our credentials.&lt;br /&gt;
&lt;br /&gt;
To navigate to the menu_item.rb file we performed the following steps.&lt;br /&gt;
&lt;br /&gt;
1. Open terminal inside the virtual environment.&lt;br /&gt;
&lt;br /&gt;
2. Navigate to the model folder of the application by typing the following command in the terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;cd/expetiza/app/models&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Menu_item.jpg]]&lt;br /&gt;
&lt;br /&gt;
The menu_item_spec.rb test file is present in this directory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;expertiza/spec/models/&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The menu_item_spec.rb is the main file where test cases have been written.&lt;br /&gt;
&lt;br /&gt;
To navigate to the menu_item.rb file we performed the following steps.&lt;br /&gt;
&lt;br /&gt;
1. Open terminal inside the virtual environment.&lt;br /&gt;
&lt;br /&gt;
2. Navigate to the model folder of the application by typing the following command in the terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;cd/expertiza/spec/models&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Menu_item_spec.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Functionality of Menu Items model ===&lt;br /&gt;
Menu Items is a model which gives the functionality to the top menu bar in the Expertiza website. It controls the display of drop down menus and its sub menus. It directs how these drop downs are displayed with regards to different users which have different permission attributes.&lt;br /&gt;
A super admin has the permission to edit the menu bar, by adding or deleting menu item blocks from it. Upon adding each item, he gets to position it either in the main menu bar or into different sub categories.&lt;br /&gt;
&lt;br /&gt;
====Sample Views====&lt;br /&gt;
&lt;br /&gt;
Sample view of menu bar item for instructor ans student are shown below.   &lt;br /&gt;
&lt;br /&gt;
[[File:E1813 memu bar instructor.png]]&lt;br /&gt;
&lt;br /&gt;
View from a student account. &lt;br /&gt;
[[File:E1813menu bar expertiza.png]]&lt;br /&gt;
&lt;br /&gt;
====Table ====&lt;br /&gt;
Table corresponding to menu item model has the following attributes:- &lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;b&amp;gt;Label&amp;lt;/b&amp;gt; :- These attributes talk about the labeling being given to the attributes &lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;b&amp;gt;Parent id&amp;lt;/b&amp;gt; :- It tells about under which attribute does this particular attribute fall . If it is set has &amp;lt;null&amp;gt; it is the base category. &lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;b&amp;gt;Sequence id&amp;lt;/b&amp;gt; :- It gives sequence numbering for determining the way the attributes are ordered within a parent. &lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;b&amp;gt;controller action id&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
6. &amp;lt;b&amp;gt;Content page id&amp;lt;/b&amp;gt; :- These attributes tell, to which direction/ page, this selection directs the user onto.&lt;br /&gt;
&lt;br /&gt;
====Methods in the Model====&lt;br /&gt;
&lt;br /&gt;
Different instance methods and class methods exist in this models . Brief description of each of them are : - &lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;b&amp;gt;find_or_create_by_name(params)&amp;lt;/b&amp;gt; :- Class Method &lt;br /&gt;
This method finds or creates a new entry with the given name obtained in params &lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;b&amp;gt;delete&amp;lt;/b&amp;gt; :- Instance Method&lt;br /&gt;
This methods deletes the entry and all the child entries ( entries having the same parent id ) lined to it &lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;b&amp;gt;above&amp;lt;/b&amp;gt; :- Instance Method&lt;br /&gt;
It returns the entry that is above a present sequence number for a given parent id &lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;b&amp;gt;below&amp;lt;/b&amp;gt; :- Instance Method &lt;br /&gt;
It returns the entry that is below a present sequence number for a given parent id &lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;b&amp;gt;repack(repack_id)&amp;lt;/b&amp;gt; :- Class Method &lt;br /&gt;
It modifies the sequence numbers, making them in order, removing the skip entries present in it. It is performed after certain sequences have been deleted. repack_id tells the parent id under which these changes are to be made&lt;br /&gt;
&lt;br /&gt;
6. &amp;lt;b&amp;gt;next_seq(parent id)&amp;lt;/b&amp;gt; :- Class Method&lt;br /&gt;
It returns the next possible sequence id corresponding to a given parent id entries. This function would be helpful if we wish to add a new entry and find out which sequence id is to be given to it. &lt;br /&gt;
&lt;br /&gt;
7. &amp;lt;b&amp;gt;items_for_permission&amp;lt;/b&amp;gt; :- Class Method&lt;br /&gt;
It returns the set of items that are possible to be displayed for a given permission id and also based on controller action id and page id being present for it.&lt;br /&gt;
&lt;br /&gt;
=== Test Entries Creation ===&lt;br /&gt;
Mock/dummy objects are needed to be created for any unit testing criteria.These objects are loaded freshly and deleted after every testing condition. &lt;br /&gt;
&lt;br /&gt;
Several methods exist for creating such a objects, whose parameters need to be designed to satisfy the conditions under test. Using 'factories' is one such method where few of the attributes are filled in with predefined values when an created. Here, for this specific case, we haven't used, factories method as, the number of attributes were limited in menu_items model and could be filled in completely with the required values each time. &lt;br /&gt;
&lt;br /&gt;
For testing menu_items, we created required entries into the database using &amp;quot;MenuItem.new()&amp;quot; method, giving different values for each of the test inputs to cover the required testing conditions.&lt;br /&gt;
&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    @test1 = MenuItem.new(name: &amp;quot;home1&amp;quot;, parent_id: nil, seq: 1, controller_action_id: nil, content_page_id: nil, label: &amp;quot;newlabel&amp;quot;)&lt;br /&gt;
    @test1.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
The above is an example entry used for creating objects. 6 such test objects were created with entries giving combinations of parent_id and sequence numbers. &lt;br /&gt;
&lt;br /&gt;
Before each test, all the objects are created, which is done using &amp;quot;before(:each)&amp;quot; key word.&lt;br /&gt;
Also several objects of 'ControllerAction' and 'ContentPage' had to be created for testing one of the methods which acted based on those values.&lt;br /&gt;
&lt;br /&gt;
=== Testing Conditions ===&lt;br /&gt;
A total of 16 testing conditions were required to be performed for testing all the functions in menu items model file.&lt;br /&gt;
&lt;br /&gt;
The conditions that needed to be tested are as below:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;b&amp;gt;.find_or_create_by_name&amp;lt;/b&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 In this we had write unit test cases to test if the method returned a menu_item corresponding to a name.&lt;br /&gt;
 Here we expect that if the method find_or_create_by_name() is passed the parameter &amp;quot;home&amp;quot;, then it should return a value equal to &amp;quot;home&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;b&amp;gt;#delete&amp;lt;/b&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 In this test cases were written to check if the method deletes current menu items and all child menu items.&lt;br /&gt;
 In this case, if the parent menu item is deleted, all its child record should should be deleted.&lt;br /&gt;
 For our specific case, the parent and its 3 child menu_items are expected to be deleted.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;b&amp;gt;#above&amp;lt;/b&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 3.1 &amp;quot;When current menu item has parent_id, the method returns the first parent menu item by querying the parent_id and current sequence number minus one&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method above() on the active record test4, the method should return a value equal to the active record test3.&lt;br /&gt;
&lt;br /&gt;
 3.2 &amp;quot;When current menu item does not have parent_id, the method returns the first parent menu item by querying the current sequence number minus one&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method above() on the active record test5, the method should return a value equal to the active record test1.&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;b&amp;gt;#below&amp;lt;/b&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 4.1 &amp;quot;When current menu item has parent_id,the method returns the first parent menu item by querying the parent_id and current sequence number plus one&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method below() on the active record test3, the method should return a value equal to the active record test4&lt;br /&gt;
      &lt;br /&gt;
 4.2 &amp;quot;When current menu item does not have parent_id, the method returns the first parent menu item by querying the current sequence number plus one&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method below() on the active record test1, the method should return a value equal to the active record test5.&lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;b&amp;gt;.repack:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 5.1 &amp;quot;When current menu item has repack_id, the method finds all menus items with parent_id equal to repack_id and repacks the sequence number&amp;quot;.&lt;br /&gt;
      Here we expect that if the method repack() is invoked on the MenuItem and passed the value 1, &lt;br /&gt;
      then, it will repack the sequence ids and returns the list of repacked seq_ids.&lt;br /&gt;
 5.2 &amp;quot;When current menu item does not have repack_id, the method finds all menus items with parent_id null and repacks the sequence number&amp;quot;.&lt;br /&gt;
      Here we expect that if the method repack() is invoked on the MenuItem and passed the value Null, &lt;br /&gt;
      it will match all the values with parent_id = Null and returns the list of repacked seq_ids.&lt;br /&gt;
&lt;br /&gt;
6. &amp;lt;b&amp;gt;.next_seq:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 6.1 &amp;quot;When parent_id is bigger than 0, the method selects corresponding menu items with inputted parent_id and returns the next sequence number&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method next_seq() on the MenuItem and pass the value 1, the method should return a value equal to 5.&lt;br /&gt;
      &lt;br /&gt;
 6.2 &amp;quot;When parent_id is smaller than or equal to 0, the method selects corresponding menu items with parent_id null and returns the next sequence number&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method next_seq() on the MenuItem and pass the value nil, the method should return a value equal to 6.&lt;br /&gt;
&lt;br /&gt;
7. &amp;lt;b&amp;gt;.items_for_permissions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 7.1 &amp;quot;When inputted variable (permission_ids) is nil and when the controller_action_id of current item is bigger than 0 and when perms does not exist, &lt;br /&gt;
     the method returns the corresponding items&amp;quot;.&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems, &lt;br /&gt;
     then the method should return a list of active_records which satisfy the condition.&lt;br /&gt;
 7.2 &amp;quot;When the controller_action_id of current item is smaller than or equal to 0 and the content_page_id of current item is bigger than 0 and when perms does not exist, &lt;br /&gt;
     the method returns the corresponding items&amp;quot;.&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems, &lt;br /&gt;
     then the method should return a list of active_records which satisfy the condition.&lt;br /&gt;
 7.3 &amp;quot;When the controller_action_id and content_page_id of current item is smaller than or equal to 0, &lt;br /&gt;
     the method returns the corresponding items&amp;quot;.&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems, &lt;br /&gt;
     the method should return an empty list.&lt;br /&gt;
 7.4 &amp;quot;When inputted variable (permission_ids) is not nil and when the controller_action_id of current item is bigger than 0 and when perms exists, &lt;br /&gt;
     the method returns the corresponding items&amp;quot;.&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems and passed the value 1 as parameter, &lt;br /&gt;
     then the method should return a list of active_records &lt;br /&gt;
     which satisfy the condition.&lt;br /&gt;
 7.5 &amp;quot;When the controller_action_id of current item is smaller than or equal to 0 and the content_page_id of current item is bigger than 0, and when perms exists, &lt;br /&gt;
     the method returns corresponding items.&amp;quot;&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems and passed the value 1 as parameter, &lt;br /&gt;
     then the method should return a list of active_records which satisfy the condition.&lt;br /&gt;
 7.6 &amp;quot;When the controller_action_id and content_page_id of current item is smaller than or equal to 0, &lt;br /&gt;
     the method returns the corresponding items.&amp;quot;&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems and passed the value 1 as a parameter, &lt;br /&gt;
     the method should return an empty list.&lt;br /&gt;
&lt;br /&gt;
The screenshot of the actual &amp;lt;b&amp;gt;menu_item_spec.rb&amp;lt;/b&amp;gt; file is give below:&lt;br /&gt;
[[File:Menu item spec code.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Test Runs ==&lt;br /&gt;
&lt;br /&gt;
A screenshot of the tests passing is shown here&lt;br /&gt;
[[File:RunTest.jpg]]&lt;br /&gt;
&lt;br /&gt;
Screencast of a test run can be found here[https://www.youtube.com/watch?v=Acywhk_IjDY&amp;amp;feature=youtu.be]&lt;br /&gt;
&lt;br /&gt;
== Conclusion and Learning Outcomes ==&lt;br /&gt;
&lt;br /&gt;
After writing the test cases we used SimpleCov to measure the C0 coverage of our rails application.&lt;br /&gt;
In our case we did not have to install SimpleCov explicitly since it was already installed earlier.&lt;br /&gt;
After running rake spec to run the test cases, SimpleCov creates a directory called coverage in our rails application folder.&lt;br /&gt;
This folder called coverage contains an index.html file which when opened in a browser renders an html page which gives the C0 coverage of each of the files in the Controllers, Models, Helpers in the app directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The learning outcomes after performing this project can be summarized in the following points:&lt;br /&gt;
&lt;br /&gt;
1. We got an hands on experience about how to write tests following the Test Driven Development approach.&lt;br /&gt;
&lt;br /&gt;
2. We learned about how to write units tests for models and controllers in RSpec.&lt;br /&gt;
&lt;br /&gt;
3. We also learned how to understand the functionality of an already developed application.For our case, before writing the test cases for the menu_items.rb we had the understand how different models interacted with each other and how each action by different users would make changes in the database schema.&lt;br /&gt;
&lt;br /&gt;
4. We also gained a better understanding about how different tables, columns of a large applications in structured in the database schema.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/sandeep993/expertiza/tree/menu_item_branch GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;/div&gt;</summary>
		<author><name>Srajend</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:RunTest.jpg&amp;diff=115707</id>
		<title>File:RunTest.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:RunTest.jpg&amp;diff=115707"/>
		<updated>2018-04-03T00:15:18Z</updated>

		<summary type="html">&lt;p&gt;Srajend: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Srajend</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1813_Test_Menu_Items_Model&amp;diff=115702</id>
		<title>CSC/ECE 517 Spring 2018/E1813 Test Menu Items Model</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2018/E1813_Test_Menu_Items_Model&amp;diff=115702"/>
		<updated>2018-04-03T00:13:47Z</updated>

		<summary type="html">&lt;p&gt;Srajend: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page is for the description of changes made under E1813 OSS Assignment for Spring 2018, CSC/ECE 517.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===Expertiza===&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source web application based on [http://rubyonrails.org/ Ruby on Rails] framework,  supported by the National Science Foundation. &lt;br /&gt;
It is a place where students can submit and peer-review learning objects (assignments, codes, write ups, websites, etc). For an instructor, expertiza allows to create and customize new or existing assignments. For students, it allows to create and work on various projects and assignments. It provides a platform to peer review other students' submissions across various document types, including the URLs and wiki pages.&lt;br /&gt;
===Test Driven-Development===&lt;br /&gt;
Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: Requirements are turned into very specific test cases, then the software is improved to pass the new tests, only. This is opposed to software development that allows software to be added that is not proven to meet requirements.&lt;br /&gt;
Test-driven development is related to the test-first programming concepts of extreme programming, begun in 1999,but more recently has created more general interest in its own right.&lt;br /&gt;
The TDD sequence can be can be summarized in following steps.&lt;br /&gt;
&lt;br /&gt;
1.Add a Test:&lt;br /&gt;
&lt;br /&gt;
TDD begins by writing succinct test cases to test each of the features. This is opposite to traditional software development paradigm where code is written first and then test cases are later written to test the application.&lt;br /&gt;
&lt;br /&gt;
2.Run all tests and see if the new test fails:&lt;br /&gt;
&lt;br /&gt;
This step validates that the test harness is working correctly, shows that the new test does not pass without requiring new code because the required behavior already exists, and it rules out the possibility that the new test is flawed and will always pass. The new test should fail for the expected reason. This step increases the developer's confidence in the new test.&lt;br /&gt;
&lt;br /&gt;
3.Write the code:&lt;br /&gt;
&lt;br /&gt;
The next step is to write the minimum amount of code that causes the test case to pass.&lt;br /&gt;
&lt;br /&gt;
4.Run tests:&lt;br /&gt;
&lt;br /&gt;
In this steps the test cases are run.If all test cases now pass, the programmer can be confident that the new code meets the test requirements, and does not break or degrade any existing features. If they do not, the new code must be adjusted until they do.&lt;br /&gt;
&lt;br /&gt;
5. Refactor code:&lt;br /&gt;
&lt;br /&gt;
In this step, refactoring of code is performed by following good design principles like removal of duplicate code, improving the readability and maintainability of the code.&lt;br /&gt;
&lt;br /&gt;
6. Repeat:&lt;br /&gt;
&lt;br /&gt;
Starting with another new test,the next step is to repeat the cycle to push the functionality forward. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Advantages of using TDD:&lt;br /&gt;
*Narrowing Problem Focus&lt;br /&gt;
*Tidier Code&lt;br /&gt;
*Not worrying about dependencies&lt;br /&gt;
*Easier refactoring&lt;br /&gt;
*Better Test coverage and fewer bugs&lt;br /&gt;
&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
[https://en.wikipedia.org/wiki/Unit_testing Unit Testing] is a software testing method by which individual units of source code are tested to catch errors early in the development process. For a model it involves testing the interface and on how it responds to commands and queries from outside. Model testing is bounded to the functionality of only the model under test and doesn't test how its collaborating models get affected based on this query.&lt;br /&gt;
&lt;br /&gt;
Unit Testing provides several benefits which can be summarized in the below points.&lt;br /&gt;
&lt;br /&gt;
1. Finds problems early:&lt;br /&gt;
&lt;br /&gt;
Unit testing finds problems early in the development cycle. This includes both bugs in the programmer's implementation and flaws or missing parts of the specification for the unit.&lt;br /&gt;
In test-driven development (TDD), which is frequently used in both extreme programming and scrum, unit tests are created before the code itself is written. When the tests pass, that code is considered complete.&lt;br /&gt;
&lt;br /&gt;
2. Facilitates change:&lt;br /&gt;
&lt;br /&gt;
Unit testing allows the programmer to refactor code or upgrade system libraries at a later date, and make sure the module still works correctly (e.g., in regression testing). The procedure is to write test cases for all functions and methods so that whenever a change causes a fault, it can be quickly identified. Unit tests detect changes which may break a design contract.&lt;br /&gt;
&lt;br /&gt;
3. Simplifies Integration:&lt;br /&gt;
&lt;br /&gt;
Unit testing may reduce uncertainty in the units themselves and can be used in a bottom-up testing style approach. By testing the parts of a program first and then testing the sum of its parts, integration testing becomes much easier.&lt;br /&gt;
&lt;br /&gt;
4. Documentation:&lt;br /&gt;
&lt;br /&gt;
Developers looking to learn what functionality is provided by a unit, and how to use it, can look at the unit tests to gain a basic understanding of the unit's interface's API.&lt;br /&gt;
&lt;br /&gt;
5. Design:&lt;br /&gt;
&lt;br /&gt;
When software is developed using a test-driven approach, the combination of writing the unit test to specify the interface plus the refactoring activities performed after the test is passing, may take the place of formal design. Each unit test can be seen as a design element specifying classes, methods, and observable behavior.&lt;br /&gt;
&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
&lt;br /&gt;
This project is to write unit tests using rspec for menu_items.rb model. It is to test all class and instance methods used in this file. The unit tests are to be written to make the path coverage of menu_item.rb more than 90% and achieve the highest possible branch coverage.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
The files to be understood and created are:&lt;br /&gt;
&lt;br /&gt;
1. app/models/menu_items.rb&lt;br /&gt;
&lt;br /&gt;
2. spec/models/menu_items_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
Students who collaborated to work on this problem statement are :&lt;br /&gt;
&lt;br /&gt;
1. Harish Pullagurla ( hpullag@ncsu.edu )&lt;br /&gt;
&lt;br /&gt;
2. Kalyan Ghosh (kghosh@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
3. Sandeep Rajendran(srajend@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
== Plan Of Work ==&lt;br /&gt;
&lt;br /&gt;
The task in hand was to write test cases for testing the menu_items model file. No Rspec file for the corresponding model exists so there was a need to create a new file and build tests from scratch. &lt;br /&gt;
For this purposes different sub tasks involved&lt;br /&gt;
&lt;br /&gt;
1. Setting up the Expertiza environment &lt;br /&gt;
&lt;br /&gt;
2. Understand the functionality of model file in menu_items.rb &lt;br /&gt;
&lt;br /&gt;
3. Understand the linked data attributes being used, like controller_actions, content_page, permissions_id&lt;br /&gt;
&lt;br /&gt;
4. Creating dummy entries for testing different functionalities. &lt;br /&gt;
&lt;br /&gt;
5. Writing testing conditions for different functions and cross checking with the expected outputs.&lt;br /&gt;
&lt;br /&gt;
== Implementation Steps==&lt;br /&gt;
&lt;br /&gt;
=== Expertiza Environment Setup ===&lt;br /&gt;
The steps that we followed to set up the Expertiza environment are as follows:&lt;br /&gt;
&lt;br /&gt;
1. In the first step we installed the Virtual Box free software from Oracle in our local machines.&lt;br /&gt;
&lt;br /&gt;
2. Then we downloaded the lightweight Lubuntu image file and imported the image file into the virtualbox ubuntu environment.&lt;br /&gt;
&lt;br /&gt;
3. Then we executed the following set up commands in the terminal to set up the application in our local machine.&lt;br /&gt;
&lt;br /&gt;
Setup commands:&lt;br /&gt;
&lt;br /&gt;
*sudo su&lt;br /&gt;
*gem install bundler&lt;br /&gt;
*exit&lt;br /&gt;
*git clone [Your forked Expertiza repo url]&lt;br /&gt;
*cd expertiza&lt;br /&gt;
*bash setup.sh&lt;br /&gt;
(change config/database.yml, there is no MySQL password by default)&lt;br /&gt;
*bundle install&lt;br /&gt;
*rails server&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After successfully setting up the environment, we could LogIn to the Expertiza application using our credentials.&lt;br /&gt;
&lt;br /&gt;
To navigate to the menu_item.rb file we performed the following steps.&lt;br /&gt;
&lt;br /&gt;
1. Open terminal inside the virtual environment.&lt;br /&gt;
&lt;br /&gt;
2. Navigate to the model folder of the application by typing the following command in the terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;cd/expetiza/app/models&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Menu_item.jpg]]&lt;br /&gt;
&lt;br /&gt;
The menu_item_spec.rb test file is present in this directory&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;expertiza/spec/models/&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The menu_item_spec.rb is the main file where test cases have been written.&lt;br /&gt;
&lt;br /&gt;
To navigate to the menu_item.rb file we performed the following steps.&lt;br /&gt;
&lt;br /&gt;
1. Open terminal inside the virtual environment.&lt;br /&gt;
&lt;br /&gt;
2. Navigate to the model folder of the application by typing the following command in the terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;cd/expertiza/spec/models&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Menu_item_spec.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Functionality of Menu Items model ===&lt;br /&gt;
Menu Items is a model which gives the functionality to the top menu bar in the Expertiza website. It controls the display of drop down menus and its sub menus. It directs how these drop downs are displayed with regards to different users which have different permission attributes.&lt;br /&gt;
A super admin has the permission to edit the menu bar, by adding or deleting menu item blocks from it. Upon adding each item, he gets to position it either in the main menu bar or into different sub categories.&lt;br /&gt;
&lt;br /&gt;
====Sample Views====&lt;br /&gt;
&lt;br /&gt;
Sample view of menu bar item for instructor ans student are shown below.   &lt;br /&gt;
&lt;br /&gt;
[[File:E1813 memu bar instructor.png]]&lt;br /&gt;
&lt;br /&gt;
View from a student account. &lt;br /&gt;
[[File:E1813menu bar expertiza.png]]&lt;br /&gt;
&lt;br /&gt;
====Table ====&lt;br /&gt;
Table corresponding to menu item model has the following attributes:- &lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;b&amp;gt;Label&amp;lt;/b&amp;gt; :- These attributes talk about the labeling being given to the attributes &lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;b&amp;gt;Parent id&amp;lt;/b&amp;gt; :- It tells about under which attribute does this particular attribute fall . If it is set has &amp;lt;null&amp;gt; it is the base category. &lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;b&amp;gt;Sequence id&amp;lt;/b&amp;gt; :- It gives sequence numbering for determining the way the attributes are ordered within a parent. &lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;b&amp;gt;controller action id&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
6. &amp;lt;b&amp;gt;Content page id&amp;lt;/b&amp;gt; :- These attributes tell, to which direction/ page, this selection directs the user onto.&lt;br /&gt;
&lt;br /&gt;
====Methods in the Model====&lt;br /&gt;
&lt;br /&gt;
Different instance methods and class methods exist in this models . Brief description of each of them are : - &lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;b&amp;gt;find_or_create_by_name(params)&amp;lt;/b&amp;gt; :- Class Method &lt;br /&gt;
This method finds or creates a new entry with the given name obtained in params &lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;b&amp;gt;delete&amp;lt;/b&amp;gt; :- Instance Method&lt;br /&gt;
This methods deletes the entry and all the child entries ( entries having the same parent id ) lined to it &lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;b&amp;gt;above&amp;lt;/b&amp;gt; :- Instance Method&lt;br /&gt;
It returns the entry that is above a present sequence number for a given parent id &lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;b&amp;gt;below&amp;lt;/b&amp;gt; :- Instance Method &lt;br /&gt;
It returns the entry that is below a present sequence number for a given parent id &lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;b&amp;gt;repack(repack_id)&amp;lt;/b&amp;gt; :- Class Method &lt;br /&gt;
It modifies the sequence numbers, making them in order, removing the skip entries present in it. It is performed after certain sequences have been deleted. repack_id tells the parent id under which these changes are to be made&lt;br /&gt;
&lt;br /&gt;
6. &amp;lt;b&amp;gt;next_seq(parent id)&amp;lt;/b&amp;gt; :- Class Method&lt;br /&gt;
It returns the next possible sequence id corresponding to a given parent id entries. This function would be helpful if we wish to add a new entry and find out which sequence id is to be given to it. &lt;br /&gt;
&lt;br /&gt;
7. &amp;lt;b&amp;gt;items_for_permission&amp;lt;/b&amp;gt; :- Class Method&lt;br /&gt;
It returns the set of items that are possible to be displayed for a given permission id and also based on controller action id and page id being present for it.&lt;br /&gt;
&lt;br /&gt;
=== Test Entries Creation ===&lt;br /&gt;
Mock/dummy objects are needed to be created for any unit testing criteria.These objects are loaded freshly and deleted after every testing condition. &lt;br /&gt;
&lt;br /&gt;
Several methods exist for creating such a objects, whose parameters need to be designed to satisfy the conditions under test. Using 'factories' is one such method where few of the attributes are filled in with predefined values when an created. Here, for this specific case, we haven't used, factories method as, the number of attributes were limited in menu_items model and could be filled in completely with the required values each time. &lt;br /&gt;
&lt;br /&gt;
For testing menu_items, we created required entries into the database using &amp;quot;MenuItem.new()&amp;quot; method, giving different values for each of the test inputs to cover the required testing conditions.&lt;br /&gt;
&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    @test1 = MenuItem.new(name: &amp;quot;home1&amp;quot;, parent_id: nil, seq: 1, controller_action_id: nil, content_page_id: nil, label: &amp;quot;newlabel&amp;quot;)&lt;br /&gt;
    @test1.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
The above is an example entry used for creating objects. 6 such test objects were created with entries giving combinations of parent_id and sequence numbers. &lt;br /&gt;
&lt;br /&gt;
Before each test, all the objects are created, which is done using &amp;quot;before(:each)&amp;quot; key word.&lt;br /&gt;
Also several objects of 'ControllerAction' and 'ContentPage' had to be created for testing one of the methods which acted based on those values.&lt;br /&gt;
&lt;br /&gt;
=== Testing Conditions ===&lt;br /&gt;
A total of 16 testing conditions were required to be performed for testing all the functions in menu items model file.&lt;br /&gt;
&lt;br /&gt;
The conditions that needed to be tested are as below:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;b&amp;gt;.find_or_create_by_name&amp;lt;/b&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 In this we had write unit test cases to test if the method returned a menu_item corresponding to a name.&lt;br /&gt;
 Here we expect that if the method find_or_create_by_name() is passed the parameter &amp;quot;home&amp;quot;, then it should return a value equal to &amp;quot;home&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;b&amp;gt;#delete&amp;lt;/b&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 In this test cases were written to check if the method deletes current menu items and all child menu items.&lt;br /&gt;
 In this case, if the parent menu item is deleted, all its child record should should be deleted.&lt;br /&gt;
 For our specific case, the parent and its 3 child menu_items are expected to be deleted.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;b&amp;gt;#above&amp;lt;/b&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 3.1 &amp;quot;When current menu item has parent_id, the method returns the first parent menu item by querying the parent_id and current sequence number minus one&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method above() on the active record test4, the method should return a value equal to the active record test3.&lt;br /&gt;
&lt;br /&gt;
 3.2 &amp;quot;When current menu item does not have parent_id, the method returns the first parent menu item by querying the current sequence number minus one&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method above() on the active record test5, the method should return a value equal to the active record test1.&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;b&amp;gt;#below&amp;lt;/b&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 4.1 &amp;quot;When current menu item has parent_id,the method returns the first parent menu item by querying the parent_id and current sequence number plus one&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method below() on the active record test3, the method should return a value equal to the active record test4&lt;br /&gt;
      &lt;br /&gt;
 4.2 &amp;quot;When current menu item does not have parent_id, the method returns the first parent menu item by querying the current sequence number plus one&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method below() on the active record test1, the method should return a value equal to the active record test5.&lt;br /&gt;
&lt;br /&gt;
5. &amp;lt;b&amp;gt;.repack:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 5.1 &amp;quot;When current menu item has repack_id, the method finds all menus items with parent_id equal to repack_id and repacks the sequence number&amp;quot;.&lt;br /&gt;
      Here we expect that if the method repack() is invoked on the MenuItem and passed the value 1, &lt;br /&gt;
      then, it will repack the sequence ids and returns the list of repacked seq_ids.&lt;br /&gt;
 5.2 &amp;quot;When current menu item does not have repack_id, the method finds all menus items with parent_id null and repacks the sequence number&amp;quot;.&lt;br /&gt;
      Here we expect that if the method repack() is invoked on the MenuItem and passed the value Null, &lt;br /&gt;
      it will match all the values with parent_id = Null and returns the list of repacked seq_ids.&lt;br /&gt;
&lt;br /&gt;
6. &amp;lt;b&amp;gt;.next_seq:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 6.1 &amp;quot;When parent_id is bigger than 0, the method selects corresponding menu items with inputted parent_id and returns the next sequence number&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method next_seq() on the MenuItem and pass the value 1, the method should return a value equal to 5.&lt;br /&gt;
      &lt;br /&gt;
 6.2 &amp;quot;When parent_id is smaller than or equal to 0, the method selects corresponding menu items with parent_id null and returns the next sequence number&amp;quot;.&lt;br /&gt;
      Here we expect that if we invoke the method next_seq() on the MenuItem and pass the value nil, the method should return a value equal to 6.&lt;br /&gt;
&lt;br /&gt;
7. &amp;lt;b&amp;gt;.items_for_permissions:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test cases were written to check if the below conditions are satisfied:&lt;br /&gt;
&lt;br /&gt;
 7.1 &amp;quot;When inputted variable (permission_ids) is nil and when the controller_action_id of current item is bigger than 0 and when perms does not exist, &lt;br /&gt;
     the method returns the corresponding items&amp;quot;.&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems, &lt;br /&gt;
     then the method should return a list of active_records which satisfy the condition.&lt;br /&gt;
 7.2 &amp;quot;When the controller_action_id of current item is smaller than or equal to 0 and the content_page_id of current item is bigger than 0 and when perms does not exist, &lt;br /&gt;
     the method returns the corresponding items&amp;quot;.&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems, &lt;br /&gt;
     then the method should return a list of active_records which satisfy the condition.&lt;br /&gt;
 7.3 &amp;quot;When the controller_action_id and content_page_id of current item is smaller than or equal to 0, &lt;br /&gt;
     the method returns the corresponding items&amp;quot;.&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems, &lt;br /&gt;
     the method should return an empty list.&lt;br /&gt;
 7.4 &amp;quot;When inputted variable (permission_ids) is not nil and when the controller_action_id of current item is bigger than 0 and when perms exists, &lt;br /&gt;
     the method returns the corresponding items&amp;quot;.&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems and passed the value 1 as parameter, &lt;br /&gt;
     then the method should return a list of active_records &lt;br /&gt;
     which satisfy the condition.&lt;br /&gt;
 7.5 &amp;quot;When the controller_action_id of current item is smaller than or equal to 0 and the content_page_id of current item is bigger than 0, and when perms exists, &lt;br /&gt;
     the method returns corresponding items.&amp;quot;&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems and passed the value 1 as parameter, &lt;br /&gt;
     then the method should return a list of active_records which satisfy the condition.&lt;br /&gt;
 7.6 &amp;quot;When the controller_action_id and content_page_id of current item is smaller than or equal to 0, &lt;br /&gt;
     the method returns the corresponding items.&amp;quot;&lt;br /&gt;
     Here we expect that if the method items_for_permissions() is invoked on the MenuItems and passed the value 1 as a parameter, &lt;br /&gt;
     the method should return an empty list.&lt;br /&gt;
&lt;br /&gt;
The screenshot of the actual &amp;lt;b&amp;gt;menu_item_spec.rb&amp;lt;/b&amp;gt; file is give below:&lt;br /&gt;
[[File:Menu item spec code.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Test Runs ==&lt;br /&gt;
&lt;br /&gt;
A screenshot of the tests passing is shown here&lt;br /&gt;
[[File:RunTest.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Conclusion and Learning Outcomes ==&lt;br /&gt;
&lt;br /&gt;
After writing the test cases we used SimpleCov to measure the C0 coverage of our rails application.&lt;br /&gt;
In our case we did not have to install SimpleCov explicitly since it was already installed earlier.&lt;br /&gt;
After running rake spec to run the test cases, SimpleCov creates a directory called coverage in our rails application folder.&lt;br /&gt;
This folder called coverage contains an index.html file which when opened in a browser renders an html page which gives the C0 coverage of each of the files in the Controllers,Models,Helpers in the app directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The learning outcomes after performing this project can be summarized in the following points:&lt;br /&gt;
&lt;br /&gt;
1. We got an hands on experience about how to write tests following the Test Driven Development approach.&lt;br /&gt;
&lt;br /&gt;
2. We learned about how to write units tests for models and controllers in RSpec.&lt;br /&gt;
&lt;br /&gt;
3. We also learned how to understand the functionality of an already developed application.For our case, before writing the test cases for the menu_items.rb we had the understand how different models interacted with each other and how each action by different users would make changes in the database schema.&lt;br /&gt;
&lt;br /&gt;
4. We also gained a better understanding about how different tables, columns of a large applications in structured in the database schema.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/sandeep993/expertiza/tree/menu_item_branch GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;/div&gt;</summary>
		<author><name>Srajend</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:TestRun.png&amp;diff=115687</id>
		<title>File:TestRun.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:TestRun.png&amp;diff=115687"/>
		<updated>2018-04-03T00:07:11Z</updated>

		<summary type="html">&lt;p&gt;Srajend: uploaded a new version of &amp;amp;quot;File:TestRun.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Srajend</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:TestRun.png&amp;diff=115686</id>
		<title>File:TestRun.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:TestRun.png&amp;diff=115686"/>
		<updated>2018-04-03T00:06:47Z</updated>

		<summary type="html">&lt;p&gt;Srajend: uploaded a new version of &amp;amp;quot;File:TestRun.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Srajend</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:TestRun.png&amp;diff=115682</id>
		<title>File:TestRun.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:TestRun.png&amp;diff=115682"/>
		<updated>2018-04-03T00:05:10Z</updated>

		<summary type="html">&lt;p&gt;Srajend: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Srajend</name></author>
	</entry>
</feed>