<?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=Jli94</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=Jli94"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Jli94"/>
	<updated>2026-05-25T03:20:32Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=121585</id>
		<title>CSC/ECE 517 Fall 2018/E1873 Specialized rubics for different topic types</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=121585"/>
		<updated>2018-12-18T05:10:49Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /*  Procedure &amp;amp; Result  */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==''' Introduction '''==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
One of the fantastic features that Expertiza provides is for each assignment, it allows students providing reviews for others' jobs. This is done by offering a pre-defined questionnaire for the whole assignment, which is called the rubric for this assignment. Each rubric has several questions, each question provides a criterion to evaluate the performance from a specific angle. Then students can evaluate the entire job by rating and answering these questions. The team did that job can also get a detailed feedback for different aspects of the project.&lt;br /&gt;
&lt;br /&gt;
=== Motivation ===&lt;br /&gt;
One of the problems for the review system is that for each assignment, different topics are included. Students can choose the one topic they like, and those topics fall into different categories. That is, an assignment always include different kind of projects. In Expertiza, the topic can be refactoring projects, testing projects, Mozilla projects,  etc. Apparently, for different kinds of projects, we have different criteria to evaluate their performance. However, due to the current design of the system, all projects belong to the same assignment can only have the same rubric, which may lead to unnecessary criteria for some projects and inadequate criteria for other projects. &lt;br /&gt;
To make sure all kinds of projects can be evaluated properly. We plan to refactor the system to allow assigning different rubies for different projects in a specified appointment.&lt;br /&gt;
&lt;br /&gt;
==''' Analysis &amp;amp; Plan '''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To realize such purpose, we have the following tasks need to be done:&lt;br /&gt;
&lt;br /&gt;
===Check Box===&lt;br /&gt;
For current design, the rubric used for a specified assignment is set at the following page. To make sure users can choose to set different rubrics for different projects, we need first add a checkbox at this page. Therefore, users can use this box to indicate if they want to use the same rubric for all the projects or set some different rubrics for some projects.&lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873rubric.png]]&lt;br /&gt;
&lt;br /&gt;
===Dropdown List===&lt;br /&gt;
To make sure users can choose rubrics for each project, we should add a new dropdown list beside each project in the following page. The number of dropdown list should decide by review round number. Therefore, each time users choose to identify different rubrics for different projects, the list will appear and users can choose proper rubrics. The default rubric set at last page will be overwritten in this case. &lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873project.png]]&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Make changes to the controller so that these functions can work. Most of our logic control codes will be written in ''helpers/sign_up_sheet_helper.rb''.&lt;br /&gt;
&lt;br /&gt;
logic flowchart:&lt;br /&gt;
&lt;br /&gt;
[[File:umlj.png]]&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
Add questionnaire_id in sign_up_topics table to make sure the projects can always relate to correct rubrics&lt;br /&gt;
&lt;br /&gt;
[[File:databasejj.png]]&lt;br /&gt;
&lt;br /&gt;
===Test===&lt;br /&gt;
Test what we changed to make sure it works as intended and not influence the original system.&lt;br /&gt;
&lt;br /&gt;
==''' Implement Steps '''==&lt;br /&gt;
&lt;br /&gt;
=== Task 1  Add checkbox===&lt;br /&gt;
1. edit the file views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a checkbox at the top of the page which says &amp;quot;Vary rubric by topic&amp;quot;&lt;br /&gt;
&lt;br /&gt;
3. set the default state for this checkbox as unchecked&lt;br /&gt;
&lt;br /&gt;
===Task 2 Add dropdown list===&lt;br /&gt;
1. edit the file views/assignment/edit/_general.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a variable to indicate if the checkbox said in Task 1 is checked&lt;br /&gt;
&lt;br /&gt;
3. create a new file under views/sign_up_sheet called &amp;quot;_rubrics_list.html.erb&amp;quot; to store the code for the dropdown list&lt;br /&gt;
&lt;br /&gt;
4. edit the file views/sign_up_sheet/_table_line.html.erb&lt;br /&gt;
&lt;br /&gt;
5. add the code to render the dropdown list&lt;br /&gt;
&lt;br /&gt;
6. making a judgment before rendering the dropdown list, only if the checkbox in Task 1ist checked to render the page&lt;br /&gt;
&lt;br /&gt;
===Task 3 Change controllers===&lt;br /&gt;
Change the update method in sign_up_sheet_controller.rb to make sure when new rubric is chosen for a specific topic, it can be stored in the database properly&lt;br /&gt;
&lt;br /&gt;
===Task 4 Create migration===&lt;br /&gt;
1. create a new migration to add questionnaire_id in sign_up_topics&lt;br /&gt;
&lt;br /&gt;
2. the questionnaire_id is a foreign key which references to questionnaires&lt;br /&gt;
&lt;br /&gt;
3. change the file models/sign_up_topic.rb, and add the relations with the questionnaire, the relation between them is one-to-one&lt;br /&gt;
&lt;br /&gt;
===Task 5 Test the changes===&lt;br /&gt;
1. make a test plan for the features that need to be tested&lt;br /&gt;
&lt;br /&gt;
2. follow the test plan to write automatic test codes&lt;br /&gt;
&lt;br /&gt;
3. evaluate the results and refactor codes&lt;br /&gt;
&lt;br /&gt;
==''' Test plan '''==&lt;br /&gt;
We mainly use cucumber and capybara to test UI, and the following are detailed plans&lt;br /&gt;
&lt;br /&gt;
===Test checkbox===&lt;br /&gt;
1. go to the rubrics page under the assignment&lt;br /&gt;
&lt;br /&gt;
2. we can see the checkbox says &amp;quot;Vary rubric by topic&amp;quot; shows on this page&lt;br /&gt;
&lt;br /&gt;
3. the initial state of the checkbox is unchecked&lt;br /&gt;
&lt;br /&gt;
===Test dropdown list===&lt;br /&gt;
====Scenario 1====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is unchecked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3.there are no dropdown lists beside topics&lt;br /&gt;
====Scenario 2====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is checked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3. the table to show the topics have a row called &amp;quot;rubrics&amp;quot;&lt;br /&gt;
&lt;br /&gt;
4. under this title, each topic has a dropdown list&lt;br /&gt;
&lt;br /&gt;
==''' Procedure &amp;amp; Result '''==&lt;br /&gt;
===Test===&lt;br /&gt;
Instead of testing UI, we did some unit tests using Rspec.&lt;br /&gt;
&lt;br /&gt;
For testing update_topic_questionnaires.&lt;br /&gt;
*when attributes are nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it 'returns false' do&lt;br /&gt;
  expect(assignment_form.update_topic_questionnaires(nil)).to be false&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when attributes are not nil and at least one topic_questionnaire's id is nil or blank&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
let(:attributes) { [topic_questionnaire, topic_questionnaire2] }&lt;br /&gt;
before(:each) do&lt;br /&gt;
  allow(topic_questionnaire).to receive(:[]).with(:id).and_return(nil)&lt;br /&gt;
  allow(topic_questionnaire2).to receive(:[]).with(:id).and_return(1)&lt;br /&gt;
  allow(TopicQuestionnaire).to receive(:where).with(sign_up_topic_id: SignUpTopic.where(assignment_id: 1)).and_return([])&lt;br /&gt;
  allow(TopicQuestionnaire).to receive(:new).with(topic_questionnaire).and_return(topic_questionnaire)&lt;br /&gt;
  allow(TopicQuestionnaire).to receive(:find).with(1).and_return(topic_questionnaire2)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when both save and update_attributes method do not work&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it 'changes @has_errors value to true and returns attributes (args)' do&lt;br /&gt;
  allow(topic_questionnaire).to receive(:save).and_return(false)&lt;br /&gt;
  allow(topic_questionnaire2).to receive(:update_attributes).with(topic_questionnaire2).and_return(false)&lt;br /&gt;
  expect(assignment_form.update_topic_questionnaires(attributes)).to eq(attributes)&lt;br /&gt;
  expect(assignment_form.instance_variable_get(:@has_errors)).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when both save and update_attributes method work well&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it 'returns attributes (args) and @has_errors value is nil' do&lt;br /&gt;
  allow(topic_questionnaire).to receive(:save).and_return(true)&lt;br /&gt;
  allow(topic_questionnaire2).to receive(:update_attributes).with(topic_questionnaire2).and_return(true)&lt;br /&gt;
  expect(assignment_form.update_topic_questionnaires(attributes)).to eq(attributes)&lt;br /&gt;
  expect(assignment_form.instance_variable_get(:@has_errors)).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For testing review_by_rounds, check the number of rounds which decides the rounds of the questionnaire that each assignment needs.&lt;br /&gt;
*when used in round is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it 'returns false' do&lt;br /&gt;
  expect(@review_by_rounds).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181218000845.png&amp;diff=121584</id>
		<title>File:微信图片 20181218000845.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181218000845.png&amp;diff=121584"/>
		<updated>2018-12-18T05:09:24Z</updated>

		<summary type="html">&lt;p&gt;Jli94: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=121581</id>
		<title>CSC/ECE 517 Fall 2018/E1873 Specialized rubics for different topic types</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=121581"/>
		<updated>2018-12-18T05:06:45Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Test */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==''' Introduction '''==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
One of the fantastic features that Expertiza provides is for each assignment, it allows students providing reviews for others' jobs. This is done by offering a pre-defined questionnaire for the whole assignment, which is called the rubric for this assignment. Each rubric has several questions, each question provides a criterion to evaluate the performance from a specific angle. Then students can evaluate the entire job by rating and answering these questions. The team did that job can also get a detailed feedback for different aspects of the project.&lt;br /&gt;
&lt;br /&gt;
=== Motivation ===&lt;br /&gt;
One of the problems for the review system is that for each assignment, different topics are included. Students can choose the one topic they like, and those topics fall into different categories. That is, an assignment always include different kind of projects. In Expertiza, the topic can be refactoring projects, testing projects, Mozilla projects,  etc. Apparently, for different kinds of projects, we have different criteria to evaluate their performance. However, due to the current design of the system, all projects belong to the same assignment can only have the same rubric, which may lead to unnecessary criteria for some projects and inadequate criteria for other projects. &lt;br /&gt;
To make sure all kinds of projects can be evaluated properly. We plan to refactor the system to allow assigning different rubies for different projects in a specified appointment.&lt;br /&gt;
&lt;br /&gt;
==''' Analysis &amp;amp; Plan '''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To realize such purpose, we have the following tasks need to be done:&lt;br /&gt;
&lt;br /&gt;
===Check Box===&lt;br /&gt;
For current design, the rubric used for a specified assignment is set at the following page. To make sure users can choose to set different rubrics for different projects, we need first add a checkbox at this page. Therefore, users can use this box to indicate if they want to use the same rubric for all the projects or set some different rubrics for some projects.&lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873rubric.png]]&lt;br /&gt;
&lt;br /&gt;
===Dropdown List===&lt;br /&gt;
To make sure users can choose rubrics for each project, we should add a new dropdown list beside each project in the following page. The number of dropdown list should decide by review round number. Therefore, each time users choose to identify different rubrics for different projects, the list will appear and users can choose proper rubrics. The default rubric set at last page will be overwritten in this case. &lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873project.png]]&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Make changes to the controller so that these functions can work. Most of our logic control codes will be written in ''helpers/sign_up_sheet_helper.rb''.&lt;br /&gt;
&lt;br /&gt;
logic flowchart:&lt;br /&gt;
&lt;br /&gt;
[[File:umlj.png]]&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
Add questionnaire_id in sign_up_topics table to make sure the projects can always relate to correct rubrics&lt;br /&gt;
&lt;br /&gt;
[[File:databasejj.png]]&lt;br /&gt;
&lt;br /&gt;
===Test===&lt;br /&gt;
Test what we changed to make sure it works as intended and not influence the original system.&lt;br /&gt;
&lt;br /&gt;
==''' Implement Steps '''==&lt;br /&gt;
&lt;br /&gt;
=== Task 1  Add checkbox===&lt;br /&gt;
1. edit the file views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a checkbox at the top of the page which says &amp;quot;Vary rubric by topic&amp;quot;&lt;br /&gt;
&lt;br /&gt;
3. set the default state for this checkbox as unchecked&lt;br /&gt;
&lt;br /&gt;
===Task 2 Add dropdown list===&lt;br /&gt;
1. edit the file views/assignment/edit/_general.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a variable to indicate if the checkbox said in Task 1 is checked&lt;br /&gt;
&lt;br /&gt;
3. create a new file under views/sign_up_sheet called &amp;quot;_rubrics_list.html.erb&amp;quot; to store the code for the dropdown list&lt;br /&gt;
&lt;br /&gt;
4. edit the file views/sign_up_sheet/_table_line.html.erb&lt;br /&gt;
&lt;br /&gt;
5. add the code to render the dropdown list&lt;br /&gt;
&lt;br /&gt;
6. making a judgment before rendering the dropdown list, only if the checkbox in Task 1ist checked to render the page&lt;br /&gt;
&lt;br /&gt;
===Task 3 Change controllers===&lt;br /&gt;
Change the update method in sign_up_sheet_controller.rb to make sure when new rubric is chosen for a specific topic, it can be stored in the database properly&lt;br /&gt;
&lt;br /&gt;
===Task 4 Create migration===&lt;br /&gt;
1. create a new migration to add questionnaire_id in sign_up_topics&lt;br /&gt;
&lt;br /&gt;
2. the questionnaire_id is a foreign key which references to questionnaires&lt;br /&gt;
&lt;br /&gt;
3. change the file models/sign_up_topic.rb, and add the relations with the questionnaire, the relation between them is one-to-one&lt;br /&gt;
&lt;br /&gt;
===Task 5 Test the changes===&lt;br /&gt;
1. make a test plan for the features that need to be tested&lt;br /&gt;
&lt;br /&gt;
2. follow the test plan to write automatic test codes&lt;br /&gt;
&lt;br /&gt;
3. evaluate the results and refactor codes&lt;br /&gt;
&lt;br /&gt;
==''' Test plan '''==&lt;br /&gt;
We mainly use cucumber and capybara to test UI, and the following are detailed plans&lt;br /&gt;
&lt;br /&gt;
===Test checkbox===&lt;br /&gt;
1. go to the rubrics page under the assignment&lt;br /&gt;
&lt;br /&gt;
2. we can see the checkbox says &amp;quot;Vary rubric by topic&amp;quot; shows on this page&lt;br /&gt;
&lt;br /&gt;
3. the initial state of the checkbox is unchecked&lt;br /&gt;
&lt;br /&gt;
===Test dropdown list===&lt;br /&gt;
====Scenario 1====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is unchecked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3.there are no dropdown lists beside topics&lt;br /&gt;
====Scenario 2====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is checked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3. the table to show the topics have a row called &amp;quot;rubrics&amp;quot;&lt;br /&gt;
&lt;br /&gt;
4. under this title, each topic has a dropdown list&lt;br /&gt;
&lt;br /&gt;
==''' Procedure &amp;amp; Result '''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Result===&lt;br /&gt;
[[File:1873-result.png]]&lt;br /&gt;
===Test===&lt;br /&gt;
Instead of testing UI, we did some unit tests using Rspec.&lt;br /&gt;
&lt;br /&gt;
For testing update_topic_questionnaires.&lt;br /&gt;
*when attributes are nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it 'returns false' do&lt;br /&gt;
  expect(assignment_form.update_topic_questionnaires(nil)).to be false&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when attributes are not nil and at least one topic_questionnaire's id is nil or blank&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
let(:attributes) { [topic_questionnaire, topic_questionnaire2] }&lt;br /&gt;
before(:each) do&lt;br /&gt;
  allow(topic_questionnaire).to receive(:[]).with(:id).and_return(nil)&lt;br /&gt;
  allow(topic_questionnaire2).to receive(:[]).with(:id).and_return(1)&lt;br /&gt;
  allow(TopicQuestionnaire).to receive(:where).with(sign_up_topic_id: SignUpTopic.where(assignment_id: 1)).and_return([])&lt;br /&gt;
  allow(TopicQuestionnaire).to receive(:new).with(topic_questionnaire).and_return(topic_questionnaire)&lt;br /&gt;
  allow(TopicQuestionnaire).to receive(:find).with(1).and_return(topic_questionnaire2)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when both save and update_attributes method do not work&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it 'changes @has_errors value to true and returns attributes (args)' do&lt;br /&gt;
  allow(topic_questionnaire).to receive(:save).and_return(false)&lt;br /&gt;
  allow(topic_questionnaire2).to receive(:update_attributes).with(topic_questionnaire2).and_return(false)&lt;br /&gt;
  expect(assignment_form.update_topic_questionnaires(attributes)).to eq(attributes)&lt;br /&gt;
  expect(assignment_form.instance_variable_get(:@has_errors)).to be true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when both save and update_attributes method work well&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it 'returns attributes (args) and @has_errors value is nil' do&lt;br /&gt;
  allow(topic_questionnaire).to receive(:save).and_return(true)&lt;br /&gt;
  allow(topic_questionnaire2).to receive(:update_attributes).with(topic_questionnaire2).and_return(true)&lt;br /&gt;
  expect(assignment_form.update_topic_questionnaires(attributes)).to eq(attributes)&lt;br /&gt;
  expect(assignment_form.instance_variable_get(:@has_errors)).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For testing review_by_rounds, check the number of rounds which decides the rounds of the questionnaire that each assignment needs.&lt;br /&gt;
*when used in round is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
it 'returns false' do&lt;br /&gt;
  expect(@review_by_rounds).to be nil&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:1873-result.png&amp;diff=121579</id>
		<title>File:1873-result.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:1873-result.png&amp;diff=121579"/>
		<updated>2018-12-18T05:05:05Z</updated>

		<summary type="html">&lt;p&gt;Jli94: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120546</id>
		<title>CSC/ECE 517 Fall 2018/E1873 Specialized rubics for different topic types</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120546"/>
		<updated>2018-11-21T01:25:52Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==''' Introduction '''==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
One of the fantastic features that Expertiza provides is for each assignment, it allows students providing reviews for others' jobs. This is done by offering a pre-defined questionnaire for the whole assignment, which is called the rubric for this assignment. Each rubric has several questions, each question provides a criterion to evaluate the performance from a specific angle. Then students can evaluate the entire job by rating and answering these questions. The team did that job can also get a detailed feedback for different aspects of the project.&lt;br /&gt;
&lt;br /&gt;
=== Motivation ===&lt;br /&gt;
One of the problems for the review system is that for each assignment, different topics are included. Students can choose the one topic they like, and those topics fall into different categories. That is, an assignment always include different kind of projects. In Expertiza, the topic can be refactoring projects, testing projects, Mozilla projects,  etc. Apparently, for different kinds of projects, we have different criteria to evaluate their performance. However, due to the current design of the system, all projects belong to the same assignment can only have the same rubric, which may lead to unnecessary criteria for some projects and inadequate criteria for other projects. &lt;br /&gt;
To make sure all kinds of projects can be evaluated properly. We plan to refactor the system to allow assigning different rubies for different projects in a specified appointment.&lt;br /&gt;
&lt;br /&gt;
==''' Analysis &amp;amp; Plan '''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To realize such purpose, we have the following tasks need to be done:&lt;br /&gt;
&lt;br /&gt;
===Check Box===&lt;br /&gt;
For current design, the rubric used for a specified assignment is set at the following page. To make sure users can choose to set different rubrics for different projects, we need first add a checkbox at this page. Therefore, users can use this box to indicate if they want to use the same rubric for all the projects or set some different rubrics for some projects.&lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873rubric.png]]&lt;br /&gt;
&lt;br /&gt;
===Dropdown List===&lt;br /&gt;
To make sure users can choose rubrics for each project, we should add a new dropdown list beside each project in the following page. The number of dropdown list should decide by review round number. Therefore, each time users choose to identify different rubrics for different projects, the list will appear and users can choose proper rubrics. The default rubric set at last page will be overwritten in this case. &lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873project.png]]&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Make changes to the controller so that these functions can work. Most of our logic control codes will be written in ''helpers/sign_up_sheet_helper.rb''.&lt;br /&gt;
&lt;br /&gt;
logic flowchart:&lt;br /&gt;
&lt;br /&gt;
[[File:umlj.png]]&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
Add questionnaire_id in sign_up_topics table to make sure the projects can always relate to correct rubrics&lt;br /&gt;
&lt;br /&gt;
[[File:Untitled Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
===Test===&lt;br /&gt;
Test what we changed to make sure it works as intended and not influence the original system.&lt;br /&gt;
&lt;br /&gt;
==''' Implement Steps '''==&lt;br /&gt;
&lt;br /&gt;
=== Task 1  Add checkbox===&lt;br /&gt;
1. edit the file views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a checkbox at the top of the page which says &amp;quot;Vary rubric by topic&amp;quot;&lt;br /&gt;
&lt;br /&gt;
3. set the default state for this checkbox as unchecked&lt;br /&gt;
&lt;br /&gt;
===Task 2 Add dropdown list===&lt;br /&gt;
1. edit the file views/assignment/edit/_general.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a variable to indicate if the checkbox said in Task 1 is checked&lt;br /&gt;
&lt;br /&gt;
3. create a new file under views/sign_up_sheet called &amp;quot;_rubrics_list.html.erb&amp;quot; to store the code for the dropdown list&lt;br /&gt;
&lt;br /&gt;
4. edit the file views/sign_up_sheet/_table_line.html.erb&lt;br /&gt;
&lt;br /&gt;
5. add the code to render the dropdown list&lt;br /&gt;
&lt;br /&gt;
6. making a judgment before rendering the dropdown list, only if the checkbox in Task 1ist checked to render the page&lt;br /&gt;
&lt;br /&gt;
===Task 3 Change controllers===&lt;br /&gt;
Change the update method in sign_up_sheet_controller.rb to make sure when new rubric is chosen for a specific topic, it can be stored in the database properly&lt;br /&gt;
&lt;br /&gt;
===Task 4 Create migration===&lt;br /&gt;
1. create a new migration to add questionnaire_id in sign_up_topics&lt;br /&gt;
&lt;br /&gt;
2. the questionnaire_id is a foreign key which references to questionnaires&lt;br /&gt;
&lt;br /&gt;
3. change the file models/sign_up_topic.rb, and add the relations with the questionnaire, the relation between them is one-to-one&lt;br /&gt;
&lt;br /&gt;
===Task 5 Test the changes===&lt;br /&gt;
1. make a test plan for the features that need to be tested&lt;br /&gt;
&lt;br /&gt;
2. follow the test plan to write automatic test codes&lt;br /&gt;
&lt;br /&gt;
3. evaluate the results and refactor codes&lt;br /&gt;
&lt;br /&gt;
==''' Test plan '''==&lt;br /&gt;
We mainly use cucumber and capybara to test UI, and the following are detailed plans&lt;br /&gt;
&lt;br /&gt;
===Test checkbox===&lt;br /&gt;
1. go to the rubrics page under the assignment&lt;br /&gt;
&lt;br /&gt;
2. we can see the checkbox says &amp;quot;Vary rubric by topic&amp;quot; shows on this page&lt;br /&gt;
&lt;br /&gt;
3. the initial state of the checkbox is unchecked&lt;br /&gt;
&lt;br /&gt;
===Test dropdown list===&lt;br /&gt;
====Scenario 1====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is unchecked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3.there are no dropdown lists beside topics&lt;br /&gt;
====Scenario 2====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is checked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3. the table to show the topics have a row called &amp;quot;rubrics&amp;quot;&lt;br /&gt;
&lt;br /&gt;
4. under this title, each topic has a dropdown list&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120545</id>
		<title>CSC/ECE 517 Fall 2018/E1873 Specialized rubics for different topic types</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120545"/>
		<updated>2018-11-21T01:25:40Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==''' Introduction '''==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
One of the fantastic features that Expertiza provides is for each assignment, it allows students providing reviews for others' jobs. This is done by offering a pre-defined questionnaire for the whole assignment, which is called the rubric for this assignment. Each rubric has several questions, each question provides a criterion to evaluate the performance from a specific angle. Then students can evaluate the entire job by rating and answering these questions. The team did that job can also get a detailed feedback for different aspects of the project.&lt;br /&gt;
&lt;br /&gt;
=== Motivation ===&lt;br /&gt;
One of the problems for the review system is that for each assignment, different topics are included. Students can choose the one topic they like, and those topics fall into different categories. That is, an assignment always include different kind of projects. In Expertiza, the topic can be refactoring projects, testing projects, Mozilla projects,  etc. Apparently, for different kinds of projects, we have different criteria to evaluate their performance. However, due to the current design of the system, all projects belong to the same assignment can only have the same rubric, which may lead to unnecessary criteria for some projects and inadequate criteria for other projects. &lt;br /&gt;
To make sure all kinds of projects can be evaluated properly. We plan to refactor the system to allow assigning different rubies for different projects in a specified appointment.&lt;br /&gt;
&lt;br /&gt;
==''' Analysis &amp;amp; Plan '''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To realize such purpose, we have the following tasks need to be done:&lt;br /&gt;
&lt;br /&gt;
===Check Box===&lt;br /&gt;
For current design, the rubric used for a specified assignment is set at the following page. To make sure users can choose to set different rubrics for different projects, we need first add a checkbox at this page. Therefore, users can use this box to indicate if they want to use the same rubric for all the projects or set some different rubrics for some projects.&lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873rubric.png]]&lt;br /&gt;
&lt;br /&gt;
===Dropdown List===&lt;br /&gt;
To make sure users can choose rubrics for each project, we should add a new dropdown list beside each project in the following page. The number of dropdown list should decide by review round number. Therefore, each time users choose to identify different rubrics for different projects, the list will appear and users can choose proper rubrics. The default rubric set at last page will be overwritten in this case. &lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873project.png]]&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Make changes to the controller so that these functions can work. Most of our logic control codes will be written in ''helpers/sign_up_sheet_helper.rb''.&lt;br /&gt;
&lt;br /&gt;
logic flowchart:&lt;br /&gt;
&lt;br /&gt;
[[File:umlj.png]]&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
Add questionnaire_id in sign_up_topics table to make sure the projects can always relate to correct rubrics&lt;br /&gt;
&lt;br /&gt;
[[File:Untitled Diagram.png|500px|aaa]]&lt;br /&gt;
&lt;br /&gt;
===Test===&lt;br /&gt;
Test what we changed to make sure it works as intended and not influence the original system.&lt;br /&gt;
&lt;br /&gt;
==''' Implement Steps '''==&lt;br /&gt;
&lt;br /&gt;
=== Task 1  Add checkbox===&lt;br /&gt;
1. edit the file views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a checkbox at the top of the page which says &amp;quot;Vary rubric by topic&amp;quot;&lt;br /&gt;
&lt;br /&gt;
3. set the default state for this checkbox as unchecked&lt;br /&gt;
&lt;br /&gt;
===Task 2 Add dropdown list===&lt;br /&gt;
1. edit the file views/assignment/edit/_general.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a variable to indicate if the checkbox said in Task 1 is checked&lt;br /&gt;
&lt;br /&gt;
3. create a new file under views/sign_up_sheet called &amp;quot;_rubrics_list.html.erb&amp;quot; to store the code for the dropdown list&lt;br /&gt;
&lt;br /&gt;
4. edit the file views/sign_up_sheet/_table_line.html.erb&lt;br /&gt;
&lt;br /&gt;
5. add the code to render the dropdown list&lt;br /&gt;
&lt;br /&gt;
6. making a judgment before rendering the dropdown list, only if the checkbox in Task 1ist checked to render the page&lt;br /&gt;
&lt;br /&gt;
===Task 3 Change controllers===&lt;br /&gt;
Change the update method in sign_up_sheet_controller.rb to make sure when new rubric is chosen for a specific topic, it can be stored in the database properly&lt;br /&gt;
&lt;br /&gt;
===Task 4 Create migration===&lt;br /&gt;
1. create a new migration to add questionnaire_id in sign_up_topics&lt;br /&gt;
&lt;br /&gt;
2. the questionnaire_id is a foreign key which references to questionnaires&lt;br /&gt;
&lt;br /&gt;
3. change the file models/sign_up_topic.rb, and add the relations with the questionnaire, the relation between them is one-to-one&lt;br /&gt;
&lt;br /&gt;
===Task 5 Test the changes===&lt;br /&gt;
1. make a test plan for the features that need to be tested&lt;br /&gt;
&lt;br /&gt;
2. follow the test plan to write automatic test codes&lt;br /&gt;
&lt;br /&gt;
3. evaluate the results and refactor codes&lt;br /&gt;
&lt;br /&gt;
==''' Test plan '''==&lt;br /&gt;
We mainly use cucumber and capybara to test UI, and the following are detailed plans&lt;br /&gt;
&lt;br /&gt;
===Test checkbox===&lt;br /&gt;
1. go to the rubrics page under the assignment&lt;br /&gt;
&lt;br /&gt;
2. we can see the checkbox says &amp;quot;Vary rubric by topic&amp;quot; shows on this page&lt;br /&gt;
&lt;br /&gt;
3. the initial state of the checkbox is unchecked&lt;br /&gt;
&lt;br /&gt;
===Test dropdown list===&lt;br /&gt;
====Scenario 1====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is unchecked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3.there are no dropdown lists beside topics&lt;br /&gt;
====Scenario 2====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is checked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3. the table to show the topics have a row called &amp;quot;rubrics&amp;quot;&lt;br /&gt;
&lt;br /&gt;
4. under this title, each topic has a dropdown list&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120539</id>
		<title>CSC/ECE 517 Fall 2018/E1873 Specialized rubics for different topic types</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120539"/>
		<updated>2018-11-21T01:23:33Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==''' Introduction '''==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
One of the fantastic features that Expertiza provides is for each assignment, it allows students providing reviews for others' jobs. This is done by offering a pre-defined questionnaire for the whole assignment, which is called the rubric for this assignment. Each rubric has several questions, each question provides a criterion to evaluate the performance from a specific angle. Then students can evaluate the entire job by rating and answering these questions. The team did that job can also get a detailed feedback for different aspects of the project.&lt;br /&gt;
&lt;br /&gt;
=== Motivation ===&lt;br /&gt;
One of the problems for the review system is that for each assignment, different topics are included. Students can choose the one topic they like, and those topics fall into different categories. That is, an assignment always include different kind of projects. In Expertiza, the topic can be refactoring projects, testing projects, Mozilla projects,  etc. Apparently, for different kinds of projects, we have different criteria to evaluate their performance. However, due to the current design of the system, all projects belong to the same assignment can only have the same rubric, which may lead to unnecessary criteria for some projects and inadequate criteria for other projects. &lt;br /&gt;
To make sure all kinds of projects can be evaluated properly. We plan to refactor the system to allow assigning different rubies for different projects in a specified appointment.&lt;br /&gt;
&lt;br /&gt;
==''' Analysis &amp;amp; Plan '''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To realize such purpose, we have the following tasks need to be done:&lt;br /&gt;
&lt;br /&gt;
===Check Box===&lt;br /&gt;
For current design, the rubric used for a specified assignment is set at the following page. To make sure users can choose to set different rubrics for different projects, we need first add a checkbox at this page. Therefore, users can use this box to indicate if they want to use the same rubric for all the projects or set some different rubrics for some projects.&lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873rubric.png]]&lt;br /&gt;
&lt;br /&gt;
===Dropdown List===&lt;br /&gt;
To make sure users can choose rubrics for each project, we should add a new dropdown list beside each project in the following page. The number of dropdown list should decide by review round number. Therefore, each time users choose to identify different rubrics for different projects, the list will appear and users can choose proper rubrics. The default rubric set at last page will be overwritten in this case. &lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873project.png]]&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Make changes to the controller so that these functions can work. Most of our logic control codes will be written in ''helpers/sign_up_sheet_helper.rb''.&lt;br /&gt;
&lt;br /&gt;
logic flowchart:&lt;br /&gt;
&lt;br /&gt;
[[File:umlj.png]]&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
Add questionnaire_id in sign_up_topics table to make sure the projects can always relate to correct rubrics&lt;br /&gt;
&lt;br /&gt;
[[File:Untitled Diagram.png|500px]]&lt;br /&gt;
&lt;br /&gt;
===Test===&lt;br /&gt;
Test what we changed to make sure it works as intended and not influence the original system.&lt;br /&gt;
&lt;br /&gt;
==''' Implement Steps '''==&lt;br /&gt;
&lt;br /&gt;
=== Task 1  Add checkbox===&lt;br /&gt;
1. edit the file views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a checkbox at the top of the page which says &amp;quot;Vary rubric by topic&amp;quot;&lt;br /&gt;
&lt;br /&gt;
3. set the default state for this checkbox as unchecked&lt;br /&gt;
&lt;br /&gt;
===Task 2 Add dropdown list===&lt;br /&gt;
1. edit the file views/assignment/edit/_general.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a variable to indicate if the checkbox said in Task 1 is checked&lt;br /&gt;
&lt;br /&gt;
3. create a new file under views/sign_up_sheet called &amp;quot;_rubrics_list.html.erb&amp;quot; to store the code for the dropdown list&lt;br /&gt;
&lt;br /&gt;
4. edit the file views/sign_up_sheet/_table_line.html.erb&lt;br /&gt;
&lt;br /&gt;
5. add the code to render the dropdown list&lt;br /&gt;
&lt;br /&gt;
6. making a judgment before rendering the dropdown list, only if the checkbox in Task 1ist checked to render the page&lt;br /&gt;
&lt;br /&gt;
===Task 3 Change controllers===&lt;br /&gt;
Change the update method in sign_up_sheet_controller.rb to make sure when new rubric is chosen for a specific topic, it can be stored in the database properly&lt;br /&gt;
&lt;br /&gt;
===Task 4 Create migration===&lt;br /&gt;
1. create a new migration to add questionnaire_id in sign_up_topics&lt;br /&gt;
&lt;br /&gt;
2. the questionnaire_id is a foreign key which references to questionnaires&lt;br /&gt;
&lt;br /&gt;
3. change the file models/sign_up_topic.rb, and add the relations with the questionnaire, the relation between them is one-to-one&lt;br /&gt;
&lt;br /&gt;
===Task 5 Test the changes===&lt;br /&gt;
1. make a test plan for the features that need to be tested&lt;br /&gt;
&lt;br /&gt;
2. follow the test plan to write automatic test codes&lt;br /&gt;
&lt;br /&gt;
3. evaluate the results and refactor codes&lt;br /&gt;
&lt;br /&gt;
==''' Test plan '''==&lt;br /&gt;
We mainly use cucumber and capybara to test UI, and the following are detailed plans&lt;br /&gt;
&lt;br /&gt;
===Test checkbox===&lt;br /&gt;
1. go to the rubrics page under the assignment&lt;br /&gt;
&lt;br /&gt;
2. we can see the checkbox says &amp;quot;Vary rubric by topic&amp;quot; shows on this page&lt;br /&gt;
&lt;br /&gt;
3. the initial state of the checkbox is unchecked&lt;br /&gt;
&lt;br /&gt;
===Test dropdown list===&lt;br /&gt;
====Scenario 1====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is unchecked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3.there are no dropdown lists beside topics&lt;br /&gt;
====Scenario 2====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is checked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3. the table to show the topics have a row called &amp;quot;rubrics&amp;quot;&lt;br /&gt;
&lt;br /&gt;
4. under this title, each topic has a dropdown list&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120538</id>
		<title>CSC/ECE 517 Fall 2018/E1873 Specialized rubics for different topic types</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120538"/>
		<updated>2018-11-21T01:23:14Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==''' Introduction '''==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
One of the fantastic features that Expertiza provides is for each assignment, it allows students providing reviews for others' jobs. This is done by offering a pre-defined questionnaire for the whole assignment, which is called the rubric for this assignment. Each rubric has several questions, each question provides a criterion to evaluate the performance from a specific angle. Then students can evaluate the entire job by rating and answering these questions. The team did that job can also get a detailed feedback for different aspects of the project.&lt;br /&gt;
&lt;br /&gt;
=== Motivation ===&lt;br /&gt;
One of the problems for the review system is that for each assignment, different topics are included. Students can choose the one topic they like, and those topics fall into different categories. That is, an assignment always include different kind of projects. In Expertiza, the topic can be refactoring projects, testing projects, Mozilla projects,  etc. Apparently, for different kinds of projects, we have different criteria to evaluate their performance. However, due to the current design of the system, all projects belong to the same assignment can only have the same rubric, which may lead to unnecessary criteria for some projects and inadequate criteria for other projects. &lt;br /&gt;
To make sure all kinds of projects can be evaluated properly. We plan to refactor the system to allow assigning different rubies for different projects in a specified appointment.&lt;br /&gt;
&lt;br /&gt;
==''' Analysis &amp;amp; Plan '''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To realize such purpose, we have the following tasks need to be done:&lt;br /&gt;
&lt;br /&gt;
===Check Box===&lt;br /&gt;
For current design, the rubric used for a specified assignment is set at the following page. To make sure users can choose to set different rubrics for different projects, we need first add a checkbox at this page. Therefore, users can use this box to indicate if they want to use the same rubric for all the projects or set some different rubrics for some projects.&lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873rubric.png]]&lt;br /&gt;
&lt;br /&gt;
===Dropdown List===&lt;br /&gt;
To make sure users can choose rubrics for each project, we should add a new dropdown list beside each project in the following page. The number of dropdown list should decide by review round number. Therefore, each time users choose to identify different rubrics for different projects, the list will appear and users can choose proper rubrics. The default rubric set at last page will be overwritten in this case. &lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873project.png]]&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Make changes to the controller so that these functions can work. Most of our logic control codes will be written in ''helpers/sign_up_sheet_helper.rb''.&lt;br /&gt;
&lt;br /&gt;
logic flowchart:&lt;br /&gt;
&lt;br /&gt;
[[File:umlj.png]]&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
Add questionnaire_id in sign_up_topics table to make sure the projects can always relate to correct rubrics&lt;br /&gt;
&lt;br /&gt;
[[File:Untitled Diagram.png]]|500px&lt;br /&gt;
&lt;br /&gt;
===Test===&lt;br /&gt;
Test what we changed to make sure it works as intended and not influence the original system.&lt;br /&gt;
&lt;br /&gt;
==''' Implement Steps '''==&lt;br /&gt;
&lt;br /&gt;
=== Task 1  Add checkbox===&lt;br /&gt;
1. edit the file views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a checkbox at the top of the page which says &amp;quot;Vary rubric by topic&amp;quot;&lt;br /&gt;
&lt;br /&gt;
3. set the default state for this checkbox as unchecked&lt;br /&gt;
&lt;br /&gt;
===Task 2 Add dropdown list===&lt;br /&gt;
1. edit the file views/assignment/edit/_general.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a variable to indicate if the checkbox said in Task 1 is checked&lt;br /&gt;
&lt;br /&gt;
3. create a new file under views/sign_up_sheet called &amp;quot;_rubrics_list.html.erb&amp;quot; to store the code for the dropdown list&lt;br /&gt;
&lt;br /&gt;
4. edit the file views/sign_up_sheet/_table_line.html.erb&lt;br /&gt;
&lt;br /&gt;
5. add the code to render the dropdown list&lt;br /&gt;
&lt;br /&gt;
6. making a judgment before rendering the dropdown list, only if the checkbox in Task 1ist checked to render the page&lt;br /&gt;
&lt;br /&gt;
===Task 3 Change controllers===&lt;br /&gt;
Change the update method in sign_up_sheet_controller.rb to make sure when new rubric is chosen for a specific topic, it can be stored in the database properly&lt;br /&gt;
&lt;br /&gt;
===Task 4 Create migration===&lt;br /&gt;
1. create a new migration to add questionnaire_id in sign_up_topics&lt;br /&gt;
&lt;br /&gt;
2. the questionnaire_id is a foreign key which references to questionnaires&lt;br /&gt;
&lt;br /&gt;
3. change the file models/sign_up_topic.rb, and add the relations with the questionnaire, the relation between them is one-to-one&lt;br /&gt;
&lt;br /&gt;
===Task 5 Test the changes===&lt;br /&gt;
1. make a test plan for the features that need to be tested&lt;br /&gt;
&lt;br /&gt;
2. follow the test plan to write automatic test codes&lt;br /&gt;
&lt;br /&gt;
3. evaluate the results and refactor codes&lt;br /&gt;
&lt;br /&gt;
==''' Test plan '''==&lt;br /&gt;
We mainly use cucumber and capybara to test UI, and the following are detailed plans&lt;br /&gt;
&lt;br /&gt;
===Test checkbox===&lt;br /&gt;
1. go to the rubrics page under the assignment&lt;br /&gt;
&lt;br /&gt;
2. we can see the checkbox says &amp;quot;Vary rubric by topic&amp;quot; shows on this page&lt;br /&gt;
&lt;br /&gt;
3. the initial state of the checkbox is unchecked&lt;br /&gt;
&lt;br /&gt;
===Test dropdown list===&lt;br /&gt;
====Scenario 1====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is unchecked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3.there are no dropdown lists beside topics&lt;br /&gt;
====Scenario 2====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is checked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3. the table to show the topics have a row called &amp;quot;rubrics&amp;quot;&lt;br /&gt;
&lt;br /&gt;
4. under this title, each topic has a dropdown list&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120407</id>
		<title>CSC/ECE 517 Fall 2018/E1873 Specialized rubics for different topic types</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120407"/>
		<updated>2018-11-20T23:01:18Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==''' Introduction '''==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
One of the fantastic features that Expertiza provides is for each assignment, it allows students providing reviews for others' jobs. This is done by offering a pre-defined questionnaire for the whole assignment, which is called the rubric for this assignment. Each rubric has several questions, each question provides a criterion to evaluate the performance from a specific angle. Then students can evaluate the entire job by rating and answering these questions. The team did that job can also get a detailed feedback for different aspects of the project.&lt;br /&gt;
&lt;br /&gt;
=== Motivation ===&lt;br /&gt;
One of the problems for the review system is that for each assignment, different topics are included. Students can choose the one topic they like, and those topics fall into different categories. That is, an assignment always include different kind of projects. In Expertiza, the topic can be refactoring projects, testing projects, Mozilla projects,  etc. Apparently, for different kinds of projects, we have different criteria to evaluate their performance. However, due to the current design of the system, all projects belong to the same assignment can only have the same rubric, which may lead to unnecessary criteria for some projects and inadequate criteria for other projects. &lt;br /&gt;
To make sure all kinds of projects can be evaluated properly. We plan to refactor the system to allow assigning different rubies for different projects in a specified appointment.&lt;br /&gt;
&lt;br /&gt;
==''' Analysis &amp;amp; Plan '''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To realize such purpose, we have the following tasks need to be done:&lt;br /&gt;
&lt;br /&gt;
===Check Box===&lt;br /&gt;
For current design, the rubric used for a specified assignment is set at the following page. To make sure users can choose to set different rubrics for different projects, we need first add a checkbox at this page. Therefore, users can use this box to indicate if they want to use the same rubric for all the projects or set some different rubrics for some projects.&lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873rubric.png]]&lt;br /&gt;
&lt;br /&gt;
===Dropdown List===&lt;br /&gt;
To make sure users can choose rubrics for each project, we should add a new dropdown list beside each project in the following page. The number of dropdown list should decide by review round number. Therefore, each time users choose to identify different rubrics for different projects, the list will appear and users can choose proper rubrics. The default rubric set at last page will be overwritten in this case. &lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873project.png]]&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Make changes to the controller so that these functions can work. Most of our logic control codes will be written in ''helpers/sign_up_sheet_helper.rb''.&lt;br /&gt;
&lt;br /&gt;
logic flowchart:&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
Add questionnaire_id in sign_up_topics table to make sure the projects can always relate to correct rubrics&lt;br /&gt;
&lt;br /&gt;
===Test===&lt;br /&gt;
Test what we changed to make sure it works as intended and not influence the original system.&lt;br /&gt;
&lt;br /&gt;
==''' Implement Steps '''==&lt;br /&gt;
&lt;br /&gt;
=== Task 1  Add checkbox===&lt;br /&gt;
1. edit the file views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a checkbox at the top of the page which says &amp;quot;Vary rubric by topic&amp;quot;&lt;br /&gt;
&lt;br /&gt;
3. set the default state for this checkbox as unchecked&lt;br /&gt;
&lt;br /&gt;
===Task 2 Add dropdown list===&lt;br /&gt;
1. edit the file views/assignment/edit/_general.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a variable to indicate if the checkbox said in Task 1 is checked&lt;br /&gt;
&lt;br /&gt;
3. create a new file under views/sign_up_sheet called &amp;quot;_rubrics_list.html.erb&amp;quot; to store the code for the dropdown list&lt;br /&gt;
&lt;br /&gt;
4. edit the file views/sign_up_sheet/_table_line.html.erb&lt;br /&gt;
&lt;br /&gt;
5. add the code to render the dropdown list&lt;br /&gt;
&lt;br /&gt;
6. making a judgment before rendering the dropdown list, only if the checkbox in Task 1ist checked to render the page&lt;br /&gt;
&lt;br /&gt;
===Task 3 Change controllers===&lt;br /&gt;
Change the update method in sign_up_sheet_controller.rb to make sure when new rubric is chosen for a specific topic, it can be stored in the database properly&lt;br /&gt;
&lt;br /&gt;
===Task 4 Create migration===&lt;br /&gt;
1. create a new migration to add questionnaire_id in sign_up_topics&lt;br /&gt;
&lt;br /&gt;
2. the questionnaire_id is a foreign key which references to questionnaires&lt;br /&gt;
&lt;br /&gt;
3. change the file models/sign_up_topic.rb, and add the relations with the questionnaire, the relation between them is one-to-one&lt;br /&gt;
&lt;br /&gt;
===Task 5 Test the changes===&lt;br /&gt;
1. make a test plan for the features that need to be tested&lt;br /&gt;
&lt;br /&gt;
2. follow the test plan to write automatic test codes&lt;br /&gt;
&lt;br /&gt;
3. evaluate the results and refactor codes&lt;br /&gt;
&lt;br /&gt;
==''' Test plan '''==&lt;br /&gt;
We mainly use cucumber and capybara to test UI, and the following are detailed plans&lt;br /&gt;
&lt;br /&gt;
===Test checkbox===&lt;br /&gt;
1. go to the rubrics page under the assignment&lt;br /&gt;
&lt;br /&gt;
2. we can see the checkbox says &amp;quot;Vary rubric by topic&amp;quot; shows on this page&lt;br /&gt;
&lt;br /&gt;
3. the initial state of the checkbox is unchecked&lt;br /&gt;
&lt;br /&gt;
===Test dropdown list===&lt;br /&gt;
====Scenario 1====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is unchecked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3.there are no dropdown lists beside topics&lt;br /&gt;
====Scenario 2====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is checked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3. the table to show the topics have a row called &amp;quot;rubrics&amp;quot;&lt;br /&gt;
&lt;br /&gt;
4. under this title, each topic has a dropdown list&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120406</id>
		<title>CSC/ECE 517 Fall 2018/E1873 Specialized rubics for different topic types</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120406"/>
		<updated>2018-11-20T22:59:59Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Dropdown List */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==''' Introduction '''==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
One of the fantastic features that Expertiza provides is for each assignment, it allows students providing reviews for others' jobs. This is done by offering a pre-defined questionnaire for the whole assignment, which is called the rubric for this assignment. Each rubric has several questions, each question provides a criterion to evaluate the performance from a specific angle. Then students can evaluate the entire job by rating and answering these questions. The team did that job can also get a detailed feedback for different aspects of the project.&lt;br /&gt;
&lt;br /&gt;
=== Motivation ===&lt;br /&gt;
One of the problems for the review system is that for each assignment, different topics are included. Students can choose the one topic they like, and those topics fall into different categories. That is, an assignment always include different kind of projects. In Expertiza, the topic can be refactoring projects, testing projects, Mozilla projects,  etc. Apparently, for different kinds of projects, we have different criteria to evaluate their performance. However, due to the current design of the system, all projects belong to the same assignment can only have the same rubric, which may lead to unnecessary criteria for some projects and inadequate criteria for other projects. &lt;br /&gt;
To make sure all kinds of projects can be evaluated properly. We plan to refactor the system to allow assigning different rubies for different projects in a specified appointment.&lt;br /&gt;
&lt;br /&gt;
==''' Analysis &amp;amp; Plan '''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To realize such purpose, we have the following tasks need to be done:&lt;br /&gt;
&lt;br /&gt;
===Check Box===&lt;br /&gt;
For current design, the rubric used for a specified assignment is set at the following page. To make sure users can choose to set different rubrics for different projects, we need first add a checkbox at this page. Therefore, users can use this box to indicate if they want to use the same rubric for all the projects or set some different rubrics for some projects.&lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873rubric.png]]&lt;br /&gt;
&lt;br /&gt;
===Dropdown List===&lt;br /&gt;
To make sure users can choose rubrics for each project, we should add a new dropdown list beside each project in the following page. The number of dropdown list should decide by review round number. Therefore, each time users choose to identify different rubrics for different projects, the list will appear and users can choose proper rubrics. The default rubric set at last page will be overwritten in this case. &lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873project.png]]&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Make changes to the controller so that these functions can work. Most of our logic control codes will be written in ''helpers/sign_up_sheet_helper.rb''.&lt;br /&gt;
&lt;br /&gt;
logic flowchart:&lt;br /&gt;
&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
Add questionnaire_id in sign_up_topics table to make sure the projects can always relate to correct rubrics&lt;br /&gt;
&lt;br /&gt;
===Test===&lt;br /&gt;
Test what we changed to make sure it works as intended and not influence the original system.&lt;br /&gt;
&lt;br /&gt;
==''' Implement Steps '''==&lt;br /&gt;
&lt;br /&gt;
=== Task 1  Add checkbox===&lt;br /&gt;
1. edit the file views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a checkbox at the top of the page which says &amp;quot;Vary rubric by topic&amp;quot;&lt;br /&gt;
&lt;br /&gt;
3. set the default state for this checkbox as unchecked&lt;br /&gt;
&lt;br /&gt;
===Task 2 Add dropdown list===&lt;br /&gt;
1. edit the file views/assignment/edit/_general.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a variable to indicate if the checkbox said in Task 1 is checked&lt;br /&gt;
&lt;br /&gt;
3. create a new file under views/sign_up_sheet called &amp;quot;_rubrics_list.html.erb&amp;quot; to store the code for the dropdown list&lt;br /&gt;
&lt;br /&gt;
4. edit the file views/sign_up_sheet/_table_line.html.erb&lt;br /&gt;
&lt;br /&gt;
5. add the code to render the dropdown list&lt;br /&gt;
&lt;br /&gt;
6. making a judgment before rendering the dropdown list, only if the checkbox in Task 1ist checked to render the page&lt;br /&gt;
&lt;br /&gt;
===Task 3 Change controllers===&lt;br /&gt;
Change the update method in sign_up_sheet_controller.rb to make sure when new rubric is chosen for a specific topic, it can be stored in the database properly&lt;br /&gt;
&lt;br /&gt;
===Task 4 Create migration===&lt;br /&gt;
1. create a new migration to add questionnaire_id in sign_up_topics&lt;br /&gt;
&lt;br /&gt;
2. the questionnaire_id is a foreign key which references to questionnaires&lt;br /&gt;
&lt;br /&gt;
3. change the file models/sign_up_topic.rb, and add the relations with the questionnaire, the relation between them is one-to-one&lt;br /&gt;
&lt;br /&gt;
===Task 5 Test the changes===&lt;br /&gt;
1. make a test plan for the features that need to be tested&lt;br /&gt;
&lt;br /&gt;
2. follow the test plan to write automatic test codes&lt;br /&gt;
&lt;br /&gt;
3. evaluate the results and refactor codes&lt;br /&gt;
&lt;br /&gt;
==''' Test plan '''==&lt;br /&gt;
We mainly use cucumber and capybara to test UI, and the following are detailed plans&lt;br /&gt;
&lt;br /&gt;
===Test checkbox===&lt;br /&gt;
1. go to the rubrics page under the assignment&lt;br /&gt;
&lt;br /&gt;
2. we can see the checkbox says &amp;quot;Vary rubric by topic&amp;quot; shows on this page&lt;br /&gt;
&lt;br /&gt;
3. the initial state of the checkbox is unchecked&lt;br /&gt;
&lt;br /&gt;
===Test dropdown list===&lt;br /&gt;
====Scenario 1====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is unchecked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3.there are no dropdown lists beside topics&lt;br /&gt;
====Scenario 2====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is checked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3. the table to show the topics have a row called &amp;quot;rubrics&amp;quot;&lt;br /&gt;
&lt;br /&gt;
4. under this title, each topic has a dropdown list&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120403</id>
		<title>CSC/ECE 517 Fall 2018/E1873 Specialized rubics for different topic types</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120403"/>
		<updated>2018-11-20T22:56:17Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==''' Introduction '''==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
One of the fantastic features that Expertiza provides is for each assignment, it allows students providing reviews for others' jobs. This is done by offering a pre-defined questionnaire for the whole assignment, which is called the rubric for this assignment. Each rubric has several questions, each question provides a criterion to evaluate the performance from a specific angle. Then students can evaluate the entire job by rating and answering these questions. The team did that job can also get a detailed feedback for different aspects of the project.&lt;br /&gt;
&lt;br /&gt;
=== Motivation ===&lt;br /&gt;
One of the problems for the review system is that for each assignment, different topics are included. Students can choose the one topic they like, and those topics fall into different categories. That is, an assignment always include different kind of projects. In Expertiza, the topic can be refactoring projects, testing projects, Mozilla projects,  etc. Apparently, for different kinds of projects, we have different criteria to evaluate their performance. However, due to the current design of the system, all projects belong to the same assignment can only have the same rubric, which may lead to unnecessary criteria for some projects and inadequate criteria for other projects. &lt;br /&gt;
To make sure all kinds of projects can be evaluated properly. We plan to refactor the system to allow assigning different rubies for different projects in a specified appointment.&lt;br /&gt;
&lt;br /&gt;
==''' Analysis &amp;amp; Plan '''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To realize such purpose, we have the following tasks need to be done:&lt;br /&gt;
&lt;br /&gt;
===Check Box===&lt;br /&gt;
For current design, the rubric used for a specified assignment is set at the following page. To make sure users can choose to set different rubrics for different projects, we need first add a checkbox at this page. Therefore, users can use this box to indicate if they want to use the same rubric for all the projects or set some different rubrics for some projects.&lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873rubric.png]]&lt;br /&gt;
&lt;br /&gt;
===Dropdown List===&lt;br /&gt;
To make sure users can choose rubrics for each project, we should add a new dropdown list beside each project in the following page. Therefore, each time users choose to identify different rubrics for different projects, the list will appear and users can choose proper rubrics. The default rubric set at last page will be overwritten in this case.&lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873project.png]]&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Make changes to the controller so that these functions can work. Most of our logic control codes will be written in ''helpers/sign_up_sheet_helper.rb''.&lt;br /&gt;
&lt;br /&gt;
logic flowchart:&lt;br /&gt;
&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
Add questionnaire_id in sign_up_topics table to make sure the projects can always relate to correct rubrics&lt;br /&gt;
&lt;br /&gt;
===Test===&lt;br /&gt;
Test what we changed to make sure it works as intended and not influence the original system.&lt;br /&gt;
&lt;br /&gt;
==''' Implement Steps '''==&lt;br /&gt;
&lt;br /&gt;
=== Task 1  Add checkbox===&lt;br /&gt;
1. edit the file views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a checkbox at the top of the page which says &amp;quot;Vary rubric by topic&amp;quot;&lt;br /&gt;
&lt;br /&gt;
3. set the default state for this checkbox as unchecked&lt;br /&gt;
&lt;br /&gt;
===Task 2 Add dropdown list===&lt;br /&gt;
1. edit the file views/assignment/edit/_general.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a variable to indicate if the checkbox said in Task 1 is checked&lt;br /&gt;
&lt;br /&gt;
3. create a new file under views/sign_up_sheet called &amp;quot;_rubrics_list.html.erb&amp;quot; to store the code for the dropdown list&lt;br /&gt;
&lt;br /&gt;
4. edit the file views/sign_up_sheet/_table_line.html.erb&lt;br /&gt;
&lt;br /&gt;
5. add the code to render the dropdown list&lt;br /&gt;
&lt;br /&gt;
6. making a judgment before rendering the dropdown list, only if the checkbox in Task 1ist checked to render the page&lt;br /&gt;
&lt;br /&gt;
===Task 3 Change controllers===&lt;br /&gt;
Change the update method in sign_up_sheet_controller.rb to make sure when new rubric is chosen for a specific topic, it can be stored in the database properly&lt;br /&gt;
&lt;br /&gt;
===Task 4 Create migration===&lt;br /&gt;
1. create a new migration to add questionnaire_id in sign_up_topics&lt;br /&gt;
&lt;br /&gt;
2. the questionnaire_id is a foreign key which references to questionnaires&lt;br /&gt;
&lt;br /&gt;
3. change the file models/sign_up_topic.rb, and add the relations with the questionnaire, the relation between them is one-to-one&lt;br /&gt;
&lt;br /&gt;
===Task 5 Test the changes===&lt;br /&gt;
1. make a test plan for the features that need to be tested&lt;br /&gt;
&lt;br /&gt;
2. follow the test plan to write automatic test codes&lt;br /&gt;
&lt;br /&gt;
3. evaluate the results and refactor codes&lt;br /&gt;
&lt;br /&gt;
==''' Test plan '''==&lt;br /&gt;
We mainly use cucumber and capybara to test UI, and the following are detailed plans&lt;br /&gt;
&lt;br /&gt;
===Test checkbox===&lt;br /&gt;
1. go to the rubrics page under the assignment&lt;br /&gt;
&lt;br /&gt;
2. we can see the checkbox says &amp;quot;Vary rubric by topic&amp;quot; shows on this page&lt;br /&gt;
&lt;br /&gt;
3. the initial state of the checkbox is unchecked&lt;br /&gt;
&lt;br /&gt;
===Test dropdown list===&lt;br /&gt;
====Scenario 1====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is unchecked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3.there are no dropdown lists beside topics&lt;br /&gt;
====Scenario 2====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is checked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3. the table to show the topics have a row called &amp;quot;rubrics&amp;quot;&lt;br /&gt;
&lt;br /&gt;
4. under this title, each topic has a dropdown list&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120400</id>
		<title>CSC/ECE 517 Fall 2018/E1873 Specialized rubics for different topic types</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/E1873_Specialized_rubics_for_different_topic_types&amp;diff=120400"/>
		<updated>2018-11-20T22:41:23Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==''' Introduction '''==&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
One of the fantastic features that Expertiza provides is for each assignment, it allows students providing reviews for others' jobs. This is done by offering a pre-defined questionnaire for the whole assignment, which is called the rubric for this assignment. Each rubric has several questions, each question provides a criterion to evaluate the performance from a specific angle. Then students can evaluate the entire job by rating and answering these questions. The team did that job can also get a detailed feedback for different aspects of the project.&lt;br /&gt;
&lt;br /&gt;
=== Motivation ===&lt;br /&gt;
One of the problems for the review system is that for each assignment, different topics are included. Students can choose the one topic they like, and those topics fall into different categories. That is, an assignment always include different kind of projects. In Expertiza, the topic can be refactoring projects, testing projects, Mozilla projects,  etc. Apparently, for different kinds of projects, we have different criteria to evaluate their performance. However, due to the current design of the system, all projects belong to the same assignment can only have the same rubric, which may lead to unnecessary criteria for some projects and inadequate criteria for other projects. &lt;br /&gt;
To make sure all kinds of projects can be evaluated properly. We plan to refactor the system to allow assigning different rubies for different projects in a specified appointment.&lt;br /&gt;
&lt;br /&gt;
==''' Analysis &amp;amp; Plan '''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To realize such purpose, we have the following tasks need to be done:&lt;br /&gt;
&lt;br /&gt;
===Check Box===&lt;br /&gt;
For current design, the rubric used for a specified assignment is set at the following page. To make sure users can choose to set different rubrics for different projects, we need first add a checkbox at this page. Therefore, users can use this box to indicate if they want to use the same rubric for all the projects or set some different rubrics for some projects.&lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873rubric.png]]&lt;br /&gt;
&lt;br /&gt;
===Dropdown List===&lt;br /&gt;
To make sure users can choose rubrics for each project, we should add a new dropdown list beside each project in the following page. Therefore, each time users choose to identify different rubrics for different projects, the list will appear and users can choose proper rubrics. The default rubric set at last page will be overwritten in this case.&lt;br /&gt;
&lt;br /&gt;
[[File:2018F1873project.png]]&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Make changes to the controller so that these functions can work. Most of our logic control codes will be written in ''helpers/sign_up_sheet_helper.rb''.&lt;br /&gt;
&lt;br /&gt;
logic flowchart:&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
Add questionnaire_id in sign_up_topics table to make sure the projects can always relate to correct rubrics&lt;br /&gt;
&lt;br /&gt;
===Test===&lt;br /&gt;
Test what we changed to make sure it works as intended and not influence the original system.&lt;br /&gt;
&lt;br /&gt;
==''' Implement Steps '''==&lt;br /&gt;
&lt;br /&gt;
=== Task 1  Add checkbox===&lt;br /&gt;
1. edit the file views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a checkbox at the top of the page which says &amp;quot;Vary rubric by topic&amp;quot;&lt;br /&gt;
&lt;br /&gt;
3. set the default state for this checkbox as unchecked&lt;br /&gt;
&lt;br /&gt;
===Task 2 Add dropdown list===&lt;br /&gt;
1. edit the file views/assignment/edit/_general.html.erb&lt;br /&gt;
&lt;br /&gt;
2. add a variable to indicate if the checkbox said in Task 1 is checked&lt;br /&gt;
&lt;br /&gt;
3. create a new file under views/sign_up_sheet called &amp;quot;_rubrics_list.html.erb&amp;quot; to store the code for the dropdown list&lt;br /&gt;
&lt;br /&gt;
4. edit the file views/sign_up_sheet/_table_line.html.erb&lt;br /&gt;
&lt;br /&gt;
5. add the code to render the dropdown list&lt;br /&gt;
&lt;br /&gt;
6. making a judgment before rendering the dropdown list, only if the checkbox in Task 1ist checked to render the page&lt;br /&gt;
&lt;br /&gt;
===Task 3 Change controllers===&lt;br /&gt;
Change the update method in sign_up_sheet_controller.rb to make sure when new rubric is chosen for a specific topic, it can be stored in the database properly&lt;br /&gt;
&lt;br /&gt;
===Task 4 Create migration===&lt;br /&gt;
1. create a new migration to add questionnaire_id in sign_up_topics&lt;br /&gt;
&lt;br /&gt;
2. the questionnaire_id is a foreign key which references to questionnaires&lt;br /&gt;
&lt;br /&gt;
3. change the file models/sign_up_topic.rb, and add the relations with the questionnaire, the relation between them is one-to-one&lt;br /&gt;
&lt;br /&gt;
===Task 5 Test the changes===&lt;br /&gt;
1. make a test plan for the features that need to be tested&lt;br /&gt;
&lt;br /&gt;
2. follow the test plan to write automatic test codes&lt;br /&gt;
&lt;br /&gt;
3. evaluate the results and refactor codes&lt;br /&gt;
&lt;br /&gt;
==''' Test plan '''==&lt;br /&gt;
We mainly use cucumber and capybara to test UI, and the following are detailed plans&lt;br /&gt;
&lt;br /&gt;
===Test checkbox===&lt;br /&gt;
1. go to the rubrics page under the assignment&lt;br /&gt;
&lt;br /&gt;
2. we can see the checkbox says &amp;quot;Vary rubric by topic&amp;quot; shows on this page&lt;br /&gt;
&lt;br /&gt;
3. the initial state of the checkbox is unchecked&lt;br /&gt;
&lt;br /&gt;
===Test dropdown list===&lt;br /&gt;
====Scenario 1====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is unchecked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3.there are no dropdown lists beside topics&lt;br /&gt;
====Scenario 2====&lt;br /&gt;
1. the checkbox &amp;quot;Vary rubric by topic&amp;quot; is checked&lt;br /&gt;
&lt;br /&gt;
2. go to the topics page under assignment&lt;br /&gt;
&lt;br /&gt;
3. the table to show the topics have a row called &amp;quot;rubrics&amp;quot;&lt;br /&gt;
&lt;br /&gt;
4. under this title, each topic has a dropdown list&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118534</id>
		<title>CSC/ECE 517 Fall 2018/OSS E1848 Write unit tests for assignment team.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118534"/>
		<updated>2018-11-03T03:24:57Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Lets */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For this project, the goal is to write up unit tests for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
Assignment_team.rb in Expertiza provides a method for student to assign a team and finish one assignment. Features come at the cost of complexity; this project is focused on creating the test methods to ensure that user interaction with the assignment interface remains stable and reliable.&lt;br /&gt;
&lt;br /&gt;
=='''Bugs in assignment_team.rb'''==&lt;br /&gt;
We found some bugs in assignment_team.rb:&lt;br /&gt;
*In assign_reviewer(reviewer)&lt;br /&gt;
  42: assignment = Assignment.find(self.parent_id) =&amp;gt; assignment = Assignment.find_by(id: parent_id)&lt;br /&gt;
*In self.import(row, assignment_id, options)&lt;br /&gt;
  108: id.to_s =&amp;gt; assignment_id.to_s&lt;br /&gt;
  The id doesn't exist in the AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=='''Let'''==&lt;br /&gt;
We Use let to define a memoized helper method. The value will be cached across multiple calls in the same example but not across examples.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  let(:user) { User.new(id: 1) }&lt;br /&gt;
  let(:assignment_team) { build(:assignment_team, id: 2, parent_id: 2, name: &amp;quot;team2&amp;quot;, users: [user], submitted_hyperlinks: &amp;quot;https://www.1.ncsu.edu&amp;quot;) }&lt;br /&gt;
  let(:assignment_team1) { build(:assignment_team, id: 1, parent_id: 1, name: &amp;quot;team1&amp;quot;, submitted_hyperlinks: &amp;quot;&amp;quot;) }&lt;br /&gt;
  let(:assignment_team2) { build(:assignment_team, id: 3, parent_id: 3, directory_num: -1) }&lt;br /&gt;
  let(:questions) { {QuizQuestionnaire: double(:question)} }&lt;br /&gt;
  let(:questionnaire) { build(:questionnaire) }&lt;br /&gt;
  let(:assignment) { build(:assignment, id: 1, questionnaires: [questionnaire], name: 'Test Assgt') }&lt;br /&gt;
  let(:courseTeam) { build(:course_team, id: 1) }&lt;br /&gt;
  let(:team) { build(:assignment_team) }&lt;br /&gt;
  let(:team_user) { build(:team_user) }&lt;br /&gt;
  let(:team_without_submitted_hyperlinks) { build(:assignment_team, submitted_hyperlinks: &amp;quot;&amp;quot;) }&lt;br /&gt;
  let(:participant1) { build(:participant, id: 1, user: build(:student, id: 1, name: 'no name', fullname: 'no one')) }&lt;br /&gt;
  let(:participant2) { build(:participant, id: 2) }&lt;br /&gt;
  let(:review_response_map) { build(:review_response_map, id: 1, assignment: assignment, reviewer: participant1, reviewee: assignment_team1) }&lt;br /&gt;
  let(:signed_up_team) { build(:signed_up_team, id: 1, team_id: 1, is_waitlisted: 0, topic_id: 1) }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
There are some examples for how this project create test methods for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
===Create a team===&lt;br /&gt;
In assignment_team.rb,there is a method return the team given the participant.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.team(participant)&lt;br /&gt;
      return nil if participant.nil?&lt;br /&gt;
      team = nil&lt;br /&gt;
      teams_users = TeamsUser.where(user_id: participant.user_id)&lt;br /&gt;
      return nil unless teams_users&lt;br /&gt;
      teams_users.each do |teams_user|&lt;br /&gt;
        team = Team.find(teams_user.team_id)&lt;br /&gt;
        return team if team.parent_id == participant.parent_id&lt;br /&gt;
      end&lt;br /&gt;
      nil&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above method, the test case can be created, and there are three different possible results could be generated.&lt;br /&gt;
*when the participant is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there are not team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return(nil)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when the participant is not nil and there exist team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns the team given the participant&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return([team_user])&lt;br /&gt;
      allow(Team).to receive(:find).with(1).and_return(team)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove team by id===&lt;br /&gt;
The assignment_team.rb also provide a method which could remove team by id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.remove_team_by_id(id)&lt;br /&gt;
      old_team = AssignmentTeam.find(id)&lt;br /&gt;
      old_team.destroy unless old_team.nil?&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;deletes a team given the team id&amp;quot; do&lt;br /&gt;
      old_team = assignment_team1&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with(1).and_return(old_team)&lt;br /&gt;
      allow(old_team).to receive(:destroy).and_return(old_team)&lt;br /&gt;
      expect(AssignmentTeam.remove_team_by_id(1)).to eq(old_team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return the topic chosen by the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the topic chosen by the team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def topic&lt;br /&gt;
    SignedUpTeam.find_by(team_id: self.id, is_waitlisted: 0).try(:topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#topic&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the topic id chosen by this team&amp;quot; do&lt;br /&gt;
      allow(SignedUpTeam).to receive(:find_by).with(team_id:1, is_waitlisted: 0).and_return(signed_up_team1)&lt;br /&gt;
      expect(assignment_team1.topic).to eq(1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test examines the original codes ability to generate the topic that is chosen by the team because it first goes to the mocked instances to look for a team. In this case, to match the mock instance that has created, we look for the team that has team_id as 1, and not being waitlisted. The topic id is set to be 1 in the mock. This function returns 1, because it does return the topic id, for the team that has signed up for a topic.&lt;br /&gt;
&lt;br /&gt;
===Return whether the team has submission===&lt;br /&gt;
The assignment_team.rb offers a method that could return either true or false, in terms of whether the team has submitted work or not&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
    self.submitted_files.any? or self.submitted_hyperlinks.present?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created, and there are three possible results:&lt;br /&gt;
*when current assignment team submitted files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_files).and_return([double(:File)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit files but submitted hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_hyperlinks).and_return([double(:Hyperlink)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit either files or hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return participants of a team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the participants of a team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def participants&lt;br /&gt;
    users = self.users&lt;br /&gt;
    participants = []&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: self.parent_id)&lt;br /&gt;
      participants &amp;lt;&amp;lt; participant unless participant.nil?&lt;br /&gt;
    end&lt;br /&gt;
    participants&lt;br /&gt;
  end&lt;br /&gt;
  alias get_participants participants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#participants&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns participants of the current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 2).and_return(participant2)&lt;br /&gt;
      expect(assignment_team.participants).to eq([participant2])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return the first member of the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the first member of the team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_first_member(team_id)&lt;br /&gt;
    find_by(id: team_id).try(:participants).try(:first)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;.get_first_member&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the first participant of current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentTeam).to receive_message_chain(:find_by, :try, :try).with(id: 1).with(:participants).with(:first).and_return(participant1)&lt;br /&gt;
      expect(AssignmentTeam.get_first_member(1)).to eq(participant1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Import csv file to form teams directly===&lt;br /&gt;
The assignment_team.rb offers a method that could import csv file to form teams directly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.import(row, assignment_id, options)&lt;br /&gt;
    unless Assignment.find_by(id: assignment_id)&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with the id \&amp;quot;&amp;quot; + assignment_id.to_s + &amp;quot;\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    @assignment_team = prototype&lt;br /&gt;
    Team.import(row, assignment_id, options, @assignment_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
*when there is no assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there is no assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;raises an ImportError&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 1).and_return(nil)&lt;br /&gt;
        expect { AssignmentTeam.import([], 1, has_column_names: 'false') }&lt;br /&gt;
            .to raise_error(ImportError, &amp;quot;The assignment with the id \&amp;quot;1\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there exists an assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there exists an assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;imports a csv file to form assignment teams&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 2).and_return(double(&amp;quot;Assignment&amp;quot;, id: 2))&lt;br /&gt;
        allow(AssignmentTeam).to receive(:prototype).and_return(assignment_team)&lt;br /&gt;
        allow(Team).to receive(:import).with([], 2, {}, assignment_team).and_return(true)&lt;br /&gt;
        expect(AssignmentTeam.import([], 2, {})).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Copy the current Assignment team to the CourseTeam===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy(course_id)&lt;br /&gt;
    new_team = CourseTeam.create_team_and_node(course_id)&lt;br /&gt;
    new_team.name = name&lt;br /&gt;
    new_team.save&lt;br /&gt;
    copy_members(new_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#copy&amp;quot; do&lt;br /&gt;
    it &amp;quot;copies the current assignment team and team members to a new course team&amp;quot; do&lt;br /&gt;
      allow(CourseTeam).to receive(:create_team_and_node).with(1).and_return(courseTeam)&lt;br /&gt;
      allow(Team).to receive(:copy_members).with(courseTeam).and_return([])&lt;br /&gt;
      expect(assignment_team.copy(1)).to eq([])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===return a hash of scores that the team has received for the questions===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def scores(questions)&lt;br /&gt;
    scores = {}&lt;br /&gt;
    scores[:team] = self # This doesn't appear to be used anywhere&lt;br /&gt;
    assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
      scores[questionnaire.symbol] = {}&lt;br /&gt;
      scores[questionnaire.symbol][:assessments] = ReviewResponseMap.where(reviewee_id: self.id)&lt;br /&gt;
      scores[questionnaire.symbol][:scores] = Answer.compute_scores(scores[questionnaire.symbol][:assessments], questions[questionnaire.symbol])&lt;br /&gt;
    end&lt;br /&gt;
    scores[:total_score] = assignment.compute_total_score(scores)&lt;br /&gt;
    scores&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#scores&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns a hash of scores that current assignment team has received for the questions&amp;quot; do&lt;br /&gt;
      allow(assignment_team).to receive(:assignment).and_return(assignment)&lt;br /&gt;
      allow(ReviewResponseMap).to receive(:where).with(reviewee_id: 2).and_return(review_response_map)&lt;br /&gt;
      allow(Answer).to receive(:compute_scores).with(review_response_map, questions[QuizQuestionnaire]).and_return(10)&lt;br /&gt;
      allow(assignment).to receive(:compute_total_score).and_return(10)&lt;br /&gt;
      # expect(assignment_team.scores(questions)[:QuizQuestionnaire]).equal?({assessments: review_response_map, scores: 10}).to be true&lt;br /&gt;
      expect(assignment_team.scores(questions)[:team]).to eq(assignment_team)&lt;br /&gt;
      expect(assignment_team.scores(questions)[:total_score]).to eq(10)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return whether assignment team exist corresponding response maps===&lt;br /&gt;
The assignment_team.rb offers a method that could judge whether there exist corresponding response maps.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def received_any_peer_review?&lt;br /&gt;
    ResponseMap.where(reviewee_id: self.id, reviewed_object_id: self.parent_id).any?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
*when there exist corresponding response map&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
        allow(ResponseMap).to receive(:where).with(reviewee_id: 1, reviewed_object_id: 1).and_return([double(:ResponseMap)])&lt;br /&gt;
        expect(assignment_team1.received_any_peer_review?).to be true&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there does not exist corresponding response maps&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
        allow(ResponseMap).to receive(:where).with(reviewee_id: 1, reviewed_object_id: 1).and_return([])&lt;br /&gt;
        expect(assignment_team1.received_any_peer_review?).to be false&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Set the directory num for this team===&lt;br /&gt;
The assignment_team.rb offers a method that could Set the directory num for this team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def set_student_directory_num&lt;br /&gt;
    return if self.directory_num and self.directory_num &amp;gt;= 0&lt;br /&gt;
    max_num = AssignmentTeam.where(parent_id: self.parent_id).order('directory_num desc').first.directory_num&lt;br /&gt;
    dir_num = max_num ? max_num + 1 : 0&lt;br /&gt;
    self.update_attributes(directory_num: dir_num)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#set_student_directory_num&amp;quot; do&lt;br /&gt;
    context &amp;quot;when there is no directory number for the assignment team&amp;quot; do&lt;br /&gt;
      it &amp;quot;sets a directory number for the assignment team&amp;quot; do&lt;br /&gt;
        # allow(assignment_team1).to receive(:try).with(:directory).and_return(-1)&lt;br /&gt;
        allow(AssignmentTeam).to receive_message_chain(:where, :order, :first, :directory_num).and_return(4)&lt;br /&gt;
        expect(assignment_team2.set_student_directory_num).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test can successfully test whether the team has submitted files/hyperlinks or not, because it creates a mock function, for the submitted_files function to receive a parameter - so that the team has hypothetically passed in a submitted file. The returning value being true shows that the has_submissions? test succeeded when the team receives a submitted file.&lt;br /&gt;
&lt;br /&gt;
Similarly, we created a mock function for the team to receive a hyperlink using submitted_hyperlink. This second test case returning true shows the hyperlink being submitted is also detected by the function.&lt;br /&gt;
&lt;br /&gt;
When there's no mock happening inside the function, no file or hyperlink will be passed into the team. So has_submissions? returns false is what's being expected.&lt;br /&gt;
&lt;br /&gt;
=='''Result'''==&lt;br /&gt;
Our test cases has coverage: 100%&lt;br /&gt;
&lt;br /&gt;
There are in total 127 relevant lines, and all of them get passed.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
The testing framework in the assignment_team_spec.rb used unit tests to test the functionality of each action in the class. The mock instances are created at the beginning of the file, so that during each test they don't need to be constructed again. In order to test each unit case without depending on other functionalities, the mocked actions, as well as the desired returns are built inside different test cases, depending on the need of the case.&lt;br /&gt;
&lt;br /&gt;
In building the test framework, the key is to understand the input, output and the desired action of each function that we want to test. The Rspec test format also has a steep learning curve, but the test shows stable and robust result on the assignment_team.rb.&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118533</id>
		<title>CSC/ECE 517 Fall 2018/OSS E1848 Write unit tests for assignment team.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118533"/>
		<updated>2018-11-03T03:24:32Z</updated>

		<summary type="html">&lt;p&gt;Jli94: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For this project, the goal is to write up unit tests for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
Assignment_team.rb in Expertiza provides a method for student to assign a team and finish one assignment. Features come at the cost of complexity; this project is focused on creating the test methods to ensure that user interaction with the assignment interface remains stable and reliable.&lt;br /&gt;
&lt;br /&gt;
=='''Bugs in assignment_team.rb'''==&lt;br /&gt;
We found some bugs in assignment_team.rb:&lt;br /&gt;
*In assign_reviewer(reviewer)&lt;br /&gt;
  42: assignment = Assignment.find(self.parent_id) =&amp;gt; assignment = Assignment.find_by(id: parent_id)&lt;br /&gt;
*In self.import(row, assignment_id, options)&lt;br /&gt;
  108: id.to_s =&amp;gt; assignment_id.to_s&lt;br /&gt;
  The id doesn't exist in the AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=='''Lets'''==&lt;br /&gt;
We Use let to define a memoized helper method. The value will be cached across multiple calls in the same example but not across examples.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  let(:user) { User.new(id: 1) }&lt;br /&gt;
  let(:assignment_team) { build(:assignment_team, id: 2, parent_id: 2, name: &amp;quot;team2&amp;quot;, users: [user], submitted_hyperlinks: &amp;quot;https://www.1.ncsu.edu&amp;quot;) }&lt;br /&gt;
  let(:assignment_team1) { build(:assignment_team, id: 1, parent_id: 1, name: &amp;quot;team1&amp;quot;, submitted_hyperlinks: &amp;quot;&amp;quot;) }&lt;br /&gt;
  let(:assignment_team2) { build(:assignment_team, id: 3, parent_id: 3, directory_num: -1) }&lt;br /&gt;
  let(:questions) { {QuizQuestionnaire: double(:question)} }&lt;br /&gt;
  let(:questionnaire) { build(:questionnaire) }&lt;br /&gt;
  let(:assignment) { build(:assignment, id: 1, questionnaires: [questionnaire], name: 'Test Assgt') }&lt;br /&gt;
  let(:courseTeam) { build(:course_team, id: 1) }&lt;br /&gt;
  let(:team) { build(:assignment_team) }&lt;br /&gt;
  let(:team_user) { build(:team_user) }&lt;br /&gt;
  let(:team_without_submitted_hyperlinks) { build(:assignment_team, submitted_hyperlinks: &amp;quot;&amp;quot;) }&lt;br /&gt;
  let(:participant1) { build(:participant, id: 1, user: build(:student, id: 1, name: 'no name', fullname: 'no one')) }&lt;br /&gt;
  let(:participant2) { build(:participant, id: 2) }&lt;br /&gt;
  let(:review_response_map) { build(:review_response_map, id: 1, assignment: assignment, reviewer: participant1, reviewee: assignment_team1) }&lt;br /&gt;
  let(:signed_up_team) { build(:signed_up_team, id: 1, team_id: 1, is_waitlisted: 0, topic_id: 1) }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
There are some examples for how this project create test methods for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
===Create a team===&lt;br /&gt;
In assignment_team.rb,there is a method return the team given the participant.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.team(participant)&lt;br /&gt;
      return nil if participant.nil?&lt;br /&gt;
      team = nil&lt;br /&gt;
      teams_users = TeamsUser.where(user_id: participant.user_id)&lt;br /&gt;
      return nil unless teams_users&lt;br /&gt;
      teams_users.each do |teams_user|&lt;br /&gt;
        team = Team.find(teams_user.team_id)&lt;br /&gt;
        return team if team.parent_id == participant.parent_id&lt;br /&gt;
      end&lt;br /&gt;
      nil&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above method, the test case can be created, and there are three different possible results could be generated.&lt;br /&gt;
*when the participant is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there are not team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return(nil)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when the participant is not nil and there exist team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns the team given the participant&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return([team_user])&lt;br /&gt;
      allow(Team).to receive(:find).with(1).and_return(team)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove team by id===&lt;br /&gt;
The assignment_team.rb also provide a method which could remove team by id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.remove_team_by_id(id)&lt;br /&gt;
      old_team = AssignmentTeam.find(id)&lt;br /&gt;
      old_team.destroy unless old_team.nil?&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;deletes a team given the team id&amp;quot; do&lt;br /&gt;
      old_team = assignment_team1&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with(1).and_return(old_team)&lt;br /&gt;
      allow(old_team).to receive(:destroy).and_return(old_team)&lt;br /&gt;
      expect(AssignmentTeam.remove_team_by_id(1)).to eq(old_team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return the topic chosen by the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the topic chosen by the team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def topic&lt;br /&gt;
    SignedUpTeam.find_by(team_id: self.id, is_waitlisted: 0).try(:topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#topic&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the topic id chosen by this team&amp;quot; do&lt;br /&gt;
      allow(SignedUpTeam).to receive(:find_by).with(team_id:1, is_waitlisted: 0).and_return(signed_up_team1)&lt;br /&gt;
      expect(assignment_team1.topic).to eq(1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test examines the original codes ability to generate the topic that is chosen by the team because it first goes to the mocked instances to look for a team. In this case, to match the mock instance that has created, we look for the team that has team_id as 1, and not being waitlisted. The topic id is set to be 1 in the mock. This function returns 1, because it does return the topic id, for the team that has signed up for a topic.&lt;br /&gt;
&lt;br /&gt;
===Return whether the team has submission===&lt;br /&gt;
The assignment_team.rb offers a method that could return either true or false, in terms of whether the team has submitted work or not&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
    self.submitted_files.any? or self.submitted_hyperlinks.present?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created, and there are three possible results:&lt;br /&gt;
*when current assignment team submitted files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_files).and_return([double(:File)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit files but submitted hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_hyperlinks).and_return([double(:Hyperlink)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit either files or hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return participants of a team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the participants of a team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def participants&lt;br /&gt;
    users = self.users&lt;br /&gt;
    participants = []&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: self.parent_id)&lt;br /&gt;
      participants &amp;lt;&amp;lt; participant unless participant.nil?&lt;br /&gt;
    end&lt;br /&gt;
    participants&lt;br /&gt;
  end&lt;br /&gt;
  alias get_participants participants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#participants&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns participants of the current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 2).and_return(participant2)&lt;br /&gt;
      expect(assignment_team.participants).to eq([participant2])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return the first member of the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the first member of the team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_first_member(team_id)&lt;br /&gt;
    find_by(id: team_id).try(:participants).try(:first)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;.get_first_member&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the first participant of current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentTeam).to receive_message_chain(:find_by, :try, :try).with(id: 1).with(:participants).with(:first).and_return(participant1)&lt;br /&gt;
      expect(AssignmentTeam.get_first_member(1)).to eq(participant1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Import csv file to form teams directly===&lt;br /&gt;
The assignment_team.rb offers a method that could import csv file to form teams directly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.import(row, assignment_id, options)&lt;br /&gt;
    unless Assignment.find_by(id: assignment_id)&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with the id \&amp;quot;&amp;quot; + assignment_id.to_s + &amp;quot;\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    @assignment_team = prototype&lt;br /&gt;
    Team.import(row, assignment_id, options, @assignment_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
*when there is no assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there is no assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;raises an ImportError&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 1).and_return(nil)&lt;br /&gt;
        expect { AssignmentTeam.import([], 1, has_column_names: 'false') }&lt;br /&gt;
            .to raise_error(ImportError, &amp;quot;The assignment with the id \&amp;quot;1\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there exists an assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there exists an assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;imports a csv file to form assignment teams&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 2).and_return(double(&amp;quot;Assignment&amp;quot;, id: 2))&lt;br /&gt;
        allow(AssignmentTeam).to receive(:prototype).and_return(assignment_team)&lt;br /&gt;
        allow(Team).to receive(:import).with([], 2, {}, assignment_team).and_return(true)&lt;br /&gt;
        expect(AssignmentTeam.import([], 2, {})).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Copy the current Assignment team to the CourseTeam===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy(course_id)&lt;br /&gt;
    new_team = CourseTeam.create_team_and_node(course_id)&lt;br /&gt;
    new_team.name = name&lt;br /&gt;
    new_team.save&lt;br /&gt;
    copy_members(new_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#copy&amp;quot; do&lt;br /&gt;
    it &amp;quot;copies the current assignment team and team members to a new course team&amp;quot; do&lt;br /&gt;
      allow(CourseTeam).to receive(:create_team_and_node).with(1).and_return(courseTeam)&lt;br /&gt;
      allow(Team).to receive(:copy_members).with(courseTeam).and_return([])&lt;br /&gt;
      expect(assignment_team.copy(1)).to eq([])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===return a hash of scores that the team has received for the questions===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def scores(questions)&lt;br /&gt;
    scores = {}&lt;br /&gt;
    scores[:team] = self # This doesn't appear to be used anywhere&lt;br /&gt;
    assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
      scores[questionnaire.symbol] = {}&lt;br /&gt;
      scores[questionnaire.symbol][:assessments] = ReviewResponseMap.where(reviewee_id: self.id)&lt;br /&gt;
      scores[questionnaire.symbol][:scores] = Answer.compute_scores(scores[questionnaire.symbol][:assessments], questions[questionnaire.symbol])&lt;br /&gt;
    end&lt;br /&gt;
    scores[:total_score] = assignment.compute_total_score(scores)&lt;br /&gt;
    scores&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#scores&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns a hash of scores that current assignment team has received for the questions&amp;quot; do&lt;br /&gt;
      allow(assignment_team).to receive(:assignment).and_return(assignment)&lt;br /&gt;
      allow(ReviewResponseMap).to receive(:where).with(reviewee_id: 2).and_return(review_response_map)&lt;br /&gt;
      allow(Answer).to receive(:compute_scores).with(review_response_map, questions[QuizQuestionnaire]).and_return(10)&lt;br /&gt;
      allow(assignment).to receive(:compute_total_score).and_return(10)&lt;br /&gt;
      # expect(assignment_team.scores(questions)[:QuizQuestionnaire]).equal?({assessments: review_response_map, scores: 10}).to be true&lt;br /&gt;
      expect(assignment_team.scores(questions)[:team]).to eq(assignment_team)&lt;br /&gt;
      expect(assignment_team.scores(questions)[:total_score]).to eq(10)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return whether assignment team exist corresponding response maps===&lt;br /&gt;
The assignment_team.rb offers a method that could judge whether there exist corresponding response maps.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def received_any_peer_review?&lt;br /&gt;
    ResponseMap.where(reviewee_id: self.id, reviewed_object_id: self.parent_id).any?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
*when there exist corresponding response map&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
        allow(ResponseMap).to receive(:where).with(reviewee_id: 1, reviewed_object_id: 1).and_return([double(:ResponseMap)])&lt;br /&gt;
        expect(assignment_team1.received_any_peer_review?).to be true&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there does not exist corresponding response maps&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
        allow(ResponseMap).to receive(:where).with(reviewee_id: 1, reviewed_object_id: 1).and_return([])&lt;br /&gt;
        expect(assignment_team1.received_any_peer_review?).to be false&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Set the directory num for this team===&lt;br /&gt;
The assignment_team.rb offers a method that could Set the directory num for this team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def set_student_directory_num&lt;br /&gt;
    return if self.directory_num and self.directory_num &amp;gt;= 0&lt;br /&gt;
    max_num = AssignmentTeam.where(parent_id: self.parent_id).order('directory_num desc').first.directory_num&lt;br /&gt;
    dir_num = max_num ? max_num + 1 : 0&lt;br /&gt;
    self.update_attributes(directory_num: dir_num)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#set_student_directory_num&amp;quot; do&lt;br /&gt;
    context &amp;quot;when there is no directory number for the assignment team&amp;quot; do&lt;br /&gt;
      it &amp;quot;sets a directory number for the assignment team&amp;quot; do&lt;br /&gt;
        # allow(assignment_team1).to receive(:try).with(:directory).and_return(-1)&lt;br /&gt;
        allow(AssignmentTeam).to receive_message_chain(:where, :order, :first, :directory_num).and_return(4)&lt;br /&gt;
        expect(assignment_team2.set_student_directory_num).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test can successfully test whether the team has submitted files/hyperlinks or not, because it creates a mock function, for the submitted_files function to receive a parameter - so that the team has hypothetically passed in a submitted file. The returning value being true shows that the has_submissions? test succeeded when the team receives a submitted file.&lt;br /&gt;
&lt;br /&gt;
Similarly, we created a mock function for the team to receive a hyperlink using submitted_hyperlink. This second test case returning true shows the hyperlink being submitted is also detected by the function.&lt;br /&gt;
&lt;br /&gt;
When there's no mock happening inside the function, no file or hyperlink will be passed into the team. So has_submissions? returns false is what's being expected.&lt;br /&gt;
&lt;br /&gt;
=='''Result'''==&lt;br /&gt;
Our test cases has coverage: 100%&lt;br /&gt;
&lt;br /&gt;
There are in total 127 relevant lines, and all of them get passed.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
The testing framework in the assignment_team_spec.rb used unit tests to test the functionality of each action in the class. The mock instances are created at the beginning of the file, so that during each test they don't need to be constructed again. In order to test each unit case without depending on other functionalities, the mocked actions, as well as the desired returns are built inside different test cases, depending on the need of the case.&lt;br /&gt;
&lt;br /&gt;
In building the test framework, the key is to understand the input, output and the desired action of each function that we want to test. The Rspec test format also has a steep learning curve, but the test shows stable and robust result on the assignment_team.rb.&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118531</id>
		<title>CSC/ECE 517 Fall 2018/OSS E1848 Write unit tests for assignment team.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118531"/>
		<updated>2018-11-03T03:20:33Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Bugs in assignment_team.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For this project, the goal is to write up unit tests for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
Assignment_team.rb in Expertiza provides a method for student to assign a team and finish one assignment. Features come at the cost of complexity; this project is focused on creating the test methods to ensure that user interaction with the assignment interface remains stable and reliable.&lt;br /&gt;
&lt;br /&gt;
=='''Bugs in assignment_team.rb'''==&lt;br /&gt;
We found some bugs in assignment_team.rb:&lt;br /&gt;
*In assign_reviewer(reviewer)&lt;br /&gt;
  42: assignment = Assignment.find(self.parent_id) =&amp;gt; assignment = Assignment.find_by(id: parent_id)&lt;br /&gt;
*In self.import(row, assignment_id, options)&lt;br /&gt;
  108: id.to_s =&amp;gt; assignment_id.to_s&lt;br /&gt;
  The id doesn't exist in the AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
There are some examples for how this project create test methods for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
===Create a team===&lt;br /&gt;
In assignment_team.rb,there is a method return the team given the participant.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.team(participant)&lt;br /&gt;
      return nil if participant.nil?&lt;br /&gt;
      team = nil&lt;br /&gt;
      teams_users = TeamsUser.where(user_id: participant.user_id)&lt;br /&gt;
      return nil unless teams_users&lt;br /&gt;
      teams_users.each do |teams_user|&lt;br /&gt;
        team = Team.find(teams_user.team_id)&lt;br /&gt;
        return team if team.parent_id == participant.parent_id&lt;br /&gt;
      end&lt;br /&gt;
      nil&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above method, the test case can be created, and there are three different possible results could be generated.&lt;br /&gt;
*when the participant is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there are not team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return(nil)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when the participant is not nil and there exist team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns the team given the participant&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return([team_user])&lt;br /&gt;
      allow(Team).to receive(:find).with(1).and_return(team)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove team by id===&lt;br /&gt;
The assignment_team.rb also provide a method which could remove team by id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.remove_team_by_id(id)&lt;br /&gt;
      old_team = AssignmentTeam.find(id)&lt;br /&gt;
      old_team.destroy unless old_team.nil?&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;deletes a team given the team id&amp;quot; do&lt;br /&gt;
      old_team = assignment_team1&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with(1).and_return(old_team)&lt;br /&gt;
      allow(old_team).to receive(:destroy).and_return(old_team)&lt;br /&gt;
      expect(AssignmentTeam.remove_team_by_id(1)).to eq(old_team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return the topic chosen by the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the topic chosen by the team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def topic&lt;br /&gt;
    SignedUpTeam.find_by(team_id: self.id, is_waitlisted: 0).try(:topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#topic&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the topic id chosen by this team&amp;quot; do&lt;br /&gt;
      allow(SignedUpTeam).to receive(:find_by).with(team_id:1, is_waitlisted: 0).and_return(signed_up_team1)&lt;br /&gt;
      expect(assignment_team1.topic).to eq(1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test examines the original codes ability to generate the topic that is chosen by the team because it first goes to the mocked instances to look for a team. In this case, to match the mock instance that has created, we look for the team that has team_id as 1, and not being waitlisted. The topic id is set to be 1 in the mock. This function returns 1, because it does return the topic id, for the team that has signed up for a topic.&lt;br /&gt;
&lt;br /&gt;
===Return whether the team has submission===&lt;br /&gt;
The assignment_team.rb offers a method that could return either true or false, in terms of whether the team has submitted work or not&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
    self.submitted_files.any? or self.submitted_hyperlinks.present?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created, and there are three possible results:&lt;br /&gt;
*when current assignment team submitted files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_files).and_return([double(:File)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit files but submitted hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_hyperlinks).and_return([double(:Hyperlink)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit either files or hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return participants of a team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the participants of a team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def participants&lt;br /&gt;
    users = self.users&lt;br /&gt;
    participants = []&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: self.parent_id)&lt;br /&gt;
      participants &amp;lt;&amp;lt; participant unless participant.nil?&lt;br /&gt;
    end&lt;br /&gt;
    participants&lt;br /&gt;
  end&lt;br /&gt;
  alias get_participants participants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#participants&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns participants of the current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 2).and_return(participant2)&lt;br /&gt;
      expect(assignment_team.participants).to eq([participant2])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return the first member of the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the first member of the team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_first_member(team_id)&lt;br /&gt;
    find_by(id: team_id).try(:participants).try(:first)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;.get_first_member&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the first participant of current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentTeam).to receive_message_chain(:find_by, :try, :try).with(id: 1).with(:participants).with(:first).and_return(participant1)&lt;br /&gt;
      expect(AssignmentTeam.get_first_member(1)).to eq(participant1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Import csv file to form teams directly===&lt;br /&gt;
The assignment_team.rb offers a method that could import csv file to form teams directly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.import(row, assignment_id, options)&lt;br /&gt;
    unless Assignment.find_by(id: assignment_id)&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with the id \&amp;quot;&amp;quot; + assignment_id.to_s + &amp;quot;\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    @assignment_team = prototype&lt;br /&gt;
    Team.import(row, assignment_id, options, @assignment_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
*when there is no assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there is no assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;raises an ImportError&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 1).and_return(nil)&lt;br /&gt;
        expect { AssignmentTeam.import([], 1, has_column_names: 'false') }&lt;br /&gt;
            .to raise_error(ImportError, &amp;quot;The assignment with the id \&amp;quot;1\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there exists an assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there exists an assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;imports a csv file to form assignment teams&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 2).and_return(double(&amp;quot;Assignment&amp;quot;, id: 2))&lt;br /&gt;
        allow(AssignmentTeam).to receive(:prototype).and_return(assignment_team)&lt;br /&gt;
        allow(Team).to receive(:import).with([], 2, {}, assignment_team).and_return(true)&lt;br /&gt;
        expect(AssignmentTeam.import([], 2, {})).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Copy the current Assignment team to the CourseTeam===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy(course_id)&lt;br /&gt;
    new_team = CourseTeam.create_team_and_node(course_id)&lt;br /&gt;
    new_team.name = name&lt;br /&gt;
    new_team.save&lt;br /&gt;
    copy_members(new_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#copy&amp;quot; do&lt;br /&gt;
    it &amp;quot;copies the current assignment team and team members to a new course team&amp;quot; do&lt;br /&gt;
      allow(CourseTeam).to receive(:create_team_and_node).with(1).and_return(courseTeam)&lt;br /&gt;
      allow(Team).to receive(:copy_members).with(courseTeam).and_return([])&lt;br /&gt;
      expect(assignment_team.copy(1)).to eq([])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===return a hash of scores that the team has received for the questions===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def scores(questions)&lt;br /&gt;
    scores = {}&lt;br /&gt;
    scores[:team] = self # This doesn't appear to be used anywhere&lt;br /&gt;
    assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
      scores[questionnaire.symbol] = {}&lt;br /&gt;
      scores[questionnaire.symbol][:assessments] = ReviewResponseMap.where(reviewee_id: self.id)&lt;br /&gt;
      scores[questionnaire.symbol][:scores] = Answer.compute_scores(scores[questionnaire.symbol][:assessments], questions[questionnaire.symbol])&lt;br /&gt;
    end&lt;br /&gt;
    scores[:total_score] = assignment.compute_total_score(scores)&lt;br /&gt;
    scores&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#scores&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns a hash of scores that current assignment team has received for the questions&amp;quot; do&lt;br /&gt;
      allow(assignment_team).to receive(:assignment).and_return(assignment)&lt;br /&gt;
      allow(ReviewResponseMap).to receive(:where).with(reviewee_id: 2).and_return(review_response_map)&lt;br /&gt;
      allow(Answer).to receive(:compute_scores).with(review_response_map, questions[QuizQuestionnaire]).and_return(10)&lt;br /&gt;
      allow(assignment).to receive(:compute_total_score).and_return(10)&lt;br /&gt;
      # expect(assignment_team.scores(questions)[:QuizQuestionnaire]).equal?({assessments: review_response_map, scores: 10}).to be true&lt;br /&gt;
      expect(assignment_team.scores(questions)[:team]).to eq(assignment_team)&lt;br /&gt;
      expect(assignment_team.scores(questions)[:total_score]).to eq(10)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return whether assignment team exist corresponding response maps===&lt;br /&gt;
The assignment_team.rb offers a method that could judge whether there exist corresponding response maps.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def received_any_peer_review?&lt;br /&gt;
    ResponseMap.where(reviewee_id: self.id, reviewed_object_id: self.parent_id).any?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
*when there exist corresponding response map&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
        allow(ResponseMap).to receive(:where).with(reviewee_id: 1, reviewed_object_id: 1).and_return([double(:ResponseMap)])&lt;br /&gt;
        expect(assignment_team1.received_any_peer_review?).to be true&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there does not exist corresponding response maps&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
        allow(ResponseMap).to receive(:where).with(reviewee_id: 1, reviewed_object_id: 1).and_return([])&lt;br /&gt;
        expect(assignment_team1.received_any_peer_review?).to be false&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Set the directory num for this team===&lt;br /&gt;
The assignment_team.rb offers a method that could Set the directory num for this team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def set_student_directory_num&lt;br /&gt;
    return if self.directory_num and self.directory_num &amp;gt;= 0&lt;br /&gt;
    max_num = AssignmentTeam.where(parent_id: self.parent_id).order('directory_num desc').first.directory_num&lt;br /&gt;
    dir_num = max_num ? max_num + 1 : 0&lt;br /&gt;
    self.update_attributes(directory_num: dir_num)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#set_student_directory_num&amp;quot; do&lt;br /&gt;
    context &amp;quot;when there is no directory number for the assignment team&amp;quot; do&lt;br /&gt;
      it &amp;quot;sets a directory number for the assignment team&amp;quot; do&lt;br /&gt;
        # allow(assignment_team1).to receive(:try).with(:directory).and_return(-1)&lt;br /&gt;
        allow(AssignmentTeam).to receive_message_chain(:where, :order, :first, :directory_num).and_return(4)&lt;br /&gt;
        expect(assignment_team2.set_student_directory_num).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test can successfully test whether the team has submitted files/hyperlinks or not, because it creates a mock function, for the submitted_files function to receive a parameter - so that the team has hypothetically passed in a submitted file. The returning value being true shows that the has_submissions? test succeeded when the team receives a submitted file.&lt;br /&gt;
&lt;br /&gt;
Similarly, we created a mock function for the team to receive a hyperlink using submitted_hyperlink. This second test case returning true shows the hyperlink being submitted is also detected by the function.&lt;br /&gt;
&lt;br /&gt;
When there's no mock happening inside the function, no file or hyperlink will be passed into the team. So has_submissions? returns false is what's being expected.&lt;br /&gt;
&lt;br /&gt;
=='''Result'''==&lt;br /&gt;
Our test cases has coverage: 100%&lt;br /&gt;
&lt;br /&gt;
There are in total 127 relevant lines, and all of them get passed.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
The testing framework in the assignment_team_spec.rb used unit tests to test the functionality of each action in the class. The mock instances are created at the beginning of the file, so that during each test they don't need to be constructed again. In order to test each unit case without depending on other functionalities, the mocked actions, as well as the desired returns are built inside different test cases, depending on the need of the case.&lt;br /&gt;
&lt;br /&gt;
In building the test framework, the key is to understand the input, output and the desired action of each function that we want to test. The Rspec test format also has a steep learning curve, but the test shows stable and robust result on the assignment_team.rb.&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118530</id>
		<title>CSC/ECE 517 Fall 2018/OSS E1848 Write unit tests for assignment team.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118530"/>
		<updated>2018-11-03T03:18:05Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Bugs in assignment_team.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For this project, the goal is to write up unit tests for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
Assignment_team.rb in Expertiza provides a method for student to assign a team and finish one assignment. Features come at the cost of complexity; this project is focused on creating the test methods to ensure that user interaction with the assignment interface remains stable and reliable.&lt;br /&gt;
&lt;br /&gt;
=='''Bugs in assignment_team.rb'''==&lt;br /&gt;
We found some bugs in assignment_team.rb:&lt;br /&gt;
*In assign_reviewer(reviewer)&lt;br /&gt;
assignment = Assignment.find(self.parent_id) =&amp;gt; assignment = Assignment.find_by(id: parent_id)&lt;br /&gt;
*In self.import(row, assignment_id, options)&lt;br /&gt;
108: raise ImportError, &amp;quot;The assignment with the id \&amp;quot;&amp;quot; + id.to_s + &amp;quot;\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
=&amp;gt;raise ImportError, &amp;quot;The assignment with the id \&amp;quot;&amp;quot; + assignment_id.to_s + &amp;quot;\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
The id dose't exist in the AssignmentTeam&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
There are some examples for how this project create test methods for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
===Create a team===&lt;br /&gt;
In assignment_team.rb,there is a method return the team given the participant.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.team(participant)&lt;br /&gt;
      return nil if participant.nil?&lt;br /&gt;
      team = nil&lt;br /&gt;
      teams_users = TeamsUser.where(user_id: participant.user_id)&lt;br /&gt;
      return nil unless teams_users&lt;br /&gt;
      teams_users.each do |teams_user|&lt;br /&gt;
        team = Team.find(teams_user.team_id)&lt;br /&gt;
        return team if team.parent_id == participant.parent_id&lt;br /&gt;
      end&lt;br /&gt;
      nil&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above method, the test case can be created, and there are three different possible results could be generated.&lt;br /&gt;
*when the participant is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there are not team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return(nil)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when the participant is not nil and there exist team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns the team given the participant&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return([team_user])&lt;br /&gt;
      allow(Team).to receive(:find).with(1).and_return(team)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove team by id===&lt;br /&gt;
The assignment_team.rb also provide a method which could remove team by id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.remove_team_by_id(id)&lt;br /&gt;
      old_team = AssignmentTeam.find(id)&lt;br /&gt;
      old_team.destroy unless old_team.nil?&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;deletes a team given the team id&amp;quot; do&lt;br /&gt;
      old_team = assignment_team1&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with(1).and_return(old_team)&lt;br /&gt;
      allow(old_team).to receive(:destroy).and_return(old_team)&lt;br /&gt;
      expect(AssignmentTeam.remove_team_by_id(1)).to eq(old_team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return the topic chosen by the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the topic chosen by the team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def topic&lt;br /&gt;
    SignedUpTeam.find_by(team_id: self.id, is_waitlisted: 0).try(:topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#topic&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the topic id chosen by this team&amp;quot; do&lt;br /&gt;
      allow(SignedUpTeam).to receive(:find_by).with(team_id:1, is_waitlisted: 0).and_return(signed_up_team1)&lt;br /&gt;
      expect(assignment_team1.topic).to eq(1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test examines the original codes ability to generate the topic that is chosen by the team because it first goes to the mocked instances to look for a team. In this case, to match the mock instance that has created, we look for the team that has team_id as 1, and not being waitlisted. The topic id is set to be 1 in the mock. This function returns 1, because it does return the topic id, for the team that has signed up for a topic.&lt;br /&gt;
&lt;br /&gt;
===Return whether the team has submission===&lt;br /&gt;
The assignment_team.rb offers a method that could return either true or false, in terms of whether the team has submitted work or not&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
    self.submitted_files.any? or self.submitted_hyperlinks.present?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created, and there are three possible results:&lt;br /&gt;
*when current assignment team submitted files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_files).and_return([double(:File)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit files but submitted hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_hyperlinks).and_return([double(:Hyperlink)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit either files or hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return participants of a team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the participants of a team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def participants&lt;br /&gt;
    users = self.users&lt;br /&gt;
    participants = []&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: self.parent_id)&lt;br /&gt;
      participants &amp;lt;&amp;lt; participant unless participant.nil?&lt;br /&gt;
    end&lt;br /&gt;
    participants&lt;br /&gt;
  end&lt;br /&gt;
  alias get_participants participants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#participants&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns participants of the current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 2).and_return(participant2)&lt;br /&gt;
      expect(assignment_team.participants).to eq([participant2])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return the first member of the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the first member of the team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_first_member(team_id)&lt;br /&gt;
    find_by(id: team_id).try(:participants).try(:first)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;.get_first_member&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the first participant of current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentTeam).to receive_message_chain(:find_by, :try, :try).with(id: 1).with(:participants).with(:first).and_return(participant1)&lt;br /&gt;
      expect(AssignmentTeam.get_first_member(1)).to eq(participant1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Import csv file to form teams directly===&lt;br /&gt;
The assignment_team.rb offers a method that could import csv file to form teams directly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.import(row, assignment_id, options)&lt;br /&gt;
    unless Assignment.find_by(id: assignment_id)&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with the id \&amp;quot;&amp;quot; + assignment_id.to_s + &amp;quot;\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    @assignment_team = prototype&lt;br /&gt;
    Team.import(row, assignment_id, options, @assignment_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
*when there is no assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there is no assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;raises an ImportError&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 1).and_return(nil)&lt;br /&gt;
        expect { AssignmentTeam.import([], 1, has_column_names: 'false') }&lt;br /&gt;
            .to raise_error(ImportError, &amp;quot;The assignment with the id \&amp;quot;1\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there exists an assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there exists an assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;imports a csv file to form assignment teams&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 2).and_return(double(&amp;quot;Assignment&amp;quot;, id: 2))&lt;br /&gt;
        allow(AssignmentTeam).to receive(:prototype).and_return(assignment_team)&lt;br /&gt;
        allow(Team).to receive(:import).with([], 2, {}, assignment_team).and_return(true)&lt;br /&gt;
        expect(AssignmentTeam.import([], 2, {})).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Copy the current Assignment team to the CourseTeam===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy(course_id)&lt;br /&gt;
    new_team = CourseTeam.create_team_and_node(course_id)&lt;br /&gt;
    new_team.name = name&lt;br /&gt;
    new_team.save&lt;br /&gt;
    copy_members(new_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#copy&amp;quot; do&lt;br /&gt;
    it &amp;quot;copies the current assignment team and team members to a new course team&amp;quot; do&lt;br /&gt;
      allow(CourseTeam).to receive(:create_team_and_node).with(1).and_return(courseTeam)&lt;br /&gt;
      allow(Team).to receive(:copy_members).with(courseTeam).and_return([])&lt;br /&gt;
      expect(assignment_team.copy(1)).to eq([])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===return a hash of scores that the team has received for the questions===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def scores(questions)&lt;br /&gt;
    scores = {}&lt;br /&gt;
    scores[:team] = self # This doesn't appear to be used anywhere&lt;br /&gt;
    assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
      scores[questionnaire.symbol] = {}&lt;br /&gt;
      scores[questionnaire.symbol][:assessments] = ReviewResponseMap.where(reviewee_id: self.id)&lt;br /&gt;
      scores[questionnaire.symbol][:scores] = Answer.compute_scores(scores[questionnaire.symbol][:assessments], questions[questionnaire.symbol])&lt;br /&gt;
    end&lt;br /&gt;
    scores[:total_score] = assignment.compute_total_score(scores)&lt;br /&gt;
    scores&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#scores&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns a hash of scores that current assignment team has received for the questions&amp;quot; do&lt;br /&gt;
      allow(assignment_team).to receive(:assignment).and_return(assignment)&lt;br /&gt;
      allow(ReviewResponseMap).to receive(:where).with(reviewee_id: 2).and_return(review_response_map)&lt;br /&gt;
      allow(Answer).to receive(:compute_scores).with(review_response_map, questions[QuizQuestionnaire]).and_return(10)&lt;br /&gt;
      allow(assignment).to receive(:compute_total_score).and_return(10)&lt;br /&gt;
      # expect(assignment_team.scores(questions)[:QuizQuestionnaire]).equal?({assessments: review_response_map, scores: 10}).to be true&lt;br /&gt;
      expect(assignment_team.scores(questions)[:team]).to eq(assignment_team)&lt;br /&gt;
      expect(assignment_team.scores(questions)[:total_score]).to eq(10)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return whether assignment team exist corresponding response maps===&lt;br /&gt;
The assignment_team.rb offers a method that could judge whether there exist corresponding response maps.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def received_any_peer_review?&lt;br /&gt;
    ResponseMap.where(reviewee_id: self.id, reviewed_object_id: self.parent_id).any?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
*when there exist corresponding response map&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
        allow(ResponseMap).to receive(:where).with(reviewee_id: 1, reviewed_object_id: 1).and_return([double(:ResponseMap)])&lt;br /&gt;
        expect(assignment_team1.received_any_peer_review?).to be true&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there does not exist corresponding response maps&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
        allow(ResponseMap).to receive(:where).with(reviewee_id: 1, reviewed_object_id: 1).and_return([])&lt;br /&gt;
        expect(assignment_team1.received_any_peer_review?).to be false&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Set the directory num for this team===&lt;br /&gt;
The assignment_team.rb offers a method that could Set the directory num for this team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def set_student_directory_num&lt;br /&gt;
    return if self.directory_num and self.directory_num &amp;gt;= 0&lt;br /&gt;
    max_num = AssignmentTeam.where(parent_id: self.parent_id).order('directory_num desc').first.directory_num&lt;br /&gt;
    dir_num = max_num ? max_num + 1 : 0&lt;br /&gt;
    self.update_attributes(directory_num: dir_num)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#set_student_directory_num&amp;quot; do&lt;br /&gt;
    context &amp;quot;when there is no directory number for the assignment team&amp;quot; do&lt;br /&gt;
      it &amp;quot;sets a directory number for the assignment team&amp;quot; do&lt;br /&gt;
        # allow(assignment_team1).to receive(:try).with(:directory).and_return(-1)&lt;br /&gt;
        allow(AssignmentTeam).to receive_message_chain(:where, :order, :first, :directory_num).and_return(4)&lt;br /&gt;
        expect(assignment_team2.set_student_directory_num).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test can successfully test whether the team has submitted files/hyperlinks or not, because it creates a mock function, for the submitted_files function to receive a parameter - so that the team has hypothetically passed in a submitted file. The returning value being true shows that the has_submissions? test succeeded when the team receives a submitted file.&lt;br /&gt;
&lt;br /&gt;
Similarly, we created a mock function for the team to receive a hyperlink using submitted_hyperlink. This second test case returning true shows the hyperlink being submitted is also detected by the function.&lt;br /&gt;
&lt;br /&gt;
When there's no mock happening inside the function, no file or hyperlink will be passed into the team. So has_submissions? returns false is what's being expected.&lt;br /&gt;
&lt;br /&gt;
=='''Result'''==&lt;br /&gt;
Our test cases has coverage: 100%&lt;br /&gt;
&lt;br /&gt;
There are in total 127 relevant lines, and all of them get passed.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
The testing framework in the assignment_team_spec.rb used unit tests to test the functionality of each action in the class. The mock instances are created at the beginning of the file, so that during each test they don't need to be constructed again. In order to test each unit case without depending on other functionalities, the mocked actions, as well as the desired returns are built inside different test cases, depending on the need of the case.&lt;br /&gt;
&lt;br /&gt;
In building the test framework, the key is to understand the input, output and the desired action of each function that we want to test. The Rspec test format also has a steep learning curve, but the test shows stable and robust result on the assignment_team.rb.&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118528</id>
		<title>CSC/ECE 517 Fall 2018/OSS E1848 Write unit tests for assignment team.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118528"/>
		<updated>2018-11-03T03:17:42Z</updated>

		<summary type="html">&lt;p&gt;Jli94: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For this project, the goal is to write up unit tests for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
Assignment_team.rb in Expertiza provides a method for student to assign a team and finish one assignment. Features come at the cost of complexity; this project is focused on creating the test methods to ensure that user interaction with the assignment interface remains stable and reliable.&lt;br /&gt;
&lt;br /&gt;
=='''Bugs in assignment_team.rb'''==&lt;br /&gt;
We found some bugs in assignment_team.rb:&lt;br /&gt;
===In assign_reviewer(reviewer)===&lt;br /&gt;
assignment = Assignment.find(self.parent_id) =&amp;gt; assignment = Assignment.find_by(id: parent_id)&lt;br /&gt;
===In self.import(row, assignment_id, options)===&lt;br /&gt;
108: raise ImportError, &amp;quot;The assignment with the id \&amp;quot;&amp;quot; + id.to_s + &amp;quot;\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
=&amp;gt;raise ImportError, &amp;quot;The assignment with the id \&amp;quot;&amp;quot; + assignment_id.to_s + &amp;quot;\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
The id dose't exist in the AssignmentTeam &lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
There are some examples for how this project create test methods for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
===Create a team===&lt;br /&gt;
In assignment_team.rb,there is a method return the team given the participant.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.team(participant)&lt;br /&gt;
      return nil if participant.nil?&lt;br /&gt;
      team = nil&lt;br /&gt;
      teams_users = TeamsUser.where(user_id: participant.user_id)&lt;br /&gt;
      return nil unless teams_users&lt;br /&gt;
      teams_users.each do |teams_user|&lt;br /&gt;
        team = Team.find(teams_user.team_id)&lt;br /&gt;
        return team if team.parent_id == participant.parent_id&lt;br /&gt;
      end&lt;br /&gt;
      nil&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above method, the test case can be created, and there are three different possible results could be generated.&lt;br /&gt;
*when the participant is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there are not team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return(nil)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when the participant is not nil and there exist team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns the team given the participant&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return([team_user])&lt;br /&gt;
      allow(Team).to receive(:find).with(1).and_return(team)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove team by id===&lt;br /&gt;
The assignment_team.rb also provide a method which could remove team by id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.remove_team_by_id(id)&lt;br /&gt;
      old_team = AssignmentTeam.find(id)&lt;br /&gt;
      old_team.destroy unless old_team.nil?&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;deletes a team given the team id&amp;quot; do&lt;br /&gt;
      old_team = assignment_team1&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with(1).and_return(old_team)&lt;br /&gt;
      allow(old_team).to receive(:destroy).and_return(old_team)&lt;br /&gt;
      expect(AssignmentTeam.remove_team_by_id(1)).to eq(old_team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return the topic chosen by the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the topic chosen by the team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def topic&lt;br /&gt;
    SignedUpTeam.find_by(team_id: self.id, is_waitlisted: 0).try(:topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#topic&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the topic id chosen by this team&amp;quot; do&lt;br /&gt;
      allow(SignedUpTeam).to receive(:find_by).with(team_id:1, is_waitlisted: 0).and_return(signed_up_team1)&lt;br /&gt;
      expect(assignment_team1.topic).to eq(1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test examines the original codes ability to generate the topic that is chosen by the team because it first goes to the mocked instances to look for a team. In this case, to match the mock instance that has created, we look for the team that has team_id as 1, and not being waitlisted. The topic id is set to be 1 in the mock. This function returns 1, because it does return the topic id, for the team that has signed up for a topic.&lt;br /&gt;
&lt;br /&gt;
===Return whether the team has submission===&lt;br /&gt;
The assignment_team.rb offers a method that could return either true or false, in terms of whether the team has submitted work or not&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
    self.submitted_files.any? or self.submitted_hyperlinks.present?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created, and there are three possible results:&lt;br /&gt;
*when current assignment team submitted files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_files).and_return([double(:File)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit files but submitted hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_hyperlinks).and_return([double(:Hyperlink)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit either files or hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return participants of a team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the participants of a team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def participants&lt;br /&gt;
    users = self.users&lt;br /&gt;
    participants = []&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: self.parent_id)&lt;br /&gt;
      participants &amp;lt;&amp;lt; participant unless participant.nil?&lt;br /&gt;
    end&lt;br /&gt;
    participants&lt;br /&gt;
  end&lt;br /&gt;
  alias get_participants participants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#participants&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns participants of the current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 2).and_return(participant2)&lt;br /&gt;
      expect(assignment_team.participants).to eq([participant2])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return the first member of the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the first member of the team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_first_member(team_id)&lt;br /&gt;
    find_by(id: team_id).try(:participants).try(:first)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;.get_first_member&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the first participant of current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentTeam).to receive_message_chain(:find_by, :try, :try).with(id: 1).with(:participants).with(:first).and_return(participant1)&lt;br /&gt;
      expect(AssignmentTeam.get_first_member(1)).to eq(participant1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Import csv file to form teams directly===&lt;br /&gt;
The assignment_team.rb offers a method that could import csv file to form teams directly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.import(row, assignment_id, options)&lt;br /&gt;
    unless Assignment.find_by(id: assignment_id)&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with the id \&amp;quot;&amp;quot; + assignment_id.to_s + &amp;quot;\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    @assignment_team = prototype&lt;br /&gt;
    Team.import(row, assignment_id, options, @assignment_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
*when there is no assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there is no assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;raises an ImportError&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 1).and_return(nil)&lt;br /&gt;
        expect { AssignmentTeam.import([], 1, has_column_names: 'false') }&lt;br /&gt;
            .to raise_error(ImportError, &amp;quot;The assignment with the id \&amp;quot;1\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there exists an assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there exists an assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;imports a csv file to form assignment teams&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 2).and_return(double(&amp;quot;Assignment&amp;quot;, id: 2))&lt;br /&gt;
        allow(AssignmentTeam).to receive(:prototype).and_return(assignment_team)&lt;br /&gt;
        allow(Team).to receive(:import).with([], 2, {}, assignment_team).and_return(true)&lt;br /&gt;
        expect(AssignmentTeam.import([], 2, {})).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Copy the current Assignment team to the CourseTeam===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy(course_id)&lt;br /&gt;
    new_team = CourseTeam.create_team_and_node(course_id)&lt;br /&gt;
    new_team.name = name&lt;br /&gt;
    new_team.save&lt;br /&gt;
    copy_members(new_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#copy&amp;quot; do&lt;br /&gt;
    it &amp;quot;copies the current assignment team and team members to a new course team&amp;quot; do&lt;br /&gt;
      allow(CourseTeam).to receive(:create_team_and_node).with(1).and_return(courseTeam)&lt;br /&gt;
      allow(Team).to receive(:copy_members).with(courseTeam).and_return([])&lt;br /&gt;
      expect(assignment_team.copy(1)).to eq([])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===return a hash of scores that the team has received for the questions===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def scores(questions)&lt;br /&gt;
    scores = {}&lt;br /&gt;
    scores[:team] = self # This doesn't appear to be used anywhere&lt;br /&gt;
    assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
      scores[questionnaire.symbol] = {}&lt;br /&gt;
      scores[questionnaire.symbol][:assessments] = ReviewResponseMap.where(reviewee_id: self.id)&lt;br /&gt;
      scores[questionnaire.symbol][:scores] = Answer.compute_scores(scores[questionnaire.symbol][:assessments], questions[questionnaire.symbol])&lt;br /&gt;
    end&lt;br /&gt;
    scores[:total_score] = assignment.compute_total_score(scores)&lt;br /&gt;
    scores&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#scores&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns a hash of scores that current assignment team has received for the questions&amp;quot; do&lt;br /&gt;
      allow(assignment_team).to receive(:assignment).and_return(assignment)&lt;br /&gt;
      allow(ReviewResponseMap).to receive(:where).with(reviewee_id: 2).and_return(review_response_map)&lt;br /&gt;
      allow(Answer).to receive(:compute_scores).with(review_response_map, questions[QuizQuestionnaire]).and_return(10)&lt;br /&gt;
      allow(assignment).to receive(:compute_total_score).and_return(10)&lt;br /&gt;
      # expect(assignment_team.scores(questions)[:QuizQuestionnaire]).equal?({assessments: review_response_map, scores: 10}).to be true&lt;br /&gt;
      expect(assignment_team.scores(questions)[:team]).to eq(assignment_team)&lt;br /&gt;
      expect(assignment_team.scores(questions)[:total_score]).to eq(10)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return whether assignment team exist corresponding response maps===&lt;br /&gt;
The assignment_team.rb offers a method that could judge whether there exist corresponding response maps.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def received_any_peer_review?&lt;br /&gt;
    ResponseMap.where(reviewee_id: self.id, reviewed_object_id: self.parent_id).any?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
*when there exist corresponding response map&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
        allow(ResponseMap).to receive(:where).with(reviewee_id: 1, reviewed_object_id: 1).and_return([double(:ResponseMap)])&lt;br /&gt;
        expect(assignment_team1.received_any_peer_review?).to be true&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there does not exist corresponding response maps&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
        allow(ResponseMap).to receive(:where).with(reviewee_id: 1, reviewed_object_id: 1).and_return([])&lt;br /&gt;
        expect(assignment_team1.received_any_peer_review?).to be false&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Set the directory num for this team===&lt;br /&gt;
The assignment_team.rb offers a method that could Set the directory num for this team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def set_student_directory_num&lt;br /&gt;
    return if self.directory_num and self.directory_num &amp;gt;= 0&lt;br /&gt;
    max_num = AssignmentTeam.where(parent_id: self.parent_id).order('directory_num desc').first.directory_num&lt;br /&gt;
    dir_num = max_num ? max_num + 1 : 0&lt;br /&gt;
    self.update_attributes(directory_num: dir_num)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#set_student_directory_num&amp;quot; do&lt;br /&gt;
    context &amp;quot;when there is no directory number for the assignment team&amp;quot; do&lt;br /&gt;
      it &amp;quot;sets a directory number for the assignment team&amp;quot; do&lt;br /&gt;
        # allow(assignment_team1).to receive(:try).with(:directory).and_return(-1)&lt;br /&gt;
        allow(AssignmentTeam).to receive_message_chain(:where, :order, :first, :directory_num).and_return(4)&lt;br /&gt;
        expect(assignment_team2.set_student_directory_num).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test can successfully test whether the team has submitted files/hyperlinks or not, because it creates a mock function, for the submitted_files function to receive a parameter - so that the team has hypothetically passed in a submitted file. The returning value being true shows that the has_submissions? test succeeded when the team receives a submitted file.&lt;br /&gt;
&lt;br /&gt;
Similarly, we created a mock function for the team to receive a hyperlink using submitted_hyperlink. This second test case returning true shows the hyperlink being submitted is also detected by the function.&lt;br /&gt;
&lt;br /&gt;
When there's no mock happening inside the function, no file or hyperlink will be passed into the team. So has_submissions? returns false is what's being expected.&lt;br /&gt;
&lt;br /&gt;
=='''Result'''==&lt;br /&gt;
Our test cases has coverage: 100%&lt;br /&gt;
&lt;br /&gt;
There are in total 127 relevant lines, and all of them get passed.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
The testing framework in the assignment_team_spec.rb used unit tests to test the functionality of each action in the class. The mock instances are created at the beginning of the file, so that during each test they don't need to be constructed again. In order to test each unit case without depending on other functionalities, the mocked actions, as well as the desired returns are built inside different test cases, depending on the need of the case.&lt;br /&gt;
&lt;br /&gt;
In building the test framework, the key is to understand the input, output and the desired action of each function that we want to test. The Rspec test format also has a steep learning curve, but the test shows stable and robust result on the assignment_team.rb.&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118511</id>
		<title>CSC/ECE 517 Fall 2018/OSS E1848 Write unit tests for assignment team.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118511"/>
		<updated>2018-11-03T03:02:59Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For this progect, the goal is to wirte up unit tests for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
Assignment_team.rb in Expertiza provides a method for student to assign a team and finish one assignment. Features come at the cost of complexity; this project is focused on creating the test methods to ensure that user interaction with the assignment interface remains stable and reliable.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
There are some examples for how this project create test methods for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
===Create a team===&lt;br /&gt;
In assignment_team.rb,there is a method return the team given the participant.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.team(participant)&lt;br /&gt;
      return nil if participant.nil?&lt;br /&gt;
      team = nil&lt;br /&gt;
      teams_users = TeamsUser.where(user_id: participant.user_id)&lt;br /&gt;
      return nil unless teams_users&lt;br /&gt;
      teams_users.each do |teams_user|&lt;br /&gt;
        team = Team.find(teams_user.team_id)&lt;br /&gt;
        return team if team.parent_id == participant.parent_id&lt;br /&gt;
      end&lt;br /&gt;
      nil&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above method, the test case can be created, and there are three different possible results could be generated.&lt;br /&gt;
*when the participant is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there are not team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return(nil)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when the participant is not nil and there exist team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns the team given the participant&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return([team_user])&lt;br /&gt;
      allow(Team).to receive(:find).with(1).and_return(team)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove team by id===&lt;br /&gt;
The assignment_team.rb also provide a method which could remove team by id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.remove_team_by_id(id)&lt;br /&gt;
      old_team = AssignmentTeam.find(id)&lt;br /&gt;
      old_team.destroy unless old_team.nil?&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;deletes a team given the team id&amp;quot; do&lt;br /&gt;
      old_team = assignment_team1&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with(1).and_return(old_team)&lt;br /&gt;
      allow(old_team).to receive(:destroy).and_return(old_team)&lt;br /&gt;
      expect(AssignmentTeam.remove_team_by_id(1)).to eq(old_team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return the topic chosen by the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the topic chosen by the team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def topic&lt;br /&gt;
    SignedUpTeam.find_by(team_id: self.id, is_waitlisted: 0).try(:topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#topic&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the topic id chosen by this team&amp;quot; do&lt;br /&gt;
      allow(SignedUpTeam).to receive(:find_by).with(team_id:1, is_waitlisted: 0).and_return(signed_up_team1)&lt;br /&gt;
      expect(assignment_team1.topic).to eq(1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test examines the original codes ability to generate the topic that is chosen by the team because it first goes to the mocked instances to look for a team. In this case, to match the mock instance that has created, we look for the team that has team_id as 1, and not being waitlisted. The topic id is set to be 1 in the mock. This function returns 1, because it does return the topic id, for the team that has signed up for a topic.&lt;br /&gt;
&lt;br /&gt;
===Return whether the team has submission===&lt;br /&gt;
The assignment_team.rb offers a method that could return either true or false, in terms of whether the team has submitted work or not&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
    self.submitted_files.any? or self.submitted_hyperlinks.present?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created, and there are three possible results:&lt;br /&gt;
*when current assignment team submitted files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_files).and_return([double(:File)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit files but submitted hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_hyperlinks).and_return([double(:Hyperlink)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit either files or hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return participants of a team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the participants of a team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def participants&lt;br /&gt;
    users = self.users&lt;br /&gt;
    participants = []&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: self.parent_id)&lt;br /&gt;
      participants &amp;lt;&amp;lt; participant unless participant.nil?&lt;br /&gt;
    end&lt;br /&gt;
    participants&lt;br /&gt;
  end&lt;br /&gt;
  alias get_participants participants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#participants&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns participants of the current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 2).and_return(participant2)&lt;br /&gt;
      expect(assignment_team.participants).to eq([participant2])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return the first member of the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the first member of the team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_first_member(team_id)&lt;br /&gt;
    find_by(id: team_id).try(:participants).try(:first)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;.get_first_member&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the first participant of current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentTeam).to receive_message_chain(:find_by, :try, :try).with(id: 1).with(:participants).with(:first).and_return(participant1)&lt;br /&gt;
      expect(AssignmentTeam.get_first_member(1)).to eq(participant1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Import csv file to form teams directly===&lt;br /&gt;
The assignment_team.rb offers a method that could import csv file to form teams directly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.import(row, assignment_id, options)&lt;br /&gt;
    unless Assignment.find_by(id: assignment_id)&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with the id \&amp;quot;&amp;quot; + assignment_id.to_s + &amp;quot;\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    @assignment_team = prototype&lt;br /&gt;
    Team.import(row, assignment_id, options, @assignment_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
*when there is no assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there is no assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;raises an ImportError&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 1).and_return(nil)&lt;br /&gt;
        expect { AssignmentTeam.import([], 1, has_column_names: 'false') }&lt;br /&gt;
            .to raise_error(ImportError, &amp;quot;The assignment with the id \&amp;quot;1\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there exists an assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there exists an assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;imports a csv file to form assignment teams&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 2).and_return(double(&amp;quot;Assignment&amp;quot;, id: 2))&lt;br /&gt;
        allow(AssignmentTeam).to receive(:prototype).and_return(assignment_team)&lt;br /&gt;
        allow(Team).to receive(:import).with([], 2, {}, assignment_team).and_return(true)&lt;br /&gt;
        expect(AssignmentTeam.import([], 2, {})).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Copy the current Assignment team to the CourseTeam===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy(course_id)&lt;br /&gt;
    new_team = CourseTeam.create_team_and_node(course_id)&lt;br /&gt;
    new_team.name = name&lt;br /&gt;
    new_team.save&lt;br /&gt;
    copy_members(new_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#copy&amp;quot; do&lt;br /&gt;
    it &amp;quot;copies the current assignment team and team members to a new course team&amp;quot; do&lt;br /&gt;
      allow(CourseTeam).to receive(:create_team_and_node).with(1).and_return(courseTeam)&lt;br /&gt;
      allow(Team).to receive(:copy_members).with(courseTeam).and_return([])&lt;br /&gt;
      expect(assignment_team.copy(1)).to eq([])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===return a hash of scores that the team has received for the questions===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def scores(questions)&lt;br /&gt;
    scores = {}&lt;br /&gt;
    scores[:team] = self # This doesn't appear to be used anywhere&lt;br /&gt;
    assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
      scores[questionnaire.symbol] = {}&lt;br /&gt;
      scores[questionnaire.symbol][:assessments] = ReviewResponseMap.where(reviewee_id: self.id)&lt;br /&gt;
      scores[questionnaire.symbol][:scores] = Answer.compute_scores(scores[questionnaire.symbol][:assessments], questions[questionnaire.symbol])&lt;br /&gt;
    end&lt;br /&gt;
    scores[:total_score] = assignment.compute_total_score(scores)&lt;br /&gt;
    scores&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#scores&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns a hash of scores that current assignment team has received for the questions&amp;quot; do&lt;br /&gt;
      allow(assignment_team).to receive(:assignment).and_return(assignment)&lt;br /&gt;
      allow(ReviewResponseMap).to receive(:where).with(reviewee_id: 2).and_return(review_response_map)&lt;br /&gt;
      allow(Answer).to receive(:compute_scores).with(review_response_map, questions[QuizQuestionnaire]).and_return(10)&lt;br /&gt;
      allow(assignment).to receive(:compute_total_score).and_return(10)&lt;br /&gt;
      # expect(assignment_team.scores(questions)[:QuizQuestionnaire]).equal?({assessments: review_response_map, scores: 10}).to be true&lt;br /&gt;
      expect(assignment_team.scores(questions)[:team]).to eq(assignment_team)&lt;br /&gt;
      expect(assignment_team.scores(questions)[:total_score]).to eq(10)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return whether assignment team exist corresponding response maps===&lt;br /&gt;
The assignment_team.rb offers a method that could judge whether there exist corresponding response maps.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def received_any_peer_review?&lt;br /&gt;
    ResponseMap.where(reviewee_id: self.id, reviewed_object_id: self.parent_id).any?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
*when there exist corresponding response map&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
        allow(ResponseMap).to receive(:where).with(reviewee_id: 1, reviewed_object_id: 1).and_return([double(:ResponseMap)])&lt;br /&gt;
        expect(assignment_team1.received_any_peer_review?).to be true&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there does not exist corresponding response maps&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
        allow(ResponseMap).to receive(:where).with(reviewee_id: 1, reviewed_object_id: 1).and_return([])&lt;br /&gt;
        expect(assignment_team1.received_any_peer_review?).to be false&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Set the directory num for this team===&lt;br /&gt;
The assignment_team.rb offers a method that could Set the directory num for this team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def set_student_directory_num&lt;br /&gt;
    return if self.directory_num and self.directory_num &amp;gt;= 0&lt;br /&gt;
    max_num = AssignmentTeam.where(parent_id: self.parent_id).order('directory_num desc').first.directory_num&lt;br /&gt;
    dir_num = max_num ? max_num + 1 : 0&lt;br /&gt;
    self.update_attributes(directory_num: dir_num)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#set_student_directory_num&amp;quot; do&lt;br /&gt;
    context &amp;quot;when there is no directory number for the assignment team&amp;quot; do&lt;br /&gt;
      it &amp;quot;sets a directory number for the assignment team&amp;quot; do&lt;br /&gt;
        # allow(assignment_team1).to receive(:try).with(:directory).and_return(-1)&lt;br /&gt;
        allow(AssignmentTeam).to receive_message_chain(:where, :order, :first, :directory_num).and_return(4)&lt;br /&gt;
        expect(assignment_team2.set_student_directory_num).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test can successfully test whether the team has submitted files/hyperlinks or not, because it creates a mock function, for the submitted_files function to receive a parameter - so that the team has hypothetically passed in a submitted file. The returning value being true shows that the has_submissions? test succeeded when the team receives a submitted file.&lt;br /&gt;
&lt;br /&gt;
Similarly, we created a mock function for the team to receive a hyperlink using submitted_hyperlink. This second test case returning true shows the hyperlink being submitted is also detected by the function.&lt;br /&gt;
&lt;br /&gt;
When there's no mock happening inside the function, no file or hyperlink will be passed into the team. So has_submissions? returns false is what's being expected.&lt;br /&gt;
&lt;br /&gt;
=='''Result'''==&lt;br /&gt;
Our test cases has coverage: 100%&lt;br /&gt;
&lt;br /&gt;
There are in total 127 relevant lines, and all of them get passed.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
The testing framework in the assignment_team_spec.rb used unit tests to test the functionality of each action in the class. The mock instances are created at the beginning of the file, so that during each test they don't need to be constructed again. In order to test each unit case without depending on other functionalities, the mocked actions, as well as the desired returns are built inside different test cases, depending on the need of the case.&lt;br /&gt;
&lt;br /&gt;
In building the test framework, the key is to understand the input, output and the desired action of each functionality that we want to test. The Rspec test format also has a steep learning curve, but the test shows stable and robust result on the assignment_team.rb.&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118507</id>
		<title>CSC/ECE 517 Fall 2018/OSS E1848 Write unit tests for assignment team.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118507"/>
		<updated>2018-11-03T03:02:02Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For this progect, the goal is to wirte up unit tests for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
Assignment_team.rb in Expertiza provides a method for student to assign a team and finish one assignment. Features come at the cost of complexity; this project is focused on creating the test methods to ensure that user interaction with the assignment interface remains stable and reliable.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
There are some examples for how this project create test methods for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
===Create team===&lt;br /&gt;
In assignment_team.rb,there is a method return the team given the participant.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.team(participant)&lt;br /&gt;
      return nil if participant.nil?&lt;br /&gt;
      team = nil&lt;br /&gt;
      teams_users = TeamsUser.where(user_id: participant.user_id)&lt;br /&gt;
      return nil unless teams_users&lt;br /&gt;
      teams_users.each do |teams_user|&lt;br /&gt;
        team = Team.find(teams_user.team_id)&lt;br /&gt;
        return team if team.parent_id == participant.parent_id&lt;br /&gt;
      end&lt;br /&gt;
      nil&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above method, the test case can be created, and there are three different possible results could be generated.&lt;br /&gt;
*when the participant is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there are not team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return(nil)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when the participant is not nil and there exist team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns the team given the participant&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return([team_user])&lt;br /&gt;
      allow(Team).to receive(:find).with(1).and_return(team)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove team by id===&lt;br /&gt;
The assignment_team.rb also provide a method which could remove team by id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.remove_team_by_id(id)&lt;br /&gt;
      old_team = AssignmentTeam.find(id)&lt;br /&gt;
      old_team.destroy unless old_team.nil?&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;deletes a team given the team id&amp;quot; do&lt;br /&gt;
      old_team = assignment_team1&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with(1).and_return(old_team)&lt;br /&gt;
      allow(old_team).to receive(:destroy).and_return(old_team)&lt;br /&gt;
      expect(AssignmentTeam.remove_team_by_id(1)).to eq(old_team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return the topic chosen by the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the topic chosen by the team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def topic&lt;br /&gt;
    SignedUpTeam.find_by(team_id: self.id, is_waitlisted: 0).try(:topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#topic&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the topic id chosen by this team&amp;quot; do&lt;br /&gt;
      allow(SignedUpTeam).to receive(:find_by).with(team_id:1, is_waitlisted: 0).and_return(signed_up_team1)&lt;br /&gt;
      expect(assignment_team1.topic).to eq(1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test examines the original codes ability to generate the topic that is chosen by the team because it first goes to the mocked instances to look for a team. In this case, to match the mock instance that has created, we look for the team that has team_id as 1, and not being waitlisted. The topic id is set to be 1 in the mock. This function returns 1, because it does return the topic id, for the team that has signed up for a topic.&lt;br /&gt;
&lt;br /&gt;
===Return whether the team has submission===&lt;br /&gt;
The assignment_team.rb offers a method that could return either true or false, in terms of whether the team has submitted work or not&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
    self.submitted_files.any? or self.submitted_hyperlinks.present?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created, and there are three possible results:&lt;br /&gt;
*when current assignment team submitted files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_files).and_return([double(:File)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit files but submitted hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_hyperlinks).and_return([double(:Hyperlink)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit either files or hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return participants of a team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the participants of a team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def participants&lt;br /&gt;
    users = self.users&lt;br /&gt;
    participants = []&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: self.parent_id)&lt;br /&gt;
      participants &amp;lt;&amp;lt; participant unless participant.nil?&lt;br /&gt;
    end&lt;br /&gt;
    participants&lt;br /&gt;
  end&lt;br /&gt;
  alias get_participants participants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#participants&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns participants of the current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 2).and_return(participant2)&lt;br /&gt;
      expect(assignment_team.participants).to eq([participant2])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return the first member of the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the first member of the team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_first_member(team_id)&lt;br /&gt;
    find_by(id: team_id).try(:participants).try(:first)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;.get_first_member&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the first participant of current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentTeam).to receive_message_chain(:find_by, :try, :try).with(id: 1).with(:participants).with(:first).and_return(participant1)&lt;br /&gt;
      expect(AssignmentTeam.get_first_member(1)).to eq(participant1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Import csv file to form teams directly===&lt;br /&gt;
The assignment_team.rb offers a method that could import csv file to form teams directly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.import(row, assignment_id, options)&lt;br /&gt;
    unless Assignment.find_by(id: assignment_id)&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with the id \&amp;quot;&amp;quot; + assignment_id.to_s + &amp;quot;\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    @assignment_team = prototype&lt;br /&gt;
    Team.import(row, assignment_id, options, @assignment_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there is no assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there is no assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;raises an ImportError&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 1).and_return(nil)&lt;br /&gt;
        expect { AssignmentTeam.import([], 1, has_column_names: 'false') }&lt;br /&gt;
            .to raise_error(ImportError, &amp;quot;The assignment with the id \&amp;quot;1\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there exists an assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there exists an assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;imports a csv file to form assignment teams&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 2).and_return(double(&amp;quot;Assignment&amp;quot;, id: 2))&lt;br /&gt;
        allow(AssignmentTeam).to receive(:prototype).and_return(assignment_team)&lt;br /&gt;
        allow(Team).to receive(:import).with([], 2, {}, assignment_team).and_return(true)&lt;br /&gt;
        expect(AssignmentTeam.import([], 2, {})).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Copy the current Assignment team to the CourseTeam===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy(course_id)&lt;br /&gt;
    new_team = CourseTeam.create_team_and_node(course_id)&lt;br /&gt;
    new_team.name = name&lt;br /&gt;
    new_team.save&lt;br /&gt;
    copy_members(new_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#copy&amp;quot; do&lt;br /&gt;
    it &amp;quot;copies the current assignment team and team members to a new course team&amp;quot; do&lt;br /&gt;
      allow(CourseTeam).to receive(:create_team_and_node).with(1).and_return(courseTeam)&lt;br /&gt;
      allow(Team).to receive(:copy_members).with(courseTeam).and_return([])&lt;br /&gt;
      expect(assignment_team.copy(1)).to eq([])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===return a hash of scores that the team has received for the questions===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def scores(questions)&lt;br /&gt;
    scores = {}&lt;br /&gt;
    scores[:team] = self # This doesn't appear to be used anywhere&lt;br /&gt;
    assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
      scores[questionnaire.symbol] = {}&lt;br /&gt;
      scores[questionnaire.symbol][:assessments] = ReviewResponseMap.where(reviewee_id: self.id)&lt;br /&gt;
      scores[questionnaire.symbol][:scores] = Answer.compute_scores(scores[questionnaire.symbol][:assessments], questions[questionnaire.symbol])&lt;br /&gt;
    end&lt;br /&gt;
    scores[:total_score] = assignment.compute_total_score(scores)&lt;br /&gt;
    scores&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#scores&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns a hash of scores that current assignment team has received for the questions&amp;quot; do&lt;br /&gt;
      allow(assignment_team).to receive(:assignment).and_return(assignment)&lt;br /&gt;
      allow(ReviewResponseMap).to receive(:where).with(reviewee_id: 2).and_return(review_response_map)&lt;br /&gt;
      allow(Answer).to receive(:compute_scores).with(review_response_map, questions[QuizQuestionnaire]).and_return(10)&lt;br /&gt;
      allow(assignment).to receive(:compute_total_score).and_return(10)&lt;br /&gt;
      # expect(assignment_team.scores(questions)[:QuizQuestionnaire]).equal?({assessments: review_response_map, scores: 10}).to be true&lt;br /&gt;
      expect(assignment_team.scores(questions)[:team]).to eq(assignment_team)&lt;br /&gt;
      expect(assignment_team.scores(questions)[:total_score]).to eq(10)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return whether assignment team exist corresponding response maps===&lt;br /&gt;
The assignment_team.rb offers a method that could judge whether there exist corresponding response maps.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def received_any_peer_review?&lt;br /&gt;
    ResponseMap.where(reviewee_id: self.id, reviewed_object_id: self.parent_id).any?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there exist corresponding response map&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
        allow(ResponseMap).to receive(:where).with(reviewee_id: 1, reviewed_object_id: 1).and_return([double(:ResponseMap)])&lt;br /&gt;
        expect(assignment_team1.received_any_peer_review?).to be true&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there does not exist corresponding response maps&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
        allow(ResponseMap).to receive(:where).with(reviewee_id: 1, reviewed_object_id: 1).and_return([])&lt;br /&gt;
        expect(assignment_team1.received_any_peer_review?).to be false&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Set the directory num for this team===&lt;br /&gt;
The assignment_team.rb offers a method that could Set the directory num for this team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def set_student_directory_num&lt;br /&gt;
    return if self.directory_num and self.directory_num &amp;gt;= 0&lt;br /&gt;
    max_num = AssignmentTeam.where(parent_id: self.parent_id).order('directory_num desc').first.directory_num&lt;br /&gt;
    dir_num = max_num ? max_num + 1 : 0&lt;br /&gt;
    self.update_attributes(directory_num: dir_num)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#set_student_directory_num&amp;quot; do&lt;br /&gt;
    context &amp;quot;when there is no directory number for the assignment team&amp;quot; do&lt;br /&gt;
      it &amp;quot;sets a directory number for the assignment team&amp;quot; do&lt;br /&gt;
        # allow(assignment_team1).to receive(:try).with(:directory).and_return(-1)&lt;br /&gt;
        allow(AssignmentTeam).to receive_message_chain(:where, :order, :first, :directory_num).and_return(4)&lt;br /&gt;
        expect(assignment_team2.set_student_directory_num).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test can successfully test whether the team has submitted files/hyperlinks or not, because it creates a mock function, for the submitted_files function to receive a parameter - so that the team has hypothetically passed in a submitted file. The returning value being true shows that the has_submissions? test succeeded when the team receives a submitted file.&lt;br /&gt;
&lt;br /&gt;
Similarly, we created a mock function for the team to receive a hyperlink using submitted_hyperlink. This second test case returning true shows the hyperlink being submitted is also detected by the function.&lt;br /&gt;
&lt;br /&gt;
When there's no mock happening inside the function, no file or hyperlink will be passed into the team. So has_submissions? returns false is what's being expected.&lt;br /&gt;
&lt;br /&gt;
=='''Result'''==&lt;br /&gt;
Our test cases has coverage: 100%&lt;br /&gt;
&lt;br /&gt;
There are in total 127 relevant lines, and all of them get passed.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
The testing framework in the assignment_team_spec.rb used unit tests to test the functionality of each action in the class. The mock instances are created at the beginning of the file, so that during each test they don't need to be constructed again. In order to test each unit case without depending on other functionalities, the mocked actions, as well as the desired returns are built inside different test cases, depending on the need of the case.&lt;br /&gt;
&lt;br /&gt;
In building the test framework, the key is to understand the input, output and the desired action of each functionality that we want to test. The Rspec test format also has a steep learning curve, but the test shows stable and robust result on the assignment_team.rb.&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118495</id>
		<title>CSC/ECE 517 Fall 2018/OSS E1848 Write unit tests for assignment team.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118495"/>
		<updated>2018-11-03T02:54:25Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For this progect, the goal is to wirte up unit tests for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
Assignment_team.rb in Expertiza provides a method for student to assign a team and finish one assignment. Features come at the cost of complexity; this project is focused on creating the test methods to ensure that user interaction with the assignment interface remains stable and reliable.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
There are some examples for how this project create test methods for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
===Create team===&lt;br /&gt;
In assignment_team.rb,there is a method return the team given the participant.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.team(participant)&lt;br /&gt;
      return nil if participant.nil?&lt;br /&gt;
      team = nil&lt;br /&gt;
      teams_users = TeamsUser.where(user_id: participant.user_id)&lt;br /&gt;
      return nil unless teams_users&lt;br /&gt;
      teams_users.each do |teams_user|&lt;br /&gt;
        team = Team.find(teams_user.team_id)&lt;br /&gt;
        return team if team.parent_id == participant.parent_id&lt;br /&gt;
      end&lt;br /&gt;
      nil&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above method, the test case can be created, and there are three different possible results could be generated.&lt;br /&gt;
*when the participant is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there are not team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return(nil)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when the participant is not nil and there exist team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns the team given the participant&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return([team_user])&lt;br /&gt;
      allow(Team).to receive(:find).with(1).and_return(team)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove team by id===&lt;br /&gt;
The assignment_team.rb also provide a method which could remove team by id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.remove_team_by_id(id)&lt;br /&gt;
      old_team = AssignmentTeam.find(id)&lt;br /&gt;
      old_team.destroy unless old_team.nil?&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;deletes a team given the team id&amp;quot; do&lt;br /&gt;
      old_team = assignment_team1&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with(1).and_return(old_team)&lt;br /&gt;
      allow(old_team).to receive(:destroy).and_return(old_team)&lt;br /&gt;
      expect(AssignmentTeam.remove_team_by_id(1)).to eq(old_team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return the topic chosen by the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the topic chosen by the team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def topic&lt;br /&gt;
    SignedUpTeam.find_by(team_id: self.id, is_waitlisted: 0).try(:topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#topic&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the topic id chosen by this team&amp;quot; do&lt;br /&gt;
      allow(SignedUpTeam).to receive(:find_by).with(team_id:1, is_waitlisted: 0).and_return(signed_up_team1)&lt;br /&gt;
      expect(assignment_team1.topic).to eq(1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test examines the original codes ability to generate the topic that is chosen by the team because it first goes to the mocked instances to look for a team. In this case, to match the mock instance that has created, we look for the team that has team_id as 1, and not being waitlisted. The topic id is set to be 1 in the mock. This function returns 1, because it does return the topic id, for the team that has signed up for a topic.&lt;br /&gt;
&lt;br /&gt;
===Return whether the team has submission===&lt;br /&gt;
The assignment_team.rb offers a method that could return either true or false, in terms of whether the team has submitted work or not&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
    self.submitted_files.any? or self.submitted_hyperlinks.present?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created, and there are three possible results:&lt;br /&gt;
*when current assignment team submitted files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_files).and_return([double(:File)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit files but submitted hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_hyperlinks).and_return([double(:Hyperlink)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit either files or hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return participants of a team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the participants of a team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def participants&lt;br /&gt;
    users = self.users&lt;br /&gt;
    participants = []&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: self.parent_id)&lt;br /&gt;
      participants &amp;lt;&amp;lt; participant unless participant.nil?&lt;br /&gt;
    end&lt;br /&gt;
    participants&lt;br /&gt;
  end&lt;br /&gt;
  alias get_participants participants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#participants&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns participants of the current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 2).and_return(participant2)&lt;br /&gt;
      expect(assignment_team.participants).to eq([participant2])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return the first member of the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the first member of the team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_first_member(team_id)&lt;br /&gt;
    find_by(id: team_id).try(:participants).try(:first)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;.get_first_member&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the first participant of current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentTeam).to receive_message_chain(:find_by, :try, :try).with(id: 1).with(:participants).with(:first).and_return(participant1)&lt;br /&gt;
      expect(AssignmentTeam.get_first_member(1)).to eq(participant1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Import csv file to form teams directly===&lt;br /&gt;
The assignment_team.rb offers a method that could import csv file to form teams directly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.import(row, assignment_id, options)&lt;br /&gt;
    unless Assignment.find_by(id: assignment_id)&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with the id \&amp;quot;&amp;quot; + assignment_id.to_s + &amp;quot;\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    @assignment_team = prototype&lt;br /&gt;
    Team.import(row, assignment_id, options, @assignment_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there is no assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there is no assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;raises an ImportError&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 1).and_return(nil)&lt;br /&gt;
        expect { AssignmentTeam.import([], 1, has_column_names: 'false') }&lt;br /&gt;
            .to raise_error(ImportError, &amp;quot;The assignment with the id \&amp;quot;1\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there exists an assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there exists an assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;imports a csv file to form assignment teams&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 2).and_return(double(&amp;quot;Assignment&amp;quot;, id: 2))&lt;br /&gt;
        allow(AssignmentTeam).to receive(:prototype).and_return(assignment_team)&lt;br /&gt;
        allow(Team).to receive(:import).with([], 2, {}, assignment_team).and_return(true)&lt;br /&gt;
        expect(AssignmentTeam.import([], 2, {})).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Copy the current Assignment team to the CourseTeam===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy(course_id)&lt;br /&gt;
    new_team = CourseTeam.create_team_and_node(course_id)&lt;br /&gt;
    new_team.name = name&lt;br /&gt;
    new_team.save&lt;br /&gt;
    copy_members(new_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#copy&amp;quot; do&lt;br /&gt;
    it &amp;quot;copies the current assignment team and team members to a new course team&amp;quot; do&lt;br /&gt;
      allow(CourseTeam).to receive(:create_team_and_node).with(1).and_return(courseTeam)&lt;br /&gt;
      allow(Team).to receive(:copy_members).with(courseTeam).and_return([])&lt;br /&gt;
      expect(assignment_team.copy(1)).to eq([])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===return a hash of scores that the team has received for the questions====&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def scores(questions)&lt;br /&gt;
    scores = {}&lt;br /&gt;
    scores[:team] = self # This doesn't appear to be used anywhere&lt;br /&gt;
    assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
      scores[questionnaire.symbol] = {}&lt;br /&gt;
      scores[questionnaire.symbol][:assessments] = ReviewResponseMap.where(reviewee_id: self.id)&lt;br /&gt;
      scores[questionnaire.symbol][:scores] = Answer.compute_scores(scores[questionnaire.symbol][:assessments], questions[questionnaire.symbol])&lt;br /&gt;
    end&lt;br /&gt;
    scores[:total_score] = assignment.compute_total_score(scores)&lt;br /&gt;
    scores&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#scores&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns a hash of scores that current assignment team has received for the questions&amp;quot; do&lt;br /&gt;
      allow(assignment_team).to receive(:assignment).and_return(assignment)&lt;br /&gt;
      allow(ReviewResponseMap).to receive(:where).with(reviewee_id: 2).and_return(review_response_map)&lt;br /&gt;
      allow(Answer).to receive(:compute_scores).with(review_response_map, questions[QuizQuestionnaire]).and_return(10)&lt;br /&gt;
      allow(assignment).to receive(:compute_total_score).and_return(10)&lt;br /&gt;
      # expect(assignment_team.scores(questions)[:QuizQuestionnaire]).equal?({assessments: review_response_map, scores: 10}).to be true&lt;br /&gt;
      expect(assignment_team.scores(questions)[:team]).to eq(assignment_team)&lt;br /&gt;
      expect(assignment_team.scores(questions)[:total_score]).to eq(10)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test can successfully test whether the team has submitted files/hyperlinks or not, because it creates a mock function, for the submitted_files function to receive a parameter - so that the team has hypothetically passed in a submitted file. The returning value being true shows that the has_submissions? test succeeded when the team receives a submitted file.&lt;br /&gt;
&lt;br /&gt;
Similarly, we created a mock function for the team to receive a hyperlink using submitted_hyperlink. This second test case returning true shows the hyperlink being submitted is also detected by the function.&lt;br /&gt;
&lt;br /&gt;
When there's no mock happening inside the function, no file or hyperlink will be passed into the team. So has_submissions? returns false is what's being expected.&lt;br /&gt;
&lt;br /&gt;
=='''Result'''==&lt;br /&gt;
Our test cases has coverage: 100%&lt;br /&gt;
&lt;br /&gt;
There are in total 127 relevant lines, and all of them get passed.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
The testing framework in the assignment_team_spec.rb used unit tests to test the functionality of each action in the class. The mock instances are created at the beginning of the file, so that during each test they don't need to be constructed again. In order to test each unit case without depending on other functionalities, the mocked actions, as well as the desired returns are built inside different test cases, depending on the need of the case.&lt;br /&gt;
&lt;br /&gt;
In building the test framework, the key is to understand the input, output and the desired action of each functionality that we want to test. The Rspec test format also has a steep learning curve, but the test shows stable and robust result on the assignment_team.rb.&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118493</id>
		<title>CSC/ECE 517 Fall 2018/OSS E1848 Write unit tests for assignment team.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118493"/>
		<updated>2018-11-03T02:53:03Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For this progect, the goal is to wirte up unit tests for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
Assignment_team.rb in Expertiza provides a method for student to assign a team and finish one assignment. Features come at the cost of complexity; this project is focused on creating the test methods to ensure that user interaction with the assignment interface remains stable and reliable.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
There are some examples for how this project create test methods for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
===Create team===&lt;br /&gt;
In assignment_team.rb,there is a method return the team given the participant.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.team(participant)&lt;br /&gt;
      return nil if participant.nil?&lt;br /&gt;
      team = nil&lt;br /&gt;
      teams_users = TeamsUser.where(user_id: participant.user_id)&lt;br /&gt;
      return nil unless teams_users&lt;br /&gt;
      teams_users.each do |teams_user|&lt;br /&gt;
        team = Team.find(teams_user.team_id)&lt;br /&gt;
        return team if team.parent_id == participant.parent_id&lt;br /&gt;
      end&lt;br /&gt;
      nil&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above method, the test case can be created, and there are three different possible results could be generated.&lt;br /&gt;
*when the participant is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there are not team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return(nil)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when the participant is not nil and there exist team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns the team given the participant&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return([team_user])&lt;br /&gt;
      allow(Team).to receive(:find).with(1).and_return(team)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove team by id===&lt;br /&gt;
The assignment_team.rb also provide a method which could remove team by id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.remove_team_by_id(id)&lt;br /&gt;
      old_team = AssignmentTeam.find(id)&lt;br /&gt;
      old_team.destroy unless old_team.nil?&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;deletes a team given the team id&amp;quot; do&lt;br /&gt;
      old_team = assignment_team1&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with(1).and_return(old_team)&lt;br /&gt;
      allow(old_team).to receive(:destroy).and_return(old_team)&lt;br /&gt;
      expect(AssignmentTeam.remove_team_by_id(1)).to eq(old_team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return the topic chosen by the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the topic chosen by the team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def topic&lt;br /&gt;
    SignedUpTeam.find_by(team_id: self.id, is_waitlisted: 0).try(:topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#topic&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the topic id chosen by this team&amp;quot; do&lt;br /&gt;
      allow(SignedUpTeam).to receive(:find_by).with(team_id:1, is_waitlisted: 0).and_return(signed_up_team1)&lt;br /&gt;
      expect(assignment_team1.topic).to eq(1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test examines the original codes ability to generate the topic that is chosen by the team because it first goes to the mocked instances to look for a team. In this case, to match the mock instance that has created, we look for the team that has team_id as 1, and not being waitlisted. The topic id is set to be 1 in the mock. This function returns 1, because it does return the topic id, for the team that has signed up for a topic.&lt;br /&gt;
&lt;br /&gt;
===Return whether the team has submission===&lt;br /&gt;
The assignment_team.rb offers a method that could return either true or false, in terms of whether the team has submitted work or not&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
    self.submitted_files.any? or self.submitted_hyperlinks.present?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created, and there are three possible results:&lt;br /&gt;
*when current assignment team submitted files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_files).and_return([double(:File)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit files but submitted hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_hyperlinks).and_return([double(:Hyperlink)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit either files or hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return participants of a team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the participants of a team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def participants&lt;br /&gt;
    users = self.users&lt;br /&gt;
    participants = []&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: self.parent_id)&lt;br /&gt;
      participants &amp;lt;&amp;lt; participant unless participant.nil?&lt;br /&gt;
    end&lt;br /&gt;
    participants&lt;br /&gt;
  end&lt;br /&gt;
  alias get_participants participants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#participants&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns participants of the current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentParticipant).to receive(:find_by).with(user_id: 1, parent_id: 2).and_return(participant2)&lt;br /&gt;
      expect(assignment_team.participants).to eq([participant2])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return the first member of the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the first member of the team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_first_member(team_id)&lt;br /&gt;
    find_by(id: team_id).try(:participants).try(:first)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;.get_first_member&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the first participant of current assignment team&amp;quot; do&lt;br /&gt;
      allow(AssignmentTeam).to receive_message_chain(:find_by, :try, :try).with(id: 1).with(:participants).with(:first).and_return(participant1)&lt;br /&gt;
      expect(AssignmentTeam.get_first_member(1)).to eq(participant1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Import csv file to form teams directly===&lt;br /&gt;
The assignment_team.rb offers a method that could import csv file to form teams directly.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.import(row, assignment_id, options)&lt;br /&gt;
    unless Assignment.find_by(id: assignment_id)&lt;br /&gt;
      raise ImportError, &amp;quot;The assignment with the id \&amp;quot;&amp;quot; + assignment_id.to_s + &amp;quot;\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    @assignment_team = prototype&lt;br /&gt;
    Team.import(row, assignment_id, options, @assignment_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there is no assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there is no assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;raises an ImportError&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 1).and_return(nil)&lt;br /&gt;
        expect { AssignmentTeam.import([], 1, has_column_names: 'false') }&lt;br /&gt;
            .to raise_error(ImportError, &amp;quot;The assignment with the id \&amp;quot;1\&amp;quot; was not found. &amp;lt;a href='/assignment/new'&amp;gt;Create&amp;lt;/a&amp;gt; this assignment?&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there exists an assignment with this assignment id&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    context &amp;quot;when there exists an assignment with this assignment id&amp;quot; do&lt;br /&gt;
      it &amp;quot;imports a csv file to form assignment teams&amp;quot; do&lt;br /&gt;
        allow(Assignment).to receive(:find_by).with(id: 2).and_return(double(&amp;quot;Assignment&amp;quot;, id: 2))&lt;br /&gt;
        allow(AssignmentTeam).to receive(:prototype).and_return(assignment_team)&lt;br /&gt;
        allow(Team).to receive(:import).with([], 2, {}, assignment_team).and_return(true)&lt;br /&gt;
        expect(AssignmentTeam.import([], 2, {})).to eq(true)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Copy the current Assignment team to the CourseTeam===&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy(course_id)&lt;br /&gt;
    new_team = CourseTeam.create_team_and_node(course_id)&lt;br /&gt;
    new_team.name = name&lt;br /&gt;
    new_team.save&lt;br /&gt;
    copy_members(new_team)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#copy&amp;quot; do&lt;br /&gt;
    it &amp;quot;copies the current assignment team and team members to a new course team&amp;quot; do&lt;br /&gt;
      allow(CourseTeam).to receive(:create_team_and_node).with(1).and_return(courseTeam)&lt;br /&gt;
      allow(Team).to receive(:copy_members).with(courseTeam).and_return([])&lt;br /&gt;
      expect(assignment_team.copy(1)).to eq([])&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===return a hash of scores that the team has received for the questions====&lt;br /&gt;
The assignment_team.rb offers a method that could copy the current Assignment team to the CourseTeam.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test can successfully test whether the team has submitted files/hyperlinks or not, because it creates a mock function, for the submitted_files function to receive a parameter - so that the team has hypothetically passed in a submitted file. The returning value being true shows that the has_submissions? test succeeded when the team receives a submitted file.&lt;br /&gt;
&lt;br /&gt;
Similarly, we created a mock function for the team to receive a hyperlink using submitted_hyperlink. This second test case returning true shows the hyperlink being submitted is also detected by the function.&lt;br /&gt;
&lt;br /&gt;
When there's no mock happening inside the function, no file or hyperlink will be passed into the team. So has_submissions? returns false is what's being expected.&lt;br /&gt;
&lt;br /&gt;
=='''Result'''==&lt;br /&gt;
Our test cases has coverage: 100%&lt;br /&gt;
&lt;br /&gt;
There are in total 127 relevant lines, and all of them get passed.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
The testing framework in the assignment_team_spec.rb used unit tests to test the functionality of each action in the class. The mock instances are created at the beginning of the file, so that during each test they don't need to be constructed again. In order to test each unit case without depending on other functionalities, the mocked actions, as well as the desired returns are built inside different test cases, depending on the need of the case.&lt;br /&gt;
&lt;br /&gt;
In building the test framework, the key is to understand the input, output and the desired action of each functionality that we want to test. The Rspec test format also has a steep learning curve, but the test shows stable and robust result on the assignment_team.rb.&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118479</id>
		<title>CSC/ECE 517 Fall 2018/OSS E1848 Write unit tests for assignment team.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118479"/>
		<updated>2018-11-03T02:31:55Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Return participants of a team */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For this progect, the goal is to wirte up unit tests for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
Assignment_team.rb in Expertiza provides a method for student to assign a team and finish one assignment. Features come at the cost of complexity; this project is focused on creating the test methods to ensure that user interaction with the assignment interface remains stable and reliable.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
There are some examples for how this project create test methods for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
===Create team===&lt;br /&gt;
In assignment_team.rb,there is a method return the team given the participant.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.team(participant)&lt;br /&gt;
      return nil if participant.nil?&lt;br /&gt;
      team = nil&lt;br /&gt;
      teams_users = TeamsUser.where(user_id: participant.user_id)&lt;br /&gt;
      return nil unless teams_users&lt;br /&gt;
      teams_users.each do |teams_user|&lt;br /&gt;
        team = Team.find(teams_user.team_id)&lt;br /&gt;
        return team if team.parent_id == participant.parent_id&lt;br /&gt;
      end&lt;br /&gt;
      nil&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above method, the test case can be created, and there are three different possible results could be generated.&lt;br /&gt;
*when the participant is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there are not team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return(nil)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when the participant is not nil and there exist team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns the team given the participant&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return([team_user])&lt;br /&gt;
      allow(Team).to receive(:find).with(1).and_return(team)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove team by id===&lt;br /&gt;
The assignment_team.rb also provide a method which could remove team by id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.remove_team_by_id(id)&lt;br /&gt;
      old_team = AssignmentTeam.find(id)&lt;br /&gt;
      old_team.destroy unless old_team.nil?&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;deletes a team given the team id&amp;quot; do&lt;br /&gt;
      old_team = assignment_team1&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with(1).and_return(old_team)&lt;br /&gt;
      allow(old_team).to receive(:destroy).and_return(old_team)&lt;br /&gt;
      expect(AssignmentTeam.remove_team_by_id(1)).to eq(old_team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return the topic chosen by the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the topic chosen by the team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def topic&lt;br /&gt;
    SignedUpTeam.find_by(team_id: self.id, is_waitlisted: 0).try(:topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#topic&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the topic id chosen by this team&amp;quot; do&lt;br /&gt;
      allow(SignedUpTeam).to receive(:find_by).with(team_id:1, is_waitlisted: 0).and_return(signed_up_team1)&lt;br /&gt;
      expect(assignment_team1.topic).to eq(1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test examines the original codes ability to generate the topic that is chosen by the team because it first goes to the mocked instances to look for a team. In this case, to match the mock instance that has created, we look for the team that has team_id as 1, and not being waitlisted. The topic id is set to be 1 in the mock. This function returns 1, because it does return the topic id, for the team that has signed up for a topic.&lt;br /&gt;
&lt;br /&gt;
===Return whether the team has submission===&lt;br /&gt;
The assignment_team.rb offers a method that could return either true or false, in terms of whether the team has submitted work or not&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
    self.submitted_files.any? or self.submitted_hyperlinks.present?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created, and there are three possible results:&lt;br /&gt;
*when current assignment team submitted files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_files).and_return([double(:File)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit files but submitted hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_hyperlinks).and_return([double(:Hyperlink)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit either files or hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return participants of a team===&lt;br /&gt;
The participants function would return the participants of a team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def participants&lt;br /&gt;
    users = self.users&lt;br /&gt;
    participants = []&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: self.parent_id)&lt;br /&gt;
      participants &amp;lt;&amp;lt; participant unless participant.nil?&lt;br /&gt;
    end&lt;br /&gt;
    participants&lt;br /&gt;
  end&lt;br /&gt;
  alias get_participants participants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*returns participants of the current assignment team&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test can successfully test whether the team has submitted files/hyperlinks or not, because it creates a mock function, for the submitted_files function to receive a parameter - so that the team has hypothetically passed in a submitted file. The returning value being true shows that the has_submissions? test succeeded when the team receives a submitted file.&lt;br /&gt;
&lt;br /&gt;
Similarly, we created a mock function for the team to receive a hyperlink using submitted_hyperlink. This second test case returning true shows the hyperlink being submitted is also detected by the function.&lt;br /&gt;
&lt;br /&gt;
When there's no mock happening inside the function, no file or hyperlink will be passed into the team. So has_submissions? returns false is what's being expected.&lt;br /&gt;
&lt;br /&gt;
=='''Result'''==&lt;br /&gt;
Our test cases has coverage: 100%&lt;br /&gt;
&lt;br /&gt;
There are in total 127 relevant lines, and all of them get passed.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
The testing framework in the assignment_team_spec.rb used unit tests to test the functionality of each action in the class. The mock instances are created at the beginning of the file, so that during each test they don't need to be constructed again. In order to test each unit case without depending on other functionalities, the mocked actions, as well as the desired returns are built inside different test cases, depending on the need of the case.&lt;br /&gt;
&lt;br /&gt;
In building the test framework, the key is to understand the input, output and the desired action of each functionality that we want to test. The Rspec test format also has a steep learning curve, but the test shows stable and robust result on the assignment_team.rb.&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118478</id>
		<title>CSC/ECE 517 Fall 2018/OSS E1848 Write unit tests for assignment team.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118478"/>
		<updated>2018-11-03T02:31:16Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Return participants of a team */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For this progect, the goal is to wirte up unit tests for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
Assignment_team.rb in Expertiza provides a method for student to assign a team and finish one assignment. Features come at the cost of complexity; this project is focused on creating the test methods to ensure that user interaction with the assignment interface remains stable and reliable.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
There are some examples for how this project create test methods for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
===Create team===&lt;br /&gt;
In assignment_team.rb,there is a method return the team given the participant.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.team(participant)&lt;br /&gt;
      return nil if participant.nil?&lt;br /&gt;
      team = nil&lt;br /&gt;
      teams_users = TeamsUser.where(user_id: participant.user_id)&lt;br /&gt;
      return nil unless teams_users&lt;br /&gt;
      teams_users.each do |teams_user|&lt;br /&gt;
        team = Team.find(teams_user.team_id)&lt;br /&gt;
        return team if team.parent_id == participant.parent_id&lt;br /&gt;
      end&lt;br /&gt;
      nil&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above method, the test case can be created, and there are three different possible results could be generated.&lt;br /&gt;
*when the participant is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there are not team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return(nil)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when the participant is not nil and there exist team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns the team given the participant&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return([team_user])&lt;br /&gt;
      allow(Team).to receive(:find).with(1).and_return(team)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove team by id===&lt;br /&gt;
The assignment_team.rb also provide a method which could remove team by id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.remove_team_by_id(id)&lt;br /&gt;
      old_team = AssignmentTeam.find(id)&lt;br /&gt;
      old_team.destroy unless old_team.nil?&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;deletes a team given the team id&amp;quot; do&lt;br /&gt;
      old_team = assignment_team1&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with(1).and_return(old_team)&lt;br /&gt;
      allow(old_team).to receive(:destroy).and_return(old_team)&lt;br /&gt;
      expect(AssignmentTeam.remove_team_by_id(1)).to eq(old_team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return the topic chosen by the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the topic chosen by the team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def topic&lt;br /&gt;
    SignedUpTeam.find_by(team_id: self.id, is_waitlisted: 0).try(:topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#topic&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the topic id chosen by this team&amp;quot; do&lt;br /&gt;
      allow(SignedUpTeam).to receive(:find_by).with(team_id:1, is_waitlisted: 0).and_return(signed_up_team1)&lt;br /&gt;
      expect(assignment_team1.topic).to eq(1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test examines the original codes ability to generate the topic that is chosen by the team because it first goes to the mocked instances to look for a team. In this case, to match the mock instance that has created, we look for the team that has team_id as 1, and not being waitlisted. The topic id is set to be 1 in the mock. This function returns 1, because it does return the topic id, for the team that has signed up for a topic.&lt;br /&gt;
&lt;br /&gt;
===Return whether the team has submission===&lt;br /&gt;
The assignment_team.rb offers a method that could return either true or false, in terms of whether the team has submitted work or not&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
    self.submitted_files.any? or self.submitted_hyperlinks.present?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created, and there are three possible results:&lt;br /&gt;
*when current assignment team submitted files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_files).and_return([double(:File)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit files but submitted hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_hyperlinks).and_return([double(:Hyperlink)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit either files or hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return participants of a team===&lt;br /&gt;
The participant's function would return the participants of a team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def participants&lt;br /&gt;
    users = self.users&lt;br /&gt;
    participants = []&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: self.parent_id)&lt;br /&gt;
      participants &amp;lt;&amp;lt; participant unless participant.nil?&lt;br /&gt;
    end&lt;br /&gt;
    participants&lt;br /&gt;
  end&lt;br /&gt;
  alias get_participants participants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*returns participants of the current assignment team&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test can successfully test whether the team has submitted files/hyperlinks or not, because it creates a mock function, for the submitted_files function to receive a parameter - so that the team has hypothetically passed in a submitted file. The returning value being true shows that the has_submissions? test succeeded when the team receives a submitted file.&lt;br /&gt;
&lt;br /&gt;
Similarly, we created a mock function for the team to receive a hyperlink using submitted_hyperlink. This second test case returning true shows the hyperlink being submitted is also detected by the function.&lt;br /&gt;
&lt;br /&gt;
When there's no mock happening inside the function, no file or hyperlink will be passed into the team. So has_submissions? returns false is what's being expected.&lt;br /&gt;
&lt;br /&gt;
=='''Result'''==&lt;br /&gt;
Our test cases has coverage: 100%&lt;br /&gt;
&lt;br /&gt;
There are in total 127 relevant lines, and all of them get passed.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
The testing framework in the assignment_team_spec.rb used unit tests to test the functionality of each action in the class. The mock instances are created at the beginning of the file, so that during each test they don't need to be constructed again. In order to test each unit case without depending on other functionalities, the mocked actions, as well as the desired returns are built inside different test cases, depending on the need of the case.&lt;br /&gt;
&lt;br /&gt;
In building the test framework, the key is to understand the input, output and the desired action of each functionality that we want to test. The Rspec test format also has a steep learning curve, but the test shows stable and robust result on the assignment_team.rb.&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118100</id>
		<title>CSC/ECE 517 Fall 2018/OSS E1848 Write unit tests for assignment team.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118100"/>
		<updated>2018-11-02T20:02:33Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For this progect, the goal is to wirte up unit tests for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
Assignment_team.rb in Expertiza provides a method for student to assign a team and finish one assignment. Features come at the cost of complexity; this project is focused on creating the test methods to ensure that user interaction with the assignment interface remains stable and reliable.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
There are some examples for how this project create test methods for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
===Create team===&lt;br /&gt;
In assignment_team.rb,there is a method return the team given the participant.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.team(participant)&lt;br /&gt;
      return nil if participant.nil?&lt;br /&gt;
      team = nil&lt;br /&gt;
      teams_users = TeamsUser.where(user_id: participant.user_id)&lt;br /&gt;
      return nil unless teams_users&lt;br /&gt;
      teams_users.each do |teams_user|&lt;br /&gt;
        team = Team.find(teams_user.team_id)&lt;br /&gt;
        return team if team.parent_id == participant.parent_id&lt;br /&gt;
      end&lt;br /&gt;
      nil&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above method, the test case can be created, and there are three different possible results could be generated.&lt;br /&gt;
*when the participant is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there are not team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return(nil)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when the participant is not nil and there exist team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns the team given the participant&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return([team_user])&lt;br /&gt;
      allow(Team).to receive(:find).with(1).and_return(team)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove team by id===&lt;br /&gt;
The assignment_team.rb also provide a method which could remove team by id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.remove_team_by_id(id)&lt;br /&gt;
      old_team = AssignmentTeam.find(id)&lt;br /&gt;
      old_team.destroy unless old_team.nil?&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;deletes a team given the team id&amp;quot; do&lt;br /&gt;
      old_team = assignment_team1&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with(1).and_return(old_team)&lt;br /&gt;
      allow(old_team).to receive(:destroy).and_return(old_team)&lt;br /&gt;
      expect(AssignmentTeam.remove_team_by_id(1)).to eq(old_team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return the topic chosen by the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the topic chosen by the team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def topic&lt;br /&gt;
    SignedUpTeam.find_by(team_id: self.id, is_waitlisted: 0).try(:topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#topic&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the topic id chosen by this team&amp;quot; do&lt;br /&gt;
      allow(SignedUpTeam).to receive(:find_by).with(team_id:1, is_waitlisted: 0).and_return(signed_up_team1)&lt;br /&gt;
      expect(assignment_team1.topic).to eq(1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test examines the original codes ability to generate the topic that is chosen by the team because it first goes to the mocked instances to look for a team. In this case, to match the mock instance that has created, we look for the team that has team_id as 1, and not being waitlisted. The topic id is set to be 1 in the mock. This function returns 1, because it does return the topic id, for the team that has signed up for a topic.&lt;br /&gt;
&lt;br /&gt;
===Return whether the team has submission===&lt;br /&gt;
The assignment_team.rb offers a method that could return either true or false, in terms of whether the team has submitted work or not&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
    self.submitted_files.any? or self.submitted_hyperlinks.present?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created, and there are three possible results:&lt;br /&gt;
*when current assignment team submitted files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_files).and_return([double(:File)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit files but submitted hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_hyperlinks).and_return([double(:Hyperlink)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit either files or hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return participants of a team===&lt;br /&gt;
The participants function would return the participants of a team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def participants&lt;br /&gt;
    users = self.users&lt;br /&gt;
    participants = []&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: self.parent_id)&lt;br /&gt;
      participants &amp;lt;&amp;lt; participant unless participant.nil?&lt;br /&gt;
    end&lt;br /&gt;
    participants&lt;br /&gt;
  end&lt;br /&gt;
  alias get_participants participants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test can successfully test whether the team has submitted files/hyperlinks or not, because it creates a mock function, for the submitted_files function to receive a parameter - so that the team has hypothetically passed in a submitted file. The returning value being true shows that the has_submissions? test succeeded when the team receives a submitted file.&lt;br /&gt;
&lt;br /&gt;
Similarly, we created a mock function for the team to receive a hyperlink using submitted_hyperlink. This second test case returning true shows the hyperlink being submitted is also detected by the function.&lt;br /&gt;
&lt;br /&gt;
When there's no mock happening inside the function, no file or hyperlink will be passed into the team. So has_submissions? returns false is what's being expected.&lt;br /&gt;
&lt;br /&gt;
=='''Result'''==&lt;br /&gt;
Our test cases has coverage: 100%&lt;br /&gt;
&lt;br /&gt;
There are in total 127 relevant lines, and all of them get passed.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
The testing framework in the assignment_team_spec.rb used unit tests to test the functionality of each action in the class. The mock instances are created at the beginning of the file, so that during each test they don't need to be constructed again. In order to test each unit case without depending on other functionalities, the mocked actions, as well as the desired returns are built inside different test cases, depending on the need of the case.&lt;br /&gt;
&lt;br /&gt;
In building the test framework, the key is to understand the input, output and the desired action of each functionality that we want to test. The Rspec test format also has a steep learning curve, but the test shows stable and robust result on the assignment_team.rb.&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118098</id>
		<title>CSC/ECE 517 Fall 2018/OSS E1848 Write unit tests for assignment team.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118098"/>
		<updated>2018-11-02T20:01:36Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Return participants of a team */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For this progect, the goal is to wirte up unit tests for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
Assignment_team.rb in Expertiza provides a method for student to assign a team and finish one assignment. Features come at the cost of complexity; this project is focused on creating the test methods to ensure that user interaction with the assignment interface remains stable and reliable.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
There are some examples for how this project create test methods for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
===Create team===&lt;br /&gt;
In assignment_team.rb,there is a method return the team given the participant.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.team(participant)&lt;br /&gt;
      return nil if participant.nil?&lt;br /&gt;
      team = nil&lt;br /&gt;
      teams_users = TeamsUser.where(user_id: participant.user_id)&lt;br /&gt;
      return nil unless teams_users&lt;br /&gt;
      teams_users.each do |teams_user|&lt;br /&gt;
        team = Team.find(teams_user.team_id)&lt;br /&gt;
        return team if team.parent_id == participant.parent_id&lt;br /&gt;
      end&lt;br /&gt;
      nil&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above method, the test case can be created, and there are three different possible results could be generated.&lt;br /&gt;
*when the participant is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there are not team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return(nil)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when the participant is not nil and there exist team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns the team given the participant&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return([team_user])&lt;br /&gt;
      allow(Team).to receive(:find).with(1).and_return(team)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove team by id===&lt;br /&gt;
The assignment_team.rb also provide a method which could remove team by id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.remove_team_by_id(id)&lt;br /&gt;
      old_team = AssignmentTeam.find(id)&lt;br /&gt;
      old_team.destroy unless old_team.nil?&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;deletes a team given the team id&amp;quot; do&lt;br /&gt;
      old_team = assignment_team1&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with(1).and_return(old_team)&lt;br /&gt;
      allow(old_team).to receive(:destroy).and_return(old_team)&lt;br /&gt;
      expect(AssignmentTeam.remove_team_by_id(1)).to eq(old_team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return the topic chosen by the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the topic chosen by the team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def topic&lt;br /&gt;
    SignedUpTeam.find_by(team_id: self.id, is_waitlisted: 0).try(:topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#topic&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the topic id chosen by this team&amp;quot; do&lt;br /&gt;
      allow(SignedUpTeam).to receive(:find_by).with(team_id:1, is_waitlisted: 0).and_return(signed_up_team1)&lt;br /&gt;
      expect(assignment_team1.topic).to eq(1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test examines the original codes ability to generate the topic that is chosen by the team because it first goes to the mocked instances to look for a team. In this case, to match the mock instance that has created, we look for the team that has team_id as 1, and not being waitlisted. The topic id is set to be 1 in the mock. This function returns 1, because it does return the topic id, for the team that has signed up for a topic.&lt;br /&gt;
&lt;br /&gt;
===Return whether the team has submission===&lt;br /&gt;
The assignment_team.rb offers a method that could return either true or false, in terms of whether the team has submitted work or not&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
    self.submitted_files.any? or self.submitted_hyperlinks.present?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created, and there are three possible results:&lt;br /&gt;
*when current assignment team submitted files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_files).and_return([double(:File)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit files but submitted hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_hyperlinks).and_return([double(:Hyperlink)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit either files or hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return participants of a team===&lt;br /&gt;
The participants function would return the participants of a team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def participants&lt;br /&gt;
    users = self.users&lt;br /&gt;
    participants = []&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: self.parent_id)&lt;br /&gt;
      participants &amp;lt;&amp;lt; participant unless participant.nil?&lt;br /&gt;
    end&lt;br /&gt;
    participants&lt;br /&gt;
  end&lt;br /&gt;
  alias get_participants participants&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This test can successfully test whether the team has submitted files/hyperlinks or not, because it creates a mock function, for the submitted_files function to receive a parameter - so that the team has hypothetically passed in a submitted file. The returning value being true shows that the has_submissions? test succeeded when the team receives a submitted file.&lt;br /&gt;
&lt;br /&gt;
Similarly, we created a mock function for the team to receive a hyperlink using submitted_hyperlink. This second test case returning true shows the hyperlink being submitted is also detected by the function.&lt;br /&gt;
&lt;br /&gt;
When there's no mock happening inside the function, no file or hyperlink will be passed into the team. So has_submissions? returns false is what's being expected.&lt;br /&gt;
&lt;br /&gt;
=='''Result'''==&lt;br /&gt;
Our test cases has coverage: 100%&lt;br /&gt;
&lt;br /&gt;
There are in total 127 relevant lines, and all of them get passed.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
The testing framework in the assignment_team_spec.rb used unit tests to test the functionality of each action in the class. The mock instances are created at the beginning of the file, so that during each test they don't need to be constructed again. In order to test each unit case without depending on other functionalities, the mocked actions, as well as the desired returns are built inside different test cases, depending on the need of the case.&lt;br /&gt;
&lt;br /&gt;
In building the test framework, the key is to understand the input, output and the desired action of each functionality that we want to test. The Rspec test format also has a steep learning curve, but the test shows stable and robust result on the assignment_team.rb.&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118096</id>
		<title>CSC/ECE 517 Fall 2018/OSS E1848 Write unit tests for assignment team.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018/OSS_E1848_Write_unit_tests_for_assignment_team.rb&amp;diff=118096"/>
		<updated>2018-11-02T20:01:10Z</updated>

		<summary type="html">&lt;p&gt;Jli94: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For this progect, the goal is to wirte up unit tests for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
=='''Introduction'''==&lt;br /&gt;
Assignment_team.rb in Expertiza provides a method for student to assign a team and finish one assignment. Features come at the cost of complexity; this project is focused on creating the test methods to ensure that user interaction with the assignment interface remains stable and reliable.&lt;br /&gt;
&lt;br /&gt;
=='''Project Description'''==&lt;br /&gt;
There are some examples for how this project create test methods for assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
===Create team===&lt;br /&gt;
In assignment_team.rb,there is a method return the team given the participant.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.team(participant)&lt;br /&gt;
      return nil if participant.nil?&lt;br /&gt;
      team = nil&lt;br /&gt;
      teams_users = TeamsUser.where(user_id: participant.user_id)&lt;br /&gt;
      return nil unless teams_users&lt;br /&gt;
      teams_users.each do |teams_user|&lt;br /&gt;
        team = Team.find(teams_user.team_id)&lt;br /&gt;
        return team if team.parent_id == participant.parent_id&lt;br /&gt;
      end&lt;br /&gt;
      nil&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above method, the test case can be created, and there are three different possible results could be generated.&lt;br /&gt;
*when the participant is nil&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when there are not team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns nil&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return(nil)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when the participant is not nil and there exist team users records&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;returns the team given the participant&amp;quot; do&lt;br /&gt;
      allow(TeamsUser).to receive(:where).with(user_id: 1).and_return([team_user])&lt;br /&gt;
      allow(Team).to receive(:find).with(1).and_return(team)&lt;br /&gt;
      expect(AssignmentTeam.team(participant1)).to eq(team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Remove team by id===&lt;br /&gt;
The assignment_team.rb also provide a method which could remove team by id.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def self.remove_team_by_id(id)&lt;br /&gt;
      old_team = AssignmentTeam.find(id)&lt;br /&gt;
      old_team.destroy unless old_team.nil?&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    it &amp;quot;deletes a team given the team id&amp;quot; do&lt;br /&gt;
      old_team = assignment_team1&lt;br /&gt;
      allow(AssignmentTeam).to receive(:find).with(1).and_return(old_team)&lt;br /&gt;
      allow(old_team).to receive(:destroy).and_return(old_team)&lt;br /&gt;
      expect(AssignmentTeam.remove_team_by_id(1)).to eq(old_team)&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Return the topic chosen by the team===&lt;br /&gt;
The assignment_team.rb offers a method that could return the topic chosen by the team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def topic&lt;br /&gt;
    SignedUpTeam.find_by(team_id: self.id, is_waitlisted: 0).try(:topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe &amp;quot;#topic&amp;quot; do&lt;br /&gt;
    it &amp;quot;returns the topic id chosen by this team&amp;quot; do&lt;br /&gt;
      allow(SignedUpTeam).to receive(:find_by).with(team_id:1, is_waitlisted: 0).and_return(signed_up_team1)&lt;br /&gt;
      expect(assignment_team1.topic).to eq(1)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This test examines the original codes ability to generate the topic that is chosen by the team because it first goes to the mocked instances to look for a team. In this case, to match the mock instance that has created, we look for the team that has team_id as 1, and not being waitlisted. The topic id is set to be 1 in the mock. This function returns 1, because it does return the topic id, for the team that has signed up for a topic.&lt;br /&gt;
&lt;br /&gt;
===Return whether the team has submission===&lt;br /&gt;
The assignment_team.rb offers a method that could return either true or false, in terms of whether the team has submitted work or not&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def has_submissions?&lt;br /&gt;
    self.submitted_files.any? or self.submitted_hyperlinks.present?&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Based on the above code, the test case can be created, and there are three possible results:&lt;br /&gt;
*when current assignment team submitted files&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_files).and_return([double(:File)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit files but submitted hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns true&amp;quot; do&lt;br /&gt;
    allow(assignment_team1).to receive(:submitted_hyperlinks).and_return([double(:Hyperlink)])&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*when current assignment team did not submit either files or hyperlinks&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  it &amp;quot;returns false&amp;quot; do&lt;br /&gt;
    expect(assignment_team1.has_submissions? ).to be false&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Return participants of a team===&lt;br /&gt;
The participants function would return the participants of a team.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def participants&lt;br /&gt;
    users = self.users&lt;br /&gt;
    participants = []&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      participant = AssignmentParticipant.find_by(user_id: user.id, parent_id: self.parent_id)&lt;br /&gt;
      participants &amp;lt;&amp;lt; participant unless participant.nil?&lt;br /&gt;
    end&lt;br /&gt;
    participants&lt;br /&gt;
  end&lt;br /&gt;
  alias get_participants participants&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
This test can successfully test whether the team has submitted files/hyperlinks or not, because it creates a mock function, for the submitted_files function to receive a parameter - so that the team has hypothetically passed in a submitted file. The returning value being true shows that the has_submissions? test succeeded when the team receives a submitted file.&lt;br /&gt;
&lt;br /&gt;
Similarly, we created a mock function for the team to receive a hyperlink using submitted_hyperlink. This second test case returning true shows the hyperlink being submitted is also detected by the function.&lt;br /&gt;
&lt;br /&gt;
When there's no mock happening inside the function, no file or hyperlink will be passed into the team. So has_submissions? returns false is what's being expected.&lt;br /&gt;
&lt;br /&gt;
=='''Result'''==&lt;br /&gt;
Our test cases has coverage: 100%&lt;br /&gt;
&lt;br /&gt;
There are in total 127 relevant lines, and all of them get passed.&lt;br /&gt;
&lt;br /&gt;
=='''Conclusion'''==&lt;br /&gt;
The testing framework in the assignment_team_spec.rb used unit tests to test the functionality of each action in the class. The mock instances are created at the beginning of the file, so that during each test they don't need to be constructed again. In order to test each unit case without depending on other functionalities, the mocked actions, as well as the desired returns are built inside different test cases, depending on the need of the case.&lt;br /&gt;
&lt;br /&gt;
In building the test framework, the key is to understand the input, output and the desired action of each functionality that we want to test. The Rspec test format also has a steep learning curve, but the test shows stable and robust result on the assignment_team.rb.&lt;/div&gt;</summary>
		<author><name>Jli94</name></author>
	</entry>
</feed>