<?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=Ychen71</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=Ychen71"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Ychen71"/>
	<updated>2026-06-13T01:24:50Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1621_Refactor_and_Test_the_Quizzing_Feature&amp;diff=102282</id>
		<title>CSC/ECE 517 Spring 2016 E1621 Refactor and Test the Quizzing Feature</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1621_Refactor_and_Test_the_Quizzing_Feature&amp;diff=102282"/>
		<updated>2016-04-24T14:58:53Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Problem Statement */ Update google doc on quizzing feature&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction to Expertiza =&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt; is a project developed using Ruby on Rails&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/getting_started.html&amp;lt;/ref&amp;gt;. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an [https://en.wikipedia.org/wiki/Open_source open source] application and the code can be cloned from [https://github.com/expertiza/expertiza GitHub]. This application provides an efficient way to manage assignments, grades and reviews.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
The Expertiza quiz feature is in need of refactoring. Currently, quizzes are checked by &amp;lt;code&amp;gt;questionnaires_controller.valid_quiz&amp;lt;/code&amp;gt;. This method is rather long, involved, and does not take advantage of object-oriented practices. It combs through the parameters hash received from a request and manually checks all quiz fields, all question fields, all question choice fields, and verifies that each question has a correct choice.&lt;br /&gt;
&lt;br /&gt;
We will refactor the method to construct a quiz questionniare and then call &amp;lt;code&amp;gt;valid?&amp;lt;/code&amp;gt; to recursively validate the object tree using ActiveRecord validations. This is an improvement over the current code which checks all questions manually. The purpose of refactoring in this manner is to enhance readability, DRYness, and maintainability of Expertiza code.&lt;br /&gt;
&lt;br /&gt;
In addition to this refactoring we will implement integration testing on the quiz feature to verify that the expected behavior is present for all use cases.&lt;br /&gt;
&lt;br /&gt;
A full description of the assignment may be found [https://docs.google.com/document/d/13oRmKemlwRzXG1ItcI2zTx4r3gAAfvmuobZjxiy0oVo/edit#heading=h.su78b3gdq1a7 here]&lt;br /&gt;
&lt;br /&gt;
Program flow of this quizzing feature can be found [https://docs.google.com/document/d/1Rmq3-PfpmMeYFIOlP5Ik5pMWHbg-x-DzNfP5hDOXYfs/ here]&lt;br /&gt;
&lt;br /&gt;
=Classes involved=&lt;br /&gt;
* questionnaires_controller.rb&lt;br /&gt;
* quiz_quesetionnaire.rb&lt;br /&gt;
* quiz_question.rb&lt;br /&gt;
* quiz_question_choice.rb&lt;br /&gt;
* spec/features/quiz_spec.rb&lt;br /&gt;
&lt;br /&gt;
=Use Case and Scenarios=&lt;br /&gt;
The Quiz Use Case allows for instructors to create and manage assignments where students may write quizzes for reviewers on materials they have submitted. See the following scenarios for a complete description of how the feature is expected to work.&lt;br /&gt;
&lt;br /&gt;
==Instructors are able to create and manage an assignment's quiz feature==&lt;br /&gt;
An instructor chooses to create an assignment that has a quiz [S1]. While editing the assignment they may choose the number of quiz questions [S2] and set which phases students are allowed to take the quizzes [S3].&lt;br /&gt;
&lt;br /&gt;
* [S1] - When creating the assignment there is a checkbox labeled &amp;quot;has quiz.&amp;quot; Checking this box creates an assignment that includes a quiz.&lt;br /&gt;
* [S2] - When an assignment has a quiz there is an input field that accepts the number of questions that will be on each quiz. Setting this number appropriately changes the number of quiz questions.&lt;br /&gt;
* [S3] - Students may not take quizzes on a phase that does not allow them to do so. When on a stage that does allow for quizzes, they may take quizzes on work that they have reviewed.&lt;br /&gt;
&lt;br /&gt;
==Instructors can view quiz questions and scores from the tree view==&lt;br /&gt;
After an assignment has been created the instructor may choose to view student quizzes from the tree view [S1]. While on the quiz view page they see student quizzes [S2] and student responses [S3].&lt;br /&gt;
&lt;br /&gt;
* [S1] - The instructor may navigate to the list of assignments. Assignments with quizzes enabled will provide a link for the instructor to follow and view student quizzes.&lt;br /&gt;
* [S2] - The instructor shall be presented with the quiz title, questions, and answer choices. The correct answer choices will be in bold.&lt;br /&gt;
* [S3] - The score for each student who has taken the quiz shall be listed along with the average quiz score.&lt;br /&gt;
&lt;br /&gt;
==Students can create and edit quizzes==&lt;br /&gt;
A student navigates to the assignment work page and chooses to create a new quiz [S1] or edit an existing one [S2]. By doing so they are able to choose a quiz title  and quiz questions [S3]. Invalid input results in an error message prompting the student to fix the issue [E1].&lt;br /&gt;
&lt;br /&gt;
* [S1] - A student may only create a quiz if they have not yet done so.&lt;br /&gt;
* [S2] - A student may only edit a quiz if they have previously created one.&lt;br /&gt;
* [S3] - The quiz has the number of quiz questions defined by the instructor in the assignment.&lt;br /&gt;
&lt;br /&gt;
* [E1] - Possible errors include:&lt;br /&gt;
** The quiz has no name.&lt;br /&gt;
** One or more questions is missing text.&lt;br /&gt;
** One or more choices is missing text.&lt;br /&gt;
** A question is missing a correct answer choice.&lt;br /&gt;
&lt;br /&gt;
==Students can take quizzes on assignments they have reviewed==&lt;br /&gt;
A student decides to take a quiz [S1] on another team's assignment that they have previously reviewed. They select an artifact for review [S2] and fill in their answers. After submitting the quiz they can view their score on the take quizzes page [S3] and see question-by-question scores by clicking view [S4].&lt;br /&gt;
&lt;br /&gt;
* [S1] - The student may only take a quiz during a stage in which the assignment is configured to allow them to do so.&lt;br /&gt;
* [S2] - Only quizzes from submissions they have reviewed are available.&lt;br /&gt;
* [S3] - The take quizzes page lists the final score for each quiz.&lt;br /&gt;
* [S4] - Choosing to view a quiz will show a student each question along with their answers and the correct answers.&lt;br /&gt;
&lt;br /&gt;
=Design and Implementation=&lt;br /&gt;
Design for the refactoring has been driven by object oriented principles and test-driven-development, and makes use of the existing object hierarchy described in the following UML diagram. &lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza_quiz_hierarchy.png|Expertiza Quiz Hierarchy]]&lt;br /&gt;
&lt;br /&gt;
See the below sections for a part-by-part breakdown of the planned implementation for this project.&lt;br /&gt;
&lt;br /&gt;
==Tests==&lt;br /&gt;
Quiz tests will be added to the file spec/features/quiz_spec.rb and will make use of&lt;br /&gt;
* rspec&lt;br /&gt;
* capybara&lt;br /&gt;
* selenium&lt;br /&gt;
&lt;br /&gt;
Tests will be made which fully cover the expected behavior of each listed scenario in the Use Case.&lt;br /&gt;
&lt;br /&gt;
==Refactoring==&lt;br /&gt;
Each of the following files will be refactored as described.&lt;br /&gt;
&lt;br /&gt;
===QuestionnaireController===&lt;br /&gt;
Refactor the &amp;lt;code&amp;gt;valid_quiz&amp;lt;/code&amp;gt; method. It will be renamed to &amp;lt;code&amp;gt;validate_quiz&amp;lt;/code&amp;gt; to more properly describe the action that occurs as a result of it being called. The behavior will be changed to construct a new quiz questionnaire with submitted questions wich will be validated using &amp;lt;code&amp;gt;quiz.valid?&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===QuizQuestionnaire===&lt;br /&gt;
The following fields will be validated using ActiveRecord validations.&lt;br /&gt;
* Presence of name&lt;br /&gt;
&lt;br /&gt;
===QuizQuestion===&lt;br /&gt;
The following fields will be validated using ActiveRecord validations&lt;br /&gt;
* Presence of text&lt;br /&gt;
* Presence of type&lt;br /&gt;
* Has a correct answer&lt;br /&gt;
&lt;br /&gt;
===QuizQuestionChoice===&lt;br /&gt;
The following fields will be validated using ActiveRecord validations&lt;br /&gt;
* Presence of text&lt;br /&gt;
&lt;br /&gt;
===Test Cases===&lt;br /&gt;
In order to verify that refactoring has been done correctly and maintains the same external behavior, we will write test cases to the existing implementation. These test cases will be the ground truth of the validation feature. Refactored code will not be considered complete until all of these test cases once again pass.&lt;br /&gt;
&lt;br /&gt;
=Post Completion=&lt;br /&gt;
Testing and refactoring have been completed and a [https://github.com/expertiza/expertiza/pull/671 pull request] created to merge features back into master.&lt;br /&gt;
&lt;br /&gt;
==Refactoring==&lt;br /&gt;
Refactoring went according to plan. The following model files were edited to use ActiveRecord validations on specific fields&lt;br /&gt;
* question.rb&lt;br /&gt;
* questionnaire.rb&lt;br /&gt;
* quiz_quesetion.rb&lt;br /&gt;
* quiz_question_choice.rb&lt;br /&gt;
&lt;br /&gt;
In addition, tests were added to &amp;lt;code&amp;gt;spec/controllers/questionnaires_controller_spec.rb&amp;lt;/code&amp;gt; to test quiz validation. With passing tests, the &amp;lt;code&amp;gt;validate_quiz&amp;lt;/code&amp;gt; method in &amp;lt;code&amp;gt;questionnaires_controller&amp;lt;/code&amp;gt; was refactored. It now constructs a quiz from params and returns it if it is valid. If the quiz is invalid an error message is returned.&lt;br /&gt;
&lt;br /&gt;
===Before Refactoring===&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
def valid_quiz&lt;br /&gt;
:num_quiz_questions = Assignment.find(params[:aid]).num_quiz_questions&lt;br /&gt;
:valid = &amp;quot;valid&amp;quot;&lt;br /&gt;
&lt;br /&gt;
:(1..num_quiz_questions).each do |i|&lt;br /&gt;
:: if params[:new_question][i.to_s] == ''&lt;br /&gt;
:::// One of the questions text is not filled out&lt;br /&gt;
:::valid = &amp;quot;Please make sure all questions have text&amp;quot;&lt;br /&gt;
:::break&lt;br /&gt;
::elsif !params.has_key?(:question_type) || !params[:question_type].has_key?(i.to_s) || params[:question_type][i.to_s][:type] == nil&lt;br /&gt;
:::// A type isnt selected for a question&lt;br /&gt;
:::valid = &amp;quot;Please select a type for each question&amp;quot;&lt;br /&gt;
:::break&lt;br /&gt;
::elsif params[:questionnaire][:name]==&amp;quot;&amp;quot;&lt;br /&gt;
:::// questionnaire name is not specified&lt;br /&gt;
:::valid = &amp;quot;Please specify quiz name (please do not use your name or id).&amp;quot;&lt;br /&gt;
:::break&lt;br /&gt;
::else&lt;br /&gt;
:::type = params[:question_type][i.to_s][:type]&lt;br /&gt;
:::if type == 'MultipleChoiceCheckbox' or type == 'MultipleChoiceRadio'&lt;br /&gt;
::::correct_selected = false&lt;br /&gt;
::::(1..4).each do |x|&lt;br /&gt;
:::::if params[:new_choices][i.to_s][type][x.to_s][:txt] == ''&lt;br /&gt;
::::::// Text isnt provided for an option&lt;br /&gt;
::::::valid = &amp;quot;Please make sure every question has text for all options&amp;quot;&lt;br /&gt;
::::::break&lt;br /&gt;
:::::elsif type == 'MultipleChoiceRadio' and not params[:new_choices][i.to_s][type][x.to_s][:iscorrect] == nil&lt;br /&gt;
::::::correct_selected = true&lt;br /&gt;
:::::elsif type == 'MultipleChoiceCheckbox' and not params[:new_choices][i.to_s][type][x.to_s][:iscorrect] == 0.to_s&lt;br /&gt;
::::::correct_selected = true&lt;br /&gt;
:::::end&lt;br /&gt;
::::end&lt;br /&gt;
::::if valid == &amp;quot;valid&amp;quot; &amp;amp;&amp;amp; !correct_selected&lt;br /&gt;
:::::// A correct option isnt selected for a check box or radio question&lt;br /&gt;
:::::valid = &amp;quot;Please select a correct answer for all questions&amp;quot;&lt;br /&gt;
::::::break&lt;br /&gt;
::::end&lt;br /&gt;
:::elsif type == 'TF' # TF is not disabled. We need to test TF later.&lt;br /&gt;
::::if params[:new_choices][i.to_s][&amp;quot;TF&amp;quot;] == nil&lt;br /&gt;
:::::// A correct option isnt selected for a true/false question&lt;br /&gt;
:::::valid = &amp;quot;Please select a correct answer for all questions&amp;quot;&lt;br /&gt;
:::::break&lt;br /&gt;
::::end&lt;br /&gt;
:::end&lt;br /&gt;
::end&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:return valid&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Refactoring===&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
def validate_quiz&lt;br /&gt;
:num_quiz_questions = Assignment.find(params[:aid]).num_quiz_questions&lt;br /&gt;
&lt;br /&gt;
:questionnaire = quiz_questionnaire num_quiz_questions&lt;br /&gt;
&lt;br /&gt;
:if questionnaire.valid?&lt;br /&gt;
::return questionnaire&lt;br /&gt;
: end&lt;br /&gt;
&lt;br /&gt;
:questionnaire_errors questionnaire&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
All tests were implemented as part of &amp;lt;code&amp;gt;spec/features/quiz_spec.rb&amp;lt;/code&amp;gt; and thoroughly cover the Use Case, scenarios, and sub flows listed above. A factory file, &amp;lt;code&amp;gt;spec/factories/quiz_factory.rb&amp;lt;/code&amp;gt; was added to aid testing.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1621_Refactor_and_Test_the_Quizzing_Feature&amp;diff=102279</id>
		<title>CSC/ECE 517 Spring 2016 E1621 Refactor and Test the Quizzing Feature</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1621_Refactor_and_Test_the_Quizzing_Feature&amp;diff=102279"/>
		<updated>2016-04-16T15:06:30Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* CSC/ECE 517 Spring 2016 E1621: Refactor and test the quizzing feature */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction to Expertiza =&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt; is a project developed using Ruby on Rails&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/getting_started.html&amp;lt;/ref&amp;gt;. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an [https://en.wikipedia.org/wiki/Open_source open source] application and the code can be cloned from [https://github.com/expertiza/expertiza GitHub]. This application provides an efficient way to manage assignments, grades and reviews.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
The Expertiza quiz feature is in need of refactoring. Currently, quizzes are checked by &amp;lt;code&amp;gt;questionnaires_controller.valid_quiz&amp;lt;/code&amp;gt;. This method is rather long, involved, and does not take advantage of object-oriented practices. It combs through the parameters hash received from a request and manually checks all quiz fields, all question fields, all question choice fields, and verifies that each question has a correct choice.&lt;br /&gt;
&lt;br /&gt;
We will refactor the method to construct a quiz questionniare and then call &amp;lt;code&amp;gt;valid?&amp;lt;/code&amp;gt; to recursively validate the object tree using ActiveRecord validations. This is an improvement over the current code which checks all questions manually. The purpose of refactoring in this manner is to enhance readability, DRYness, and maintainability of Expertiza code.&lt;br /&gt;
&lt;br /&gt;
In addition to this refactoring we will implement integration testing on the quiz feature to verify that the expected behavior is present for all use cases.&lt;br /&gt;
&lt;br /&gt;
A full description of the assignment may be found [https://docs.google.com/document/d/13oRmKemlwRzXG1ItcI2zTx4r3gAAfvmuobZjxiy0oVo/edit#heading=h.su78b3gdq1a7 here]&lt;br /&gt;
&lt;br /&gt;
=Classes involved=&lt;br /&gt;
* questionnaires_controller.rb&lt;br /&gt;
* quiz_quesetionnaire.rb&lt;br /&gt;
* quiz_question.rb&lt;br /&gt;
* quiz_question_choice.rb&lt;br /&gt;
* spec/features/quiz_spec.rb&lt;br /&gt;
&lt;br /&gt;
=Use Case and Scenarios=&lt;br /&gt;
The Quiz Use Case allows for instructors to create and manage assignments where students may write quizzes for reviewers on materials they have submitted. See the following scenarios for a complete description of how the feature is expected to work.&lt;br /&gt;
&lt;br /&gt;
==Instructors are able to create and manage an assignment's quiz feature==&lt;br /&gt;
An instructor chooses to create an assignment that has a quiz [S1]. While editing the assignment they may choose the number of quiz questions [S2] and set which phases students are allowed to take the quizzes [S3].&lt;br /&gt;
&lt;br /&gt;
* [S1] - When creating the assignment there is a checkbox labeled &amp;quot;has quiz.&amp;quot; Checking this box creates an assignment that includes a quiz.&lt;br /&gt;
* [S2] - When an assignment has a quiz there is an input field that accepts the number of questions that will be on each quiz. Setting this number appropriately changes the number of quiz questions.&lt;br /&gt;
* [S3] - Students may not take quizzes on a phase that does not allow them to do so. When on a stage that does allow for quizzes, they may take quizzes on work that they have reviewed.&lt;br /&gt;
&lt;br /&gt;
==Instructors can view quiz questions and scores from the tree view==&lt;br /&gt;
After an assignment has been created the instructor may choose to view student quizzes from the tree view [S1]. While on the quiz view page they see student quizzes [S2] and student responses [S3].&lt;br /&gt;
&lt;br /&gt;
* [S1] - The instructor may navigate to the list of assignments. Assignments with quizzes enabled will provide a link for the instructor to follow and view student quizzes.&lt;br /&gt;
* [S2] - The instructor shall be presented with the quiz title, questions, and answer choices. The correct answer choices will be in bold.&lt;br /&gt;
* [S3] - The score for each student who has taken the quiz shall be listed along with the average quiz score.&lt;br /&gt;
&lt;br /&gt;
==Students can create and edit quizzes==&lt;br /&gt;
A student navigates to the assignment work page and chooses to create a new quiz [S1] or edit an existing one [S2]. By doing so they are able to choose a quiz title  and quiz questions [S3]. Invalid input results in an error message prompting the student to fix the issue [E1].&lt;br /&gt;
&lt;br /&gt;
* [S1] - A student may only create a quiz if they have not yet done so.&lt;br /&gt;
* [S2] - A student may only edit a quiz if they have previously created one.&lt;br /&gt;
* [S3] - The quiz has the number of quiz questions defined by the instructor in the assignment.&lt;br /&gt;
&lt;br /&gt;
* [E1] - Possible errors include:&lt;br /&gt;
** The quiz has no name.&lt;br /&gt;
** One or more questions is missing text.&lt;br /&gt;
** One or more choices is missing text.&lt;br /&gt;
** A question is missing a correct answer choice.&lt;br /&gt;
&lt;br /&gt;
==Students can take quizzes on assignments they have reviewed==&lt;br /&gt;
A student decides to take a quiz [S1] on another team's assignment that they have previously reviewed. They select an artifact for review [S2] and fill in their answers. After submitting the quiz they can view their score on the take quizzes page [S3] and see question-by-question scores by clicking view [S4].&lt;br /&gt;
&lt;br /&gt;
* [S1] - The student may only take a quiz during a stage in which the assignment is configured to allow them to do so.&lt;br /&gt;
* [S2] - Only quizzes from submissions they have reviewed are available.&lt;br /&gt;
* [S3] - The take quizzes page lists the final score for each quiz.&lt;br /&gt;
* [S4] - Choosing to view a quiz will show a student each question along with their answers and the correct answers.&lt;br /&gt;
&lt;br /&gt;
=Design and Implementation=&lt;br /&gt;
Design for the refactoring has been driven by object oriented principles and test-driven-development, and makes use of the existing object hierarchy described in the following UML diagram. &lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza_quiz_hierarchy.png|Expertiza Quiz Hierarchy]]&lt;br /&gt;
&lt;br /&gt;
See the below sections for a part-by-part breakdown of the planned implementation for this project.&lt;br /&gt;
&lt;br /&gt;
==Tests==&lt;br /&gt;
Quiz tests will be added to the file spec/features/quiz_spec.rb and will make use of&lt;br /&gt;
* rspec&lt;br /&gt;
* capybara&lt;br /&gt;
* selenium&lt;br /&gt;
&lt;br /&gt;
Tests will be made which fully cover the expected behavior of each listed scenario in the Use Case.&lt;br /&gt;
&lt;br /&gt;
==Refactoring==&lt;br /&gt;
Each of the following files will be refactored as described.&lt;br /&gt;
&lt;br /&gt;
===QuestionnaireController===&lt;br /&gt;
Refactor the &amp;lt;code&amp;gt;valid_quiz&amp;lt;/code&amp;gt; method. It will be renamed to &amp;lt;code&amp;gt;validate_quiz&amp;lt;/code&amp;gt; to more properly describe the action that occurs as a result of it being called. The behavior will be changed to construct a new quiz questionnaire with submitted questions wich will be validated using &amp;lt;code&amp;gt;quiz.valid?&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===QuizQuestionnaire===&lt;br /&gt;
The following fields will be validated using ActiveRecord validations.&lt;br /&gt;
* Presence of name&lt;br /&gt;
&lt;br /&gt;
===QuizQuestion===&lt;br /&gt;
The following fields will be validated using ActiveRecord validations&lt;br /&gt;
* Presence of text&lt;br /&gt;
* Presence of type&lt;br /&gt;
* Has a correct answer&lt;br /&gt;
&lt;br /&gt;
===QuizQuestionChoice===&lt;br /&gt;
The following fields will be validated using ActiveRecord validations&lt;br /&gt;
* Presence of text&lt;br /&gt;
&lt;br /&gt;
===Test Cases===&lt;br /&gt;
In order to verify that refactoring has been done correctly and maintains the same external behavior, we will write test cases to the existing implementation. These test cases will be the ground truth of the validation feature. Refactored code will not be considered complete until all of these test cases once again pass.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1621_Refactor_and_Test_the_Quizzing_Feature&amp;diff=102278</id>
		<title>CSC/ECE 517 Spring 2016 E1621 Refactor and Test the Quizzing Feature</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016_E1621_Refactor_and_Test_the_Quizzing_Feature&amp;diff=102278"/>
		<updated>2016-04-16T15:06:02Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: Created page with &amp;quot;===CSC/ECE 517 Spring 2016 E1621: Refactor and test the quizzing feature===  = Introduction to Expertiza = Expertiza&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt; is a project...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===CSC/ECE 517 Spring 2016 E1621: Refactor and test the quizzing feature===&lt;br /&gt;
&lt;br /&gt;
= Introduction to Expertiza =&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt; is a project developed using Ruby on Rails&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/getting_started.html&amp;lt;/ref&amp;gt;. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an [https://en.wikipedia.org/wiki/Open_source open source] application and the code can be cloned from [https://github.com/expertiza/expertiza GitHub]. This application provides an efficient way to manage assignments, grades and reviews.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
The Expertiza quiz feature is in need of refactoring. Currently, quizzes are checked by &amp;lt;code&amp;gt;questionnaires_controller.valid_quiz&amp;lt;/code&amp;gt;. This method is rather long, involved, and does not take advantage of object-oriented practices. It combs through the parameters hash received from a request and manually checks all quiz fields, all question fields, all question choice fields, and verifies that each question has a correct choice.&lt;br /&gt;
&lt;br /&gt;
We will refactor the method to construct a quiz questionniare and then call &amp;lt;code&amp;gt;valid?&amp;lt;/code&amp;gt; to recursively validate the object tree using ActiveRecord validations. This is an improvement over the current code which checks all questions manually. The purpose of refactoring in this manner is to enhance readability, DRYness, and maintainability of Expertiza code.&lt;br /&gt;
&lt;br /&gt;
In addition to this refactoring we will implement integration testing on the quiz feature to verify that the expected behavior is present for all use cases.&lt;br /&gt;
&lt;br /&gt;
A full description of the assignment may be found [https://docs.google.com/document/d/13oRmKemlwRzXG1ItcI2zTx4r3gAAfvmuobZjxiy0oVo/edit#heading=h.su78b3gdq1a7 here]&lt;br /&gt;
&lt;br /&gt;
=Classes involved=&lt;br /&gt;
* questionnaires_controller.rb&lt;br /&gt;
* quiz_quesetionnaire.rb&lt;br /&gt;
* quiz_question.rb&lt;br /&gt;
* quiz_question_choice.rb&lt;br /&gt;
* spec/features/quiz_spec.rb&lt;br /&gt;
&lt;br /&gt;
=Use Case and Scenarios=&lt;br /&gt;
The Quiz Use Case allows for instructors to create and manage assignments where students may write quizzes for reviewers on materials they have submitted. See the following scenarios for a complete description of how the feature is expected to work.&lt;br /&gt;
&lt;br /&gt;
==Instructors are able to create and manage an assignment's quiz feature==&lt;br /&gt;
An instructor chooses to create an assignment that has a quiz [S1]. While editing the assignment they may choose the number of quiz questions [S2] and set which phases students are allowed to take the quizzes [S3].&lt;br /&gt;
&lt;br /&gt;
* [S1] - When creating the assignment there is a checkbox labeled &amp;quot;has quiz.&amp;quot; Checking this box creates an assignment that includes a quiz.&lt;br /&gt;
* [S2] - When an assignment has a quiz there is an input field that accepts the number of questions that will be on each quiz. Setting this number appropriately changes the number of quiz questions.&lt;br /&gt;
* [S3] - Students may not take quizzes on a phase that does not allow them to do so. When on a stage that does allow for quizzes, they may take quizzes on work that they have reviewed.&lt;br /&gt;
&lt;br /&gt;
==Instructors can view quiz questions and scores from the tree view==&lt;br /&gt;
After an assignment has been created the instructor may choose to view student quizzes from the tree view [S1]. While on the quiz view page they see student quizzes [S2] and student responses [S3].&lt;br /&gt;
&lt;br /&gt;
* [S1] - The instructor may navigate to the list of assignments. Assignments with quizzes enabled will provide a link for the instructor to follow and view student quizzes.&lt;br /&gt;
* [S2] - The instructor shall be presented with the quiz title, questions, and answer choices. The correct answer choices will be in bold.&lt;br /&gt;
* [S3] - The score for each student who has taken the quiz shall be listed along with the average quiz score.&lt;br /&gt;
&lt;br /&gt;
==Students can create and edit quizzes==&lt;br /&gt;
A student navigates to the assignment work page and chooses to create a new quiz [S1] or edit an existing one [S2]. By doing so they are able to choose a quiz title  and quiz questions [S3]. Invalid input results in an error message prompting the student to fix the issue [E1].&lt;br /&gt;
&lt;br /&gt;
* [S1] - A student may only create a quiz if they have not yet done so.&lt;br /&gt;
* [S2] - A student may only edit a quiz if they have previously created one.&lt;br /&gt;
* [S3] - The quiz has the number of quiz questions defined by the instructor in the assignment.&lt;br /&gt;
&lt;br /&gt;
* [E1] - Possible errors include:&lt;br /&gt;
** The quiz has no name.&lt;br /&gt;
** One or more questions is missing text.&lt;br /&gt;
** One or more choices is missing text.&lt;br /&gt;
** A question is missing a correct answer choice.&lt;br /&gt;
&lt;br /&gt;
==Students can take quizzes on assignments they have reviewed==&lt;br /&gt;
A student decides to take a quiz [S1] on another team's assignment that they have previously reviewed. They select an artifact for review [S2] and fill in their answers. After submitting the quiz they can view their score on the take quizzes page [S3] and see question-by-question scores by clicking view [S4].&lt;br /&gt;
&lt;br /&gt;
* [S1] - The student may only take a quiz during a stage in which the assignment is configured to allow them to do so.&lt;br /&gt;
* [S2] - Only quizzes from submissions they have reviewed are available.&lt;br /&gt;
* [S3] - The take quizzes page lists the final score for each quiz.&lt;br /&gt;
* [S4] - Choosing to view a quiz will show a student each question along with their answers and the correct answers.&lt;br /&gt;
&lt;br /&gt;
=Design and Implementation=&lt;br /&gt;
Design for the refactoring has been driven by object oriented principles and test-driven-development, and makes use of the existing object hierarchy described in the following UML diagram. &lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza_quiz_hierarchy.png|Expertiza Quiz Hierarchy]]&lt;br /&gt;
&lt;br /&gt;
See the below sections for a part-by-part breakdown of the planned implementation for this project.&lt;br /&gt;
&lt;br /&gt;
==Tests==&lt;br /&gt;
Quiz tests will be added to the file spec/features/quiz_spec.rb and will make use of&lt;br /&gt;
* rspec&lt;br /&gt;
* capybara&lt;br /&gt;
* selenium&lt;br /&gt;
&lt;br /&gt;
Tests will be made which fully cover the expected behavior of each listed scenario in the Use Case.&lt;br /&gt;
&lt;br /&gt;
==Refactoring==&lt;br /&gt;
Each of the following files will be refactored as described.&lt;br /&gt;
&lt;br /&gt;
===QuestionnaireController===&lt;br /&gt;
Refactor the &amp;lt;code&amp;gt;valid_quiz&amp;lt;/code&amp;gt; method. It will be renamed to &amp;lt;code&amp;gt;validate_quiz&amp;lt;/code&amp;gt; to more properly describe the action that occurs as a result of it being called. The behavior will be changed to construct a new quiz questionnaire with submitted questions wich will be validated using &amp;lt;code&amp;gt;quiz.valid?&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===QuizQuestionnaire===&lt;br /&gt;
The following fields will be validated using ActiveRecord validations.&lt;br /&gt;
* Presence of name&lt;br /&gt;
&lt;br /&gt;
===QuizQuestion===&lt;br /&gt;
The following fields will be validated using ActiveRecord validations&lt;br /&gt;
* Presence of text&lt;br /&gt;
* Presence of type&lt;br /&gt;
* Has a correct answer&lt;br /&gt;
&lt;br /&gt;
===QuizQuestionChoice===&lt;br /&gt;
The following fields will be validated using ActiveRecord validations&lt;br /&gt;
* Presence of text&lt;br /&gt;
&lt;br /&gt;
===Test Cases===&lt;br /&gt;
In order to verify that refactoring has been done correctly and maintains the same external behavior, we will write test cases to the existing implementation. These test cases will be the ground truth of the validation feature. Refactored code will not be considered complete until all of these test cases once again pass.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=102277</id>
		<title>CSC/ECE 517 Spring 2016</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=102277"/>
		<updated>2016-04-16T15:05:49Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Active Job]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Calibration Assignment Submissions==&lt;br /&gt;
*[[Calibration Assignment Submission (OmniAuth)]]&lt;br /&gt;
*[[Calibration Assignment Submission (Patch_verb)]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Mozilla Implement HTML5 form validation]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE_517_Spring_2016/Mozilla Conforming Image Loading to HTML 5 Specs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Functional Tests for Questionnaire Controller]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 / Expertiza Self-Review Feature]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor different question types from quiz feature]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Implement private browsing]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Write automated tests for WebDriver]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor sign_up_sheet_controller.rb and sign_up_topic.rb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Functional tests for assignment creation function]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/E1604. Functional tests for Calibration function]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor and write unit tests for question type.rb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor response controller]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE_517_Spring_2016_OSS_M1606]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE_517_Spring_2016/OSS_E1601]]&lt;br /&gt;
&lt;br /&gt;
==Final Project Design Document==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 M1601 Implement HTML5 form validation]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 M1602 Make image loads conform with the spec]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 E1624 Compose functional tests for Suggest topics of student functionality ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 E1631 Team-based reviewing]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 E1628 Visualization]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 E1625 Show confidence ratings for grade based on reputations of reviewers]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 E1629 Performance improvement for Course &amp;amp; Assignment Listing]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 M1603 Implement Common Parts of the CSSOM API]]&lt;br /&gt;
*[[M1606: Implementing HTTP authorization UI and persistent sessions]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 E1620 Improve Survey Functionality]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 E1621 Refactor and Test the Quizzing Feature]]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=101474</id>
		<title>CSC/ECE 517 Spring 2016</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=101474"/>
		<updated>2016-03-29T14:02:21Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Writing Assignment 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Active Job]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Calibration Assignment Submissions==&lt;br /&gt;
*[[Calibration Assignment Submission (OmniAuth)]]&lt;br /&gt;
*[[Calibration Assignment Submission (Patch_verb)]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Mozilla Implement HTML5 form validation]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Functional Tests for Questionnaire Controller]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 / Expertiza Self-Review Feature]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor different question types from quiz feature]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Implement private browsing]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Write automated tests for WebDriver]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor sign_up_sheet_controller.rb and sign_up_topic.rb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Functional tests for assignment creation function]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/E1604. Functional tests for Calibration function]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor and write unit tests for question type.rb]]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=101473</id>
		<title>CSC/ECE 517 Spring 2016</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=101473"/>
		<updated>2016-03-29T14:02:09Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Active Job]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Calibration Assignment Submissions==&lt;br /&gt;
*[[Calibration Assignment Submission (OmniAuth)]]&lt;br /&gt;
*[[Calibration Assignment Submission (Patch_verb)]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Mozilla Implement HTML5 form validation]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Functional Tests for Questionnaire Controller]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 / Expertiza Self-Review Feature]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor different question types from quiz feature]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Implement private browsing]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Write automated tests for WebDriver]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor sign_up_sheet_controller.rb and sign_up_topic.rb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API]]&lt;br /&gt;
&lt;br /&gt;
[[CSC/ECE 517 Spring 2016/Functional tests for assignment creation function]]&lt;br /&gt;
&lt;br /&gt;
[[CSC/ECE 517 Spring 2016/E1604. Functional tests for Calibration function]]&lt;br /&gt;
&lt;br /&gt;
[[CSC/ECE 517 Spring 2016/Refactor and write unit tests for question type.rb]]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Active_Job&amp;diff=101472</id>
		<title>CSC/ECE 517 Spring 2016/Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Active_Job&amp;diff=101472"/>
		<updated>2016-03-29T14:01:00Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: Created page with &amp;quot;== '''Introduction''' == Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interfac...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts various queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletters, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is an interface which you can work with common queueing backends. &lt;br /&gt;
The reason to have Active Job in place is to make sure Rails apps can have a job infrastructure. Other existing gems can build on this framework without the limitation of API difference between different job runners such as Delayed Job and Resque. With this feature choosing queueing backends can become an operational concern. Also, switching between those queueing backends without rewrite jobs become possible.&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems[https://en.wikipedia.org/wiki/RubyGems] you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub[https://en.wikipedia.org/wiki/GitHub], as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting to carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and views need to be set in order to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher[https://rubygems.org/gems/mailcatcher/versions/0.6.1] is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''External links'''==&lt;br /&gt;
&lt;br /&gt;
*[http://www.rubyonrails.org/ Ruby on Rails official website] – rubyonrails.org&lt;br /&gt;
*[http://railscasts.com/ Railscasts.com] – (defunct) Short Screencasts that focus on Ruby on Rails technique&lt;br /&gt;
*[http://rubycasts.io/ Rubycasts.io] – Weekly 15 minute screencasts on the whole Ruby/Rails development stack&lt;br /&gt;
*[http://www.railstutorial.org/ The Rails Tutorial] – The Ruby on Rails Tutorial book and screencast series teach you how to develop and deploy Ruby on Rails apps&lt;br /&gt;
*[https://github.com/rails/rails Rails source code]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=101471</id>
		<title>CSC/ECE 517 Spring 2016</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=101471"/>
		<updated>2016-03-29T14:00:45Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: Update on writing assignment 1&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
[[CSC/ECE 517 Spring 2016/Active Job]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Calibration Assignment Submissions==&lt;br /&gt;
*[[Calibration Assignment Submission (OmniAuth)]]&lt;br /&gt;
*[[Calibration Assignment Submission (Patch_verb)]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
[[CSC/ECE 517 Spring 2016/Mozilla Implement HTML5 form validation]]&lt;br /&gt;
&lt;br /&gt;
[[CSC/ECE 517 Spring 2016/Functional Tests for Questionnaire Controller]]&lt;br /&gt;
&lt;br /&gt;
[[CSC/ECE 517 Spring 2016 / Expertiza Self-Review Feature]]&lt;br /&gt;
&lt;br /&gt;
[[CSC/ECE 517 Spring 2016/Refactor different question types from quiz feature]]&lt;br /&gt;
&lt;br /&gt;
[[CSC/ECE 517 Spring 2016/Implement private browsing]]&lt;br /&gt;
&lt;br /&gt;
[[CSC/ECE 517 Spring 2016/Write automated tests for WebDriver]]&lt;br /&gt;
&lt;br /&gt;
[[CSC/ECE 517 Spring 2016/Refactor sign_up_sheet_controller.rb and sign_up_topic.rb]]&lt;br /&gt;
&lt;br /&gt;
[[CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API]]&lt;br /&gt;
&lt;br /&gt;
[[CSC/ECE 517 Spring 2016/Functional tests for assignment creation function]]&lt;br /&gt;
&lt;br /&gt;
[[CSC/ECE 517 Spring 2016/E1604. Functional tests for Calibration function]]&lt;br /&gt;
&lt;br /&gt;
[[CSC/ECE 517 Spring 2016/Refactor and write unit tests for question type.rb]]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ychen71&amp;diff=101445</id>
		<title>User:Ychen71</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ychen71&amp;diff=101445"/>
		<updated>2016-03-28T22:27:31Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: moved User:Ychen71 to Active Job&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Active Job]]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=101444</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=101444"/>
		<updated>2016-03-28T22:27:31Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: moved User:Ychen71 to Active Job&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts various queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletters, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is an interface which you can work with common queueing backends. &lt;br /&gt;
The reason to have Active Job in place is to make sure Rails apps can have a job infrastructure. Other existing gems can build on this framework without the limitation of API difference between different job runners such as Delayed Job and Resque. With this feature choosing queueing backends can become an operational concern. Also, switching between those queueing backends without rewrite jobs become possible.&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems[https://en.wikipedia.org/wiki/RubyGems] you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub[https://en.wikipedia.org/wiki/GitHub], as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting to carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and views need to be set in order to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher[https://rubygems.org/gems/mailcatcher/versions/0.6.1] is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''External links'''==&lt;br /&gt;
&lt;br /&gt;
*[http://www.rubyonrails.org/ Ruby on Rails official website] – rubyonrails.org&lt;br /&gt;
*[http://railscasts.com/ Railscasts.com] – (defunct) Short Screencasts that focus on Ruby on Rails technique&lt;br /&gt;
*[http://rubycasts.io/ Rubycasts.io] – Weekly 15 minute screencasts on the whole Ruby/Rails development stack&lt;br /&gt;
*[http://www.railstutorial.org/ The Rails Tutorial] – The Ruby on Rails Tutorial book and screencast series teach you how to develop and deploy Ruby on Rails apps&lt;br /&gt;
*[https://github.com/rails/rails Rails source code]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=101010</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=101010"/>
		<updated>2016-03-21T22:00:43Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is a suite of functional tests for the assignment calibration function. These tests are designed to provide integration, regression, and acceptance testing by using automation technologies.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
Expertiza has a feature called Calibration that can be turned on for an assignment. When this feature is enabled an expert, typically the instructor, can provide an expert review for the assignment artifacts. After students finish their own reviews they may compare their responses to the expert review. The instructor may also view calibration results to view the scores for the entire class.&lt;br /&gt;
&lt;br /&gt;
While this is a preexisting feature within Expertiza, there currently exist no tests for it. The goal of this project is to fully test the entire flow of the calibration feature using the '''RSpec''' and '''Capybara''' frameworks.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
The moment a line of code is written it becomes legacy code in need of support. Test cases are used not only to ensure that code is operating properly, but also to ensure that it continues to do so after having been modified. An important aspect of this is acceptance testing to verify that the project meets customer requirements. Rather than performing these tests by hand, it is easier to combine an automated testing system like RSpec with a driver like Capybara which allows testing of an application's functionality from the outside by running in a  browser.&lt;br /&gt;
&lt;br /&gt;
===Flow of the calibration function===&lt;br /&gt;
A more detailed description of the calibration may be found [https://docs.google.com/document/d/1LcicJCUY0GHN1qzwRQPL9A1Nv89sVtNtxlADOzVQeBk/edit#heading=h.g4vilf87e3f0 here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in calibration on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on &amp;quot;New public assignment&amp;quot;&lt;br /&gt;
# Input all the information needed, check the “Calibrated peer-review for training?” box, click on Create&lt;br /&gt;
# Select the review rubric in “Rubrics” tab&lt;br /&gt;
# Go to “Due dates” tab, make sure that this assignment is currently in Review phase, also, make the submission allowed in review phase.&lt;br /&gt;
# Add a submitter to the assignment. This submitter will add documents to be reviewed. &lt;br /&gt;
# Go to the list of assignments, click “edit” icon of the assignment&lt;br /&gt;
# Go to the “Calibration” tab, click on the &amp;quot;Begin&amp;quot; link next to the student artifact for the expert review, and click “Submit Review”&lt;br /&gt;
# Go to “Review strategy” tab, select Instructor-Selected as review strategy, then select the radio button “Set number of reviews done by each student” and input the number of reviews&lt;br /&gt;
# Login with valid student username and password who is a reviewer for the assignment&lt;br /&gt;
# Click on the assignment&lt;br /&gt;
# Click on “Other’s work”&lt;br /&gt;
# After clicking “Begin”, Expertiza will display peer-review page&lt;br /&gt;
# Click “Submit Review”&lt;br /&gt;
# Click “Show calibration results” to see expert review&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on the “view review report” to see the calibration report&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
* rspec-rails&lt;br /&gt;
* capybara&lt;br /&gt;
* selenium-webdriver&lt;br /&gt;
* factory_girl_rails&lt;br /&gt;
&lt;br /&gt;
====Rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
====Selenium====&lt;br /&gt;
Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It is the default javascript webdriver for Capybara.&lt;br /&gt;
&lt;br /&gt;
====Factory Girl====&lt;br /&gt;
Factory Girl &amp;lt;ref&amp;gt;[https://github.com/thoughtbot/factory_girl Factory Girl]&amp;lt;/ref&amp;gt; is a factory gem meant for use in testing. It allows for easy and highly configurable on-the-fly model creation that allows tests to request a new instance of a model template and optionally override any of the defaults.&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
The following scenarios were considered when writing tests for the calibration use case:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor creates a calibrated assignment&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to add a new assignment&lt;br /&gt;
:While creating the assignment, the instructor selects to turn calibration on&lt;br /&gt;
:After creating the assignment the instructor sees a calibration tab on the assignment page&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor edits the calibration configuration&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to edit an existing assignment&lt;br /&gt;
:The instructor clicks on the calibration tab and sees it is populated with submitted artifacts&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An expert submits a review for calibration&lt;br /&gt;
:An expert has been added to an assignment to provide the expert review&lt;br /&gt;
:The expert authenticates to Expertiza and begins the expert review&lt;br /&gt;
:The expert finishes and submits the review&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Student Calibration&lt;br /&gt;
:A student has submitted a response for the assignment and it is currently in the review phase&lt;br /&gt;
:The student authenticates to Expertiza and chooses to view calibration for the assignment&lt;br /&gt;
:The student sees their own answers compared to the expert review.&lt;br /&gt;
:Answers that match are marked green, and answers that differ are marked red.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Instructor Calibration&lt;br /&gt;
:It is currently the review phase for an assignment&lt;br /&gt;
:An instructor authenticates to Expertiza and chooses to view calibration&lt;br /&gt;
:The instructor can see the percentages relating to student responses for the assignment&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the tests exists in two locations&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/factories/factories.rb Factory]&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/features/calibration_spec.rb CalibrationSpec]&lt;br /&gt;
&lt;br /&gt;
====Design Pattern====&lt;br /&gt;
We attempted to follow good OO practices by implementing the CRUD&amp;lt;ref&amp;gt;[https://en.wikipedia.org/wiki/Create,_read,_update_and_delete Create Read Update and Delete]&amp;lt;/ref&amp;gt; design pattern using Factory Girl and Capybara.&lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
Our specs follow the standard RSpec describe/it syntax. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
describe 'Some Feature' do&lt;br /&gt;
:before :each do&lt;br /&gt;
&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should do x' do&lt;br /&gt;
::expect(true).to be(true)&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should not do y' do&lt;br /&gt;
::expect(true).to be(false)&lt;br /&gt;
:end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ git clone https://github.com/EricHorton/expertiza&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create and then prepare the test database&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:test:prepare&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/calibration_spec.rb --order default&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:calibration-tests.png|Calibration Tests]]&lt;br /&gt;
 &lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* All test cases are green, which means there are no currently failing tests.&lt;br /&gt;
* Test cases are run through the Selenium driver on Firefox for javascript support. Because they are full acceptance tests they are slower than regular unit tests, but still beat evaluating the feature by hand.&lt;br /&gt;
* Tests are independent and repeatable. Database changes are made within a transaction that is rolled back after tests complete.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/EricHorton/expertiza GitHub Fork]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=101003</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=101003"/>
		<updated>2016-03-21T21:39:27Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Creating the Tests */ Update on design pattern&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is a suite of functional tests for the assignment calibration function. These tests are designed to provide integration, regression, and acceptance testing by using automation technologies.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
Expertiza has a feature called Calibration that can be turned on for an assignment. When this feature is enabled an expert, typically the instructor, can provide an expert review for the assignment artifacts. After students finish their own reviews they may compare their responses to the expert review. The instructor may also view calibration results to view the scores for the entire class.&lt;br /&gt;
&lt;br /&gt;
While this is a preexisting feature within Expertiza, there currently exist no tests for it. The goal of this project is to fully test the entire flow of the calibration feature using the '''RSpec''' and '''Capybara''' frameworks.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
The moment a line of code is written it becomes legacy code in need of support. Test cases are used not only to ensure that code is operating properly, but also to ensure that it continues to do so after having been modified. An important aspect of this is acceptance testing to verify that the project meets customer requirements. Rather than performing these tests by hand, it is easier to combine an automated testing system like RSpec with a driver like Capybara which allows testing of an application's functionality from the outside by running in a  browser.&lt;br /&gt;
&lt;br /&gt;
===Flow of the calibration function===&lt;br /&gt;
A more detailed description of the calibration may be found [https://docs.google.com/document/d/1LcicJCUY0GHN1qzwRQPL9A1Nv89sVtNtxlADOzVQeBk/edit#heading=h.g4vilf87e3f0 here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in calibration on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on &amp;quot;New public assignment&amp;quot;&lt;br /&gt;
# Input all the information needed, check the “Calibrated peer-review for training?” box, click on Create&lt;br /&gt;
# Select the review rubric in “Rubrics” tab&lt;br /&gt;
# Go to “Due dates” tab, make sure that this assignment is currently in Review phase, also, make the submission allowed in review phase.&lt;br /&gt;
# Add a submitter to the assignment. This submitter will add documents to be reviewed. &lt;br /&gt;
# Go to the list of assignments, click “edit” icon of the assignment&lt;br /&gt;
# Go to the “Calibration” tab, click on the &amp;quot;Begin&amp;quot; link next to the student artifact for the expert review, and click “Submit Review”&lt;br /&gt;
# Go to “Review strategy” tab, select Instructor-Selected as review strategy, then select the radio button “Set number of reviews done by each student” and input the number of reviews&lt;br /&gt;
# Login with valid student username and password who is a reviewer for the assignment&lt;br /&gt;
# Click on the assignment&lt;br /&gt;
# Click on “Other’s work”&lt;br /&gt;
# After clicking “Begin”, Expertiza will display peer-review page&lt;br /&gt;
# Click “Submit Review”&lt;br /&gt;
# Click “Show calibration results” to see expert review&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on the “view review report” to see the calibration report&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
* rspec-rails&lt;br /&gt;
* capybara&lt;br /&gt;
* selenium-webdriver&lt;br /&gt;
* factory_girl_rails&lt;br /&gt;
&lt;br /&gt;
====Rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
====Selenium====&lt;br /&gt;
Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It is the default javascript webdriver for Capybara.&lt;br /&gt;
&lt;br /&gt;
====Factory Girl====&lt;br /&gt;
Factory Girl &amp;lt;ref&amp;gt;[https://github.com/thoughtbot/factory_girl]&amp;lt;/ref&amp;gt; is a factory gem meant for use in testing. It allows for easy and highly configurable on-the-fly model creation that allows tests to request a new instance of a model template and optionally override any of the defaults.&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
The following scenarios were considered when writing tests for the calibration use case:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor creates a calibrated assignment&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to add a new assignment&lt;br /&gt;
:While creating the assignment, the instructor selects to turn calibration on&lt;br /&gt;
:After creating the assignment the instructor sees a calibration tab on the assignment page&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor edits the calibration configuration&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to edit an existing assignment&lt;br /&gt;
:The instructor clicks on the calibration tab and sees it is populated with submitted artifacts&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An expert submits a review for calibration&lt;br /&gt;
:An expert has been added to an assignment to provide the expert review&lt;br /&gt;
:The expert authenticates to Expertiza and begins the expert review&lt;br /&gt;
:The expert finishes and submits the review&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Student Calibration&lt;br /&gt;
:A student has submitted a response for the assignment and it is currently in the review phase&lt;br /&gt;
:The student authenticates to Expertiza and chooses to view calibration for the assignment&lt;br /&gt;
:The student sees their own answers compared to the expert review.&lt;br /&gt;
:Answers that match are marked green, and answers that differ are marked red.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Instructor Calibration&lt;br /&gt;
:It is currently the review phase for an assignment&lt;br /&gt;
:An instructor authenticates to Expertiza and chooses to view calibration&lt;br /&gt;
:The instructor can see the percentages relating to student responses for the assignment&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the tests exists in two locations&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/factories/factories.rb Factory]&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/features/calibration_spec.rb CalibrationSpec]&lt;br /&gt;
&lt;br /&gt;
====Design Pattern====&lt;br /&gt;
We attempted to follow good OO practices by implementing the CRUD&amp;lt;ref&amp;gt;[https://en.wikipedia.org/wiki/Create,_read,_update_and_delete]&amp;lt;/ref&amp;gt; design pattern using Factory Girl and Capybara.&lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
Our specs follow the standard RSpec describe/it syntax. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
describe 'Some Feature' do&lt;br /&gt;
:before :each do&lt;br /&gt;
&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should do x' do&lt;br /&gt;
::expect(true).to be(true)&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should not do y' do&lt;br /&gt;
::expect(true).to be(false)&lt;br /&gt;
:end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ git clone https://github.com/EricHorton/expertiza&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create and then prepare the test database&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:test:prepare&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/calibration_spec.rb --order default&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:calibration-tests.png|Calibration Tests]]&lt;br /&gt;
 &lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* All test cases are green, which means there are no currently failing tests.&lt;br /&gt;
* Test cases are run through the Selenium driver on Firefox for javascript support. Because they are full acceptance tests they are slower than regular unit tests, but still beat evaluating the feature by hand.&lt;br /&gt;
* Tests are independent and repeatable. Database changes are made within a transaction that is rolled back after tests complete.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/EricHorton/expertiza GitHub Fork]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=101000</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=101000"/>
		<updated>2016-03-21T21:31:30Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Creating the Tests */ Adding reference to factory girl&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is a suite of functional tests for the assignment calibration function. These tests are designed to provide integration, regression, and acceptance testing by using automation technologies.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
Expertiza has a feature called Calibration that can be turned on for an assignment. When this feature is enabled an expert, typically the instructor, can provide an expert review for the assignment artifacts. After students finish their own reviews they may compare their responses to the expert review. The instructor may also view calibration results to view the scores for the entire class.&lt;br /&gt;
&lt;br /&gt;
While this is a preexisting feature within Expertiza, there currently exist no tests for it. The goal of this project is to fully test the entire flow of the calibration feature using the '''RSpec''' and '''Capybara''' frameworks.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
The moment a line of code is written it becomes legacy code in need of support. Test cases are used not only to ensure that code is operating properly, but also to ensure that it continues to do so after having been modified. An important aspect of this is acceptance testing to verify that the project meets customer requirements. Rather than performing these tests by hand, it is easier to combine an automated testing system like RSpec with a driver like Capybara which allows testing of an application's functionality from the outside by running in a  browser.&lt;br /&gt;
&lt;br /&gt;
===Flow of the calibration function===&lt;br /&gt;
A more detailed description of the calibration may be found [https://docs.google.com/document/d/1LcicJCUY0GHN1qzwRQPL9A1Nv89sVtNtxlADOzVQeBk/edit#heading=h.g4vilf87e3f0 here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in calibration on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on &amp;quot;New public assignment&amp;quot;&lt;br /&gt;
# Input all the information needed, check the “Calibrated peer-review for training?” box, click on Create&lt;br /&gt;
# Select the review rubric in “Rubrics” tab&lt;br /&gt;
# Go to “Due dates” tab, make sure that this assignment is currently in Review phase, also, make the submission allowed in review phase.&lt;br /&gt;
# Add a submitter to the assignment. This submitter will add documents to be reviewed. &lt;br /&gt;
# Go to the list of assignments, click “edit” icon of the assignment&lt;br /&gt;
# Go to the “Calibration” tab, click on the &amp;quot;Begin&amp;quot; link next to the student artifact for the expert review, and click “Submit Review”&lt;br /&gt;
# Go to “Review strategy” tab, select Instructor-Selected as review strategy, then select the radio button “Set number of reviews done by each student” and input the number of reviews&lt;br /&gt;
# Login with valid student username and password who is a reviewer for the assignment&lt;br /&gt;
# Click on the assignment&lt;br /&gt;
# Click on “Other’s work”&lt;br /&gt;
# After clicking “Begin”, Expertiza will display peer-review page&lt;br /&gt;
# Click “Submit Review”&lt;br /&gt;
# Click “Show calibration results” to see expert review&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on the “view review report” to see the calibration report&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
* rspec-rails&lt;br /&gt;
* capybara&lt;br /&gt;
* selenium-webdriver&lt;br /&gt;
* factory_girl_rails&lt;br /&gt;
&lt;br /&gt;
====Rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
====Selenium====&lt;br /&gt;
Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It is the default javascript webdriver for Capybara.&lt;br /&gt;
&lt;br /&gt;
====Factory Girl====&lt;br /&gt;
Factory Girl &amp;lt;ref&amp;gt;[https://github.com/thoughtbot/factory_girl]&amp;lt;/ref&amp;gt; is a factory gem meant for use in testing. It allows for easy and highly configurable on-the-fly model creation that allows tests to request a new instance of a model template and optionally override any of the defaults.&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
The following scenarios were considered when writing tests for the calibration use case:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor creates a calibrated assignment&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to add a new assignment&lt;br /&gt;
:While creating the assignment, the instructor selects to turn calibration on&lt;br /&gt;
:After creating the assignment the instructor sees a calibration tab on the assignment page&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor edits the calibration configuration&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to edit an existing assignment&lt;br /&gt;
:The instructor clicks on the calibration tab and sees it is populated with submitted artifacts&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An expert submits a review for calibration&lt;br /&gt;
:An expert has been added to an assignment to provide the expert review&lt;br /&gt;
:The expert authenticates to Expertiza and begins the expert review&lt;br /&gt;
:The expert finishes and submits the review&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Student Calibration&lt;br /&gt;
:A student has submitted a response for the assignment and it is currently in the review phase&lt;br /&gt;
:The student authenticates to Expertiza and chooses to view calibration for the assignment&lt;br /&gt;
:The student sees their own answers compared to the expert review.&lt;br /&gt;
:Answers that match are marked green, and answers that differ are marked red.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Instructor Calibration&lt;br /&gt;
:It is currently the review phase for an assignment&lt;br /&gt;
:An instructor authenticates to Expertiza and chooses to view calibration&lt;br /&gt;
:The instructor can see the percentages relating to student responses for the assignment&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the tests exists in two locations&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/factories/factories.rb Factory]&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/features/calibration_spec.rb CalibrationSpec]&lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
Our specs follow the standard RSpec describe/it syntax. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
describe 'Some Feature' do&lt;br /&gt;
:before :each do&lt;br /&gt;
&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should do x' do&lt;br /&gt;
::expect(true).to be(true)&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should not do y' do&lt;br /&gt;
::expect(true).to be(false)&lt;br /&gt;
:end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ git clone https://github.com/EricHorton/expertiza&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create and then prepare the test database&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:test:prepare&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/calibration_spec.rb --order default&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:calibration-tests.png|Calibration Tests]]&lt;br /&gt;
 &lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* All test cases are green, which means there are no currently failing tests.&lt;br /&gt;
* Test cases are run through the Selenium driver on Firefox for javascript support. Because they are full acceptance tests they are slower than regular unit tests, but still beat evaluating the feature by hand.&lt;br /&gt;
* Tests are independent and repeatable. Database changes are made within a transaction that is rolled back after tests complete.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/EricHorton/expertiza GitHub Fork]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100998</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100998"/>
		<updated>2016-03-21T21:30:04Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* rspec-rails */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is a suite of functional tests for the assignment calibration function. These tests are designed to provide integration, regression, and acceptance testing by using automation technologies.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
Expertiza has a feature called Calibration that can be turned on for an assignment. When this feature is enabled an expert, typically the instructor, can provide an expert review for the assignment artifacts. After students finish their own reviews they may compare their responses to the expert review. The instructor may also view calibration results to view the scores for the entire class.&lt;br /&gt;
&lt;br /&gt;
While this is a preexisting feature within Expertiza, there currently exist no tests for it. The goal of this project is to fully test the entire flow of the calibration feature using the '''RSpec''' and '''Capybara''' frameworks.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
The moment a line of code is written it becomes legacy code in need of support. Test cases are used not only to ensure that code is operating properly, but also to ensure that it continues to do so after having been modified. An important aspect of this is acceptance testing to verify that the project meets customer requirements. Rather than performing these tests by hand, it is easier to combine an automated testing system like RSpec with a driver like Capybara which allows testing of an application's functionality from the outside by running in a  browser.&lt;br /&gt;
&lt;br /&gt;
===Flow of the calibration function===&lt;br /&gt;
A more detailed description of the calibration may be found [https://docs.google.com/document/d/1LcicJCUY0GHN1qzwRQPL9A1Nv89sVtNtxlADOzVQeBk/edit#heading=h.g4vilf87e3f0 here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in calibration on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on &amp;quot;New public assignment&amp;quot;&lt;br /&gt;
# Input all the information needed, check the “Calibrated peer-review for training?” box, click on Create&lt;br /&gt;
# Select the review rubric in “Rubrics” tab&lt;br /&gt;
# Go to “Due dates” tab, make sure that this assignment is currently in Review phase, also, make the submission allowed in review phase.&lt;br /&gt;
# Add a submitter to the assignment. This submitter will add documents to be reviewed. &lt;br /&gt;
# Go to the list of assignments, click “edit” icon of the assignment&lt;br /&gt;
# Go to the “Calibration” tab, click on the &amp;quot;Begin&amp;quot; link next to the student artifact for the expert review, and click “Submit Review”&lt;br /&gt;
# Go to “Review strategy” tab, select Instructor-Selected as review strategy, then select the radio button “Set number of reviews done by each student” and input the number of reviews&lt;br /&gt;
# Login with valid student username and password who is a reviewer for the assignment&lt;br /&gt;
# Click on the assignment&lt;br /&gt;
# Click on “Other’s work”&lt;br /&gt;
# After clicking “Begin”, Expertiza will display peer-review page&lt;br /&gt;
# Click “Submit Review”&lt;br /&gt;
# Click “Show calibration results” to see expert review&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on the “view review report” to see the calibration report&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
* rspec-rails&lt;br /&gt;
* capybara&lt;br /&gt;
* selenium-webdriver&lt;br /&gt;
* factory_girl_rails&lt;br /&gt;
&lt;br /&gt;
====Rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
====Selenium====&lt;br /&gt;
Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It is the default javascript webdriver for Capybara.&lt;br /&gt;
&lt;br /&gt;
====Factory Girl====&lt;br /&gt;
Factory Girl is a factory gem meant for use in testing. It allows for easy and highly configurable on-the-fly model creation that allows tests to request a new instance of a model template and optionally override any of the defaults.&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
The following scenarios were considered when writing tests for the calibration use case:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor creates a calibrated assignment&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to add a new assignment&lt;br /&gt;
:While creating the assignment, the instructor selects to turn calibration on&lt;br /&gt;
:After creating the assignment the instructor sees a calibration tab on the assignment page&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor edits the calibration configuration&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to edit an existing assignment&lt;br /&gt;
:The instructor clicks on the calibration tab and sees it is populated with submitted artifacts&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An expert submits a review for calibration&lt;br /&gt;
:An expert has been added to an assignment to provide the expert review&lt;br /&gt;
:The expert authenticates to Expertiza and begins the expert review&lt;br /&gt;
:The expert finishes and submits the review&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Student Calibration&lt;br /&gt;
:A student has submitted a response for the assignment and it is currently in the review phase&lt;br /&gt;
:The student authenticates to Expertiza and chooses to view calibration for the assignment&lt;br /&gt;
:The student sees their own answers compared to the expert review.&lt;br /&gt;
:Answers that match are marked green, and answers that differ are marked red.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Instructor Calibration&lt;br /&gt;
:It is currently the review phase for an assignment&lt;br /&gt;
:An instructor authenticates to Expertiza and chooses to view calibration&lt;br /&gt;
:The instructor can see the percentages relating to student responses for the assignment&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the tests exists in two locations&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/factories/factories.rb Factory]&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/features/calibration_spec.rb CalibrationSpec]&lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
Our specs follow the standard RSpec describe/it syntax. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
describe 'Some Feature' do&lt;br /&gt;
:before :each do&lt;br /&gt;
&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should do x' do&lt;br /&gt;
::expect(true).to be(true)&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should not do y' do&lt;br /&gt;
::expect(true).to be(false)&lt;br /&gt;
:end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ git clone https://github.com/EricHorton/expertiza&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create and then prepare the test database&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:test:prepare&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/calibration_spec.rb --order default&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:calibration-tests.png|Calibration Tests]]&lt;br /&gt;
 &lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* All test cases are green, which means there are no currently failing tests.&lt;br /&gt;
* Test cases are run through the Selenium driver on Firefox for javascript support. Because they are full acceptance tests they are slower than regular unit tests, but still beat evaluating the feature by hand.&lt;br /&gt;
* Tests are independent and repeatable. Database changes are made within a transaction that is rolled back after tests complete.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/EricHorton/expertiza GitHub Fork]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100997</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100997"/>
		<updated>2016-03-21T21:29:54Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* capybara */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is a suite of functional tests for the assignment calibration function. These tests are designed to provide integration, regression, and acceptance testing by using automation technologies.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
Expertiza has a feature called Calibration that can be turned on for an assignment. When this feature is enabled an expert, typically the instructor, can provide an expert review for the assignment artifacts. After students finish their own reviews they may compare their responses to the expert review. The instructor may also view calibration results to view the scores for the entire class.&lt;br /&gt;
&lt;br /&gt;
While this is a preexisting feature within Expertiza, there currently exist no tests for it. The goal of this project is to fully test the entire flow of the calibration feature using the '''RSpec''' and '''Capybara''' frameworks.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
The moment a line of code is written it becomes legacy code in need of support. Test cases are used not only to ensure that code is operating properly, but also to ensure that it continues to do so after having been modified. An important aspect of this is acceptance testing to verify that the project meets customer requirements. Rather than performing these tests by hand, it is easier to combine an automated testing system like RSpec with a driver like Capybara which allows testing of an application's functionality from the outside by running in a  browser.&lt;br /&gt;
&lt;br /&gt;
===Flow of the calibration function===&lt;br /&gt;
A more detailed description of the calibration may be found [https://docs.google.com/document/d/1LcicJCUY0GHN1qzwRQPL9A1Nv89sVtNtxlADOzVQeBk/edit#heading=h.g4vilf87e3f0 here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in calibration on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on &amp;quot;New public assignment&amp;quot;&lt;br /&gt;
# Input all the information needed, check the “Calibrated peer-review for training?” box, click on Create&lt;br /&gt;
# Select the review rubric in “Rubrics” tab&lt;br /&gt;
# Go to “Due dates” tab, make sure that this assignment is currently in Review phase, also, make the submission allowed in review phase.&lt;br /&gt;
# Add a submitter to the assignment. This submitter will add documents to be reviewed. &lt;br /&gt;
# Go to the list of assignments, click “edit” icon of the assignment&lt;br /&gt;
# Go to the “Calibration” tab, click on the &amp;quot;Begin&amp;quot; link next to the student artifact for the expert review, and click “Submit Review”&lt;br /&gt;
# Go to “Review strategy” tab, select Instructor-Selected as review strategy, then select the radio button “Set number of reviews done by each student” and input the number of reviews&lt;br /&gt;
# Login with valid student username and password who is a reviewer for the assignment&lt;br /&gt;
# Click on the assignment&lt;br /&gt;
# Click on “Other’s work”&lt;br /&gt;
# After clicking “Begin”, Expertiza will display peer-review page&lt;br /&gt;
# Click “Submit Review”&lt;br /&gt;
# Click “Show calibration results” to see expert review&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on the “view review report” to see the calibration report&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
* rspec-rails&lt;br /&gt;
* capybara&lt;br /&gt;
* selenium-webdriver&lt;br /&gt;
* factory_girl_rails&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
====Selenium====&lt;br /&gt;
Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It is the default javascript webdriver for Capybara.&lt;br /&gt;
&lt;br /&gt;
====Factory Girl====&lt;br /&gt;
Factory Girl is a factory gem meant for use in testing. It allows for easy and highly configurable on-the-fly model creation that allows tests to request a new instance of a model template and optionally override any of the defaults.&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
The following scenarios were considered when writing tests for the calibration use case:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor creates a calibrated assignment&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to add a new assignment&lt;br /&gt;
:While creating the assignment, the instructor selects to turn calibration on&lt;br /&gt;
:After creating the assignment the instructor sees a calibration tab on the assignment page&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor edits the calibration configuration&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to edit an existing assignment&lt;br /&gt;
:The instructor clicks on the calibration tab and sees it is populated with submitted artifacts&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An expert submits a review for calibration&lt;br /&gt;
:An expert has been added to an assignment to provide the expert review&lt;br /&gt;
:The expert authenticates to Expertiza and begins the expert review&lt;br /&gt;
:The expert finishes and submits the review&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Student Calibration&lt;br /&gt;
:A student has submitted a response for the assignment and it is currently in the review phase&lt;br /&gt;
:The student authenticates to Expertiza and chooses to view calibration for the assignment&lt;br /&gt;
:The student sees their own answers compared to the expert review.&lt;br /&gt;
:Answers that match are marked green, and answers that differ are marked red.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Instructor Calibration&lt;br /&gt;
:It is currently the review phase for an assignment&lt;br /&gt;
:An instructor authenticates to Expertiza and chooses to view calibration&lt;br /&gt;
:The instructor can see the percentages relating to student responses for the assignment&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the tests exists in two locations&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/factories/factories.rb Factory]&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/features/calibration_spec.rb CalibrationSpec]&lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
Our specs follow the standard RSpec describe/it syntax. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
describe 'Some Feature' do&lt;br /&gt;
:before :each do&lt;br /&gt;
&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should do x' do&lt;br /&gt;
::expect(true).to be(true)&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should not do y' do&lt;br /&gt;
::expect(true).to be(false)&lt;br /&gt;
:end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ git clone https://github.com/EricHorton/expertiza&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create and then prepare the test database&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:test:prepare&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/calibration_spec.rb --order default&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:calibration-tests.png|Calibration Tests]]&lt;br /&gt;
 &lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* All test cases are green, which means there are no currently failing tests.&lt;br /&gt;
* Test cases are run through the Selenium driver on Firefox for javascript support. Because they are full acceptance tests they are slower than regular unit tests, but still beat evaluating the feature by hand.&lt;br /&gt;
* Tests are independent and repeatable. Database changes are made within a transaction that is rolled back after tests complete.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/EricHorton/expertiza GitHub Fork]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100996</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100996"/>
		<updated>2016-03-21T21:29:46Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* factory girl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is a suite of functional tests for the assignment calibration function. These tests are designed to provide integration, regression, and acceptance testing by using automation technologies.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
Expertiza has a feature called Calibration that can be turned on for an assignment. When this feature is enabled an expert, typically the instructor, can provide an expert review for the assignment artifacts. After students finish their own reviews they may compare their responses to the expert review. The instructor may also view calibration results to view the scores for the entire class.&lt;br /&gt;
&lt;br /&gt;
While this is a preexisting feature within Expertiza, there currently exist no tests for it. The goal of this project is to fully test the entire flow of the calibration feature using the '''RSpec''' and '''Capybara''' frameworks.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
The moment a line of code is written it becomes legacy code in need of support. Test cases are used not only to ensure that code is operating properly, but also to ensure that it continues to do so after having been modified. An important aspect of this is acceptance testing to verify that the project meets customer requirements. Rather than performing these tests by hand, it is easier to combine an automated testing system like RSpec with a driver like Capybara which allows testing of an application's functionality from the outside by running in a  browser.&lt;br /&gt;
&lt;br /&gt;
===Flow of the calibration function===&lt;br /&gt;
A more detailed description of the calibration may be found [https://docs.google.com/document/d/1LcicJCUY0GHN1qzwRQPL9A1Nv89sVtNtxlADOzVQeBk/edit#heading=h.g4vilf87e3f0 here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in calibration on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on &amp;quot;New public assignment&amp;quot;&lt;br /&gt;
# Input all the information needed, check the “Calibrated peer-review for training?” box, click on Create&lt;br /&gt;
# Select the review rubric in “Rubrics” tab&lt;br /&gt;
# Go to “Due dates” tab, make sure that this assignment is currently in Review phase, also, make the submission allowed in review phase.&lt;br /&gt;
# Add a submitter to the assignment. This submitter will add documents to be reviewed. &lt;br /&gt;
# Go to the list of assignments, click “edit” icon of the assignment&lt;br /&gt;
# Go to the “Calibration” tab, click on the &amp;quot;Begin&amp;quot; link next to the student artifact for the expert review, and click “Submit Review”&lt;br /&gt;
# Go to “Review strategy” tab, select Instructor-Selected as review strategy, then select the radio button “Set number of reviews done by each student” and input the number of reviews&lt;br /&gt;
# Login with valid student username and password who is a reviewer for the assignment&lt;br /&gt;
# Click on the assignment&lt;br /&gt;
# Click on “Other’s work”&lt;br /&gt;
# After clicking “Begin”, Expertiza will display peer-review page&lt;br /&gt;
# Click “Submit Review”&lt;br /&gt;
# Click “Show calibration results” to see expert review&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on the “view review report” to see the calibration report&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
* rspec-rails&lt;br /&gt;
* capybara&lt;br /&gt;
* selenium-webdriver&lt;br /&gt;
* factory_girl_rails&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
====Selenium====&lt;br /&gt;
Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It is the default javascript webdriver for Capybara.&lt;br /&gt;
&lt;br /&gt;
====Factory Girl====&lt;br /&gt;
Factory Girl is a factory gem meant for use in testing. It allows for easy and highly configurable on-the-fly model creation that allows tests to request a new instance of a model template and optionally override any of the defaults.&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
The following scenarios were considered when writing tests for the calibration use case:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor creates a calibrated assignment&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to add a new assignment&lt;br /&gt;
:While creating the assignment, the instructor selects to turn calibration on&lt;br /&gt;
:After creating the assignment the instructor sees a calibration tab on the assignment page&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor edits the calibration configuration&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to edit an existing assignment&lt;br /&gt;
:The instructor clicks on the calibration tab and sees it is populated with submitted artifacts&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An expert submits a review for calibration&lt;br /&gt;
:An expert has been added to an assignment to provide the expert review&lt;br /&gt;
:The expert authenticates to Expertiza and begins the expert review&lt;br /&gt;
:The expert finishes and submits the review&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Student Calibration&lt;br /&gt;
:A student has submitted a response for the assignment and it is currently in the review phase&lt;br /&gt;
:The student authenticates to Expertiza and chooses to view calibration for the assignment&lt;br /&gt;
:The student sees their own answers compared to the expert review.&lt;br /&gt;
:Answers that match are marked green, and answers that differ are marked red.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Instructor Calibration&lt;br /&gt;
:It is currently the review phase for an assignment&lt;br /&gt;
:An instructor authenticates to Expertiza and chooses to view calibration&lt;br /&gt;
:The instructor can see the percentages relating to student responses for the assignment&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the tests exists in two locations&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/factories/factories.rb Factory]&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/features/calibration_spec.rb CalibrationSpec]&lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
Our specs follow the standard RSpec describe/it syntax. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
describe 'Some Feature' do&lt;br /&gt;
:before :each do&lt;br /&gt;
&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should do x' do&lt;br /&gt;
::expect(true).to be(true)&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should not do y' do&lt;br /&gt;
::expect(true).to be(false)&lt;br /&gt;
:end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ git clone https://github.com/EricHorton/expertiza&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create and then prepare the test database&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:test:prepare&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/calibration_spec.rb --order default&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:calibration-tests.png|Calibration Tests]]&lt;br /&gt;
 &lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* All test cases are green, which means there are no currently failing tests.&lt;br /&gt;
* Test cases are run through the Selenium driver on Firefox for javascript support. Because they are full acceptance tests they are slower than regular unit tests, but still beat evaluating the feature by hand.&lt;br /&gt;
* Tests are independent and repeatable. Database changes are made within a transaction that is rolled back after tests complete.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/EricHorton/expertiza GitHub Fork]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100995</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100995"/>
		<updated>2016-03-21T21:29:33Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* selenium */ Update on title&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is a suite of functional tests for the assignment calibration function. These tests are designed to provide integration, regression, and acceptance testing by using automation technologies.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
Expertiza has a feature called Calibration that can be turned on for an assignment. When this feature is enabled an expert, typically the instructor, can provide an expert review for the assignment artifacts. After students finish their own reviews they may compare their responses to the expert review. The instructor may also view calibration results to view the scores for the entire class.&lt;br /&gt;
&lt;br /&gt;
While this is a preexisting feature within Expertiza, there currently exist no tests for it. The goal of this project is to fully test the entire flow of the calibration feature using the '''RSpec''' and '''Capybara''' frameworks.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
The moment a line of code is written it becomes legacy code in need of support. Test cases are used not only to ensure that code is operating properly, but also to ensure that it continues to do so after having been modified. An important aspect of this is acceptance testing to verify that the project meets customer requirements. Rather than performing these tests by hand, it is easier to combine an automated testing system like RSpec with a driver like Capybara which allows testing of an application's functionality from the outside by running in a  browser.&lt;br /&gt;
&lt;br /&gt;
===Flow of the calibration function===&lt;br /&gt;
A more detailed description of the calibration may be found [https://docs.google.com/document/d/1LcicJCUY0GHN1qzwRQPL9A1Nv89sVtNtxlADOzVQeBk/edit#heading=h.g4vilf87e3f0 here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in calibration on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on &amp;quot;New public assignment&amp;quot;&lt;br /&gt;
# Input all the information needed, check the “Calibrated peer-review for training?” box, click on Create&lt;br /&gt;
# Select the review rubric in “Rubrics” tab&lt;br /&gt;
# Go to “Due dates” tab, make sure that this assignment is currently in Review phase, also, make the submission allowed in review phase.&lt;br /&gt;
# Add a submitter to the assignment. This submitter will add documents to be reviewed. &lt;br /&gt;
# Go to the list of assignments, click “edit” icon of the assignment&lt;br /&gt;
# Go to the “Calibration” tab, click on the &amp;quot;Begin&amp;quot; link next to the student artifact for the expert review, and click “Submit Review”&lt;br /&gt;
# Go to “Review strategy” tab, select Instructor-Selected as review strategy, then select the radio button “Set number of reviews done by each student” and input the number of reviews&lt;br /&gt;
# Login with valid student username and password who is a reviewer for the assignment&lt;br /&gt;
# Click on the assignment&lt;br /&gt;
# Click on “Other’s work”&lt;br /&gt;
# After clicking “Begin”, Expertiza will display peer-review page&lt;br /&gt;
# Click “Submit Review”&lt;br /&gt;
# Click “Show calibration results” to see expert review&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on the “view review report” to see the calibration report&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
* rspec-rails&lt;br /&gt;
* capybara&lt;br /&gt;
* selenium-webdriver&lt;br /&gt;
* factory_girl_rails&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
====Selenium====&lt;br /&gt;
Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It is the default javascript webdriver for Capybara.&lt;br /&gt;
&lt;br /&gt;
====factory girl====&lt;br /&gt;
Factory Girl is a factory gem meant for use in testing. It allows for easy and highly configurable on-the-fly model creation that allows tests to request a new instance of a model template and optionally override any of the defaults.&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
The following scenarios were considered when writing tests for the calibration use case:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor creates a calibrated assignment&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to add a new assignment&lt;br /&gt;
:While creating the assignment, the instructor selects to turn calibration on&lt;br /&gt;
:After creating the assignment the instructor sees a calibration tab on the assignment page&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor edits the calibration configuration&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to edit an existing assignment&lt;br /&gt;
:The instructor clicks on the calibration tab and sees it is populated with submitted artifacts&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An expert submits a review for calibration&lt;br /&gt;
:An expert has been added to an assignment to provide the expert review&lt;br /&gt;
:The expert authenticates to Expertiza and begins the expert review&lt;br /&gt;
:The expert finishes and submits the review&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Student Calibration&lt;br /&gt;
:A student has submitted a response for the assignment and it is currently in the review phase&lt;br /&gt;
:The student authenticates to Expertiza and chooses to view calibration for the assignment&lt;br /&gt;
:The student sees their own answers compared to the expert review.&lt;br /&gt;
:Answers that match are marked green, and answers that differ are marked red.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Instructor Calibration&lt;br /&gt;
:It is currently the review phase for an assignment&lt;br /&gt;
:An instructor authenticates to Expertiza and chooses to view calibration&lt;br /&gt;
:The instructor can see the percentages relating to student responses for the assignment&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the tests exists in two locations&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/factories/factories.rb Factory]&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/features/calibration_spec.rb CalibrationSpec]&lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
Our specs follow the standard RSpec describe/it syntax. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
describe 'Some Feature' do&lt;br /&gt;
:before :each do&lt;br /&gt;
&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should do x' do&lt;br /&gt;
::expect(true).to be(true)&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should not do y' do&lt;br /&gt;
::expect(true).to be(false)&lt;br /&gt;
:end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ git clone https://github.com/EricHorton/expertiza&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create and then prepare the test database&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:test:prepare&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/calibration_spec.rb --order default&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:calibration-tests.png|Calibration Tests]]&lt;br /&gt;
 &lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* All test cases are green, which means there are no currently failing tests.&lt;br /&gt;
* Test cases are run through the Selenium driver on Firefox for javascript support. Because they are full acceptance tests they are slower than regular unit tests, but still beat evaluating the feature by hand.&lt;br /&gt;
* Tests are independent and repeatable. Database changes are made within a transaction that is rolled back after tests complete.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/EricHorton/expertiza GitHub Fork]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100976</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100976"/>
		<updated>2016-03-21T14:39:24Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Running  the tests */ update on running test on default order&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is a suite of functional tests for the assignment calibration function. These tests are designed to provide integration, regression, and acceptance testing by using automation technologies.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
Expertiza has a feature called Calibration that can be turned on for an assignment. When this feature is enabled an expert, typically the instructor, can provide an expert review for the assignment artifacts. After students finish their own reviews they may compare their responses to the expert review. The instructor may also view calibration results to view the scores for the entire class.&lt;br /&gt;
&lt;br /&gt;
While this is a preexisting feature within Expertiza, there currently exist no tests for it. The goal of this project is to fully test the entire flow of the calibration feature using the '''RSpec''' and '''Capybara''' frameworks.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
The moment a line of code is written it becomes legacy code in need of support. Test cases are used not only to ensure that code is operating properly, but also to ensure that it continues to do so after having been modified. An important aspect of this is acceptance testing to verify that the project meets customer requirements. Rather than performing these tests by hand, it is easier to combine an automated testing system like RSpec with a driver like Capybara which allows testing of an application's functionality from the outside by running in a  browser.&lt;br /&gt;
&lt;br /&gt;
===Flow of the calibration function===&lt;br /&gt;
A more detailed description of the calibration may be found [https://docs.google.com/document/d/1LcicJCUY0GHN1qzwRQPL9A1Nv89sVtNtxlADOzVQeBk/edit#heading=h.g4vilf87e3f0 here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in calibration on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on &amp;quot;New public assignment&amp;quot;&lt;br /&gt;
# Input all the information needed, check the “Calibrated peer-review for training?” box, click on Create&lt;br /&gt;
# Select the review rubric in “Rubrics” tab&lt;br /&gt;
# Go to “Due dates” tab, make sure that this assignment is currently in Review phase, also, make the submission allowed in review phase.&lt;br /&gt;
# Add a submitter to the assignment. This submitter will add documents to be reviewed. &lt;br /&gt;
# Go to the list of assignments, click “edit” icon of the assignment&lt;br /&gt;
# Go to the “Calibration” tab, click on the &amp;quot;Begin&amp;quot; link next to the student artifact for the expert review, and click “Submit Review”&lt;br /&gt;
# Go to “Review strategy” tab, select Instructor-Selected as review strategy, then select the radio button “Set number of reviews done by each student” and input the number of reviews&lt;br /&gt;
# Login with valid student username and password who is a reviewer for the assignment&lt;br /&gt;
# Click on the assignment&lt;br /&gt;
# Click on “Other’s work”&lt;br /&gt;
# After clicking “Begin”, Expertiza will display peer-review page&lt;br /&gt;
# Click “Submit Review”&lt;br /&gt;
# Click “Show calibration results” to see expert review&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on the “view review report” to see the calibration report&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
* rspec-rails&lt;br /&gt;
* capybara&lt;br /&gt;
* selenium-webdriver&lt;br /&gt;
* factory_girl_rails&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
====selenium====&lt;br /&gt;
Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It is the default javascript webdriver for Capybara.&lt;br /&gt;
&lt;br /&gt;
====factory girl====&lt;br /&gt;
Factory Girl is a factory gem meant for use in testing. It allows for easy and highly configurable on-the-fly model creation that allows tests to request a new instance of a model template and optionally override any of the defaults.&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
The following scenarios were considered when writing tests for the calibration use case:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor creates a calibrated assignment&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to add a new assignment&lt;br /&gt;
:While creating the assignment, the instructor selects to turn calibration on&lt;br /&gt;
:After creating the assignment the instructor sees a calibration tab on the assignment page&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An instructor edits the calibration configuration&lt;br /&gt;
:An instructor authenticates to expertiza&lt;br /&gt;
:They select to edit an existing assignment&lt;br /&gt;
:The instructor clicks on the calibration tab and sees it is populated with submitted artifacts&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
An expert submits a review for calibration&lt;br /&gt;
:An expert has been added to an assignment to provide the expert review&lt;br /&gt;
:The expert authenticates to Expertiza and begins the expert review&lt;br /&gt;
:The expert finishes and submits the review&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Student Calibration&lt;br /&gt;
:A student has submitted a response for the assignment and it is currently in the review phase&lt;br /&gt;
:The student authenticates to Expertiza and chooses to view calibration for the assignment&lt;br /&gt;
:The student sees their own answers compared to the expert review.&lt;br /&gt;
:Answers that match are marked green, and answers that differ are marked red.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Instructor Calibration&lt;br /&gt;
:It is currently the review phase for an assignment&lt;br /&gt;
:An instructor authenticates to Expertiza and chooses to view calibration&lt;br /&gt;
:The instructor can see the percentages relating to student responses for the assignment&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the tests exists in two locations&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/factories/factories.rb Factory]&lt;br /&gt;
* [https://github.com/EricHorton/expertiza/blob/master/spec/features/calibration_spec.rb CalibrationSpec]&lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
Our specs follow the standard RSpec describe/it syntax. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
describe 'Some Feature' do&lt;br /&gt;
:before :each do&lt;br /&gt;
&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should do x' do&lt;br /&gt;
::expect(true).to be(true)&lt;br /&gt;
:end&lt;br /&gt;
&lt;br /&gt;
:it 'should not do y' do&lt;br /&gt;
::expect(true).to be(false)&lt;br /&gt;
:end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ git clone https://github.com/EricHorton/expertiza&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create and then prepare the test database&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:test:prepare&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/calibration_spec.rb --order default&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:calibration-tests.png|Calibration Tests]]&lt;br /&gt;
 &lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* All test cases are green, which means there are no currently failing tests.&lt;br /&gt;
* Test cases are run through the Selenium driver on Firefox for javascript support. Because they are full acceptance tests they are slower than regular unit tests, but still beat evaluating the feature by hand.&lt;br /&gt;
* Tests are independent and repeatable. Database changes are made within a transaction that is rolled back after tests complete.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/EricHorton/expertiza GitHub Fork]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100960</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100960"/>
		<updated>2016-03-18T23:59:45Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Flow of the calibration function */ Update on calibration function testing procedure&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is to Functional tests for Calibration function. &lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The instructor does expert reviews first, then after students review calibration assignments and submit peer review results, they can check the expert review. Instructor can check &amp;quot;calibration results&amp;quot; to check the calibration results of the whole class. Currently, there is no feature test for calibration function. The goal is to understand the flow of the calibration function by mock this flow in the '''Feature Tests''' using '''RSpec''' and '''Capybara''' framework.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the functionality from users perspective. '''Feature spec''' allows testing of your application's functionality from the outside either by simulating a browser or by headless browser simulation. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.&lt;br /&gt;
&lt;br /&gt;
===Flow of the calibration function===&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in assignment submission by student on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on &amp;quot;New public assignment&amp;quot;&lt;br /&gt;
# Input all the information needed, check the “Calibrated peer-review for training?” box, click on Create&lt;br /&gt;
# Select the review rubric in “Rubrics” tab&lt;br /&gt;
# Go to “Due dates” tab, make sure that this assignment is currently in Review phase, also, make the submission allowed in review phase. &lt;br /&gt;
# Go to the list of assignments, click “edit” icon of the assignment&lt;br /&gt;
# Go to the “Calibration” tab, click on the &amp;quot;Begin&amp;quot; link next to the student artifact for the expert review, and click “Submit Review”&lt;br /&gt;
# Go to “Review strategy” tab, select Instructor-Selected as review strategy, then select the radio button “Set number of reviews done by each student” and input the number of reviews&lt;br /&gt;
# Login with valid student username and password who is a reviewer for the assignment&lt;br /&gt;
# Click on the assignment&lt;br /&gt;
# Click on“Other’s work”&lt;br /&gt;
# After clicking “Begin”, Expertiza will display peer-review page&lt;br /&gt;
# Click “Submit Review”&lt;br /&gt;
# Click “Show calibration results” to see expert review&lt;br /&gt;
# Login with valid instructor username and password&lt;br /&gt;
# Click on &amp;quot;Assignment&amp;quot;&lt;br /&gt;
# Click on the “view review report” to see the calibration report&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
The gems used in feature testing are '''rspec-rails''', '''capybara''' and '''selenium'''.&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====selenium====&lt;br /&gt;
Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It is the default javascript webdriver for Capybara.&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
Based on the steps involved in manual submission of the assignment, the following test scenarios are considered:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to login&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have text content &amp;lt;b&amp;gt;Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to submit valid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit invalid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;http://&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should display flash message with text &amp;lt;b&amp;gt;URI is not valid&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit valid link to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Page should not have &amp;lt;b&amp;gt;Upload link&amp;lt;/b&amp;gt; button&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able upload file to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the feature test consist in two files:&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/assignment_setup.rb assignment_setup.rb] which contains method for creating assignments using controller calls.&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/features/student_submission_spec.rb student_assignment_submission.rb] which contain calls to assignment_setup, scenarios to test assignment submission and commands to delete the created assignments. &lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;require&amp;lt;/b&amp;gt; files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RSpec.feature 'assignment submission when student' do&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::create assignments for submission&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:each) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::capybara steps to login&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;after(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::delete assignments created&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;scenario 'submits only valid link to ongoing assignment' do&amp;lt;/b&amp;gt;&lt;br /&gt;
::mock steps using capybara&lt;br /&gt;
::make assertions&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sample Scenario====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
require 'assignment_setup'&lt;br /&gt;
&lt;br /&gt;
RSpec.feature 'assignment submission when student' do&lt;br /&gt;
&lt;br /&gt;
  active_assignment=&amp;quot;FeatureTest&amp;quot;&lt;br /&gt;
  expired_assignment=&amp;quot;LibraryRailsApp&amp;quot;&lt;br /&gt;
  d = Date.parse(Time.now.to_s)&lt;br /&gt;
  due_date1=(d &amp;gt;&amp;gt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
  due_date2=(d &amp;lt;&amp;lt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  # Before all block runs once before all the scenarios are tested&lt;br /&gt;
  before(:all) do&lt;br /&gt;
    # Create active/ongoing assignment&lt;br /&gt;
    create_assignment(active_assignment, due_date1)&lt;br /&gt;
&lt;br /&gt;
    # Create expired/finished assignment&lt;br /&gt;
    create_assignment(expired_assignment, due_date2)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Before each block runs before every scenario&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    # Login as a student before each scenario&lt;br /&gt;
    visit root_path&lt;br /&gt;
    fill_in 'User Name', :with =&amp;gt; 'student13'&lt;br /&gt;
    fill_in 'Password', :with =&amp;gt; 'password'&lt;br /&gt;
    click_on 'SIGN IN'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # After all block runs after all the scenarios are tested&lt;br /&gt;
  after(:all)do&lt;br /&gt;
    # Delete active/ongoing assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(active_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
&lt;br /&gt;
    # Delete expired/finished assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(expired_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Scenario to check whether student is able to submit valid link to an ongoing assignment&lt;br /&gt;
  scenario 'submits only valid link to ongoing assignment' do&lt;br /&gt;
    click_on active_assignment&lt;br /&gt;
    click_on 'Your work'&lt;br /&gt;
    fill_in 'submission', :with =&amp;gt; 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
    click_on 'Upload link'&lt;br /&gt;
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ mkdir review&lt;br /&gt;
$ cd review&lt;br /&gt;
$ git clone https://github.com/shrenujgandhi/expertiza.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case you don't have a database with student and instructor entries then download the dump from https://drive.google.com/a/ncsu.edu/file/d/0B2vDvVjH76uESEkzSWpJRnhGbmc/view. Extract its contents.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:create:all&lt;br /&gt;
$ cd Downloads/&lt;br /&gt;
$ mysql -u root -p expertiza_development &amp;lt; expertiza_scrubbed_2015_08_14.sql&lt;br /&gt;
password:&lt;br /&gt;
&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:migrate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/student_submission_spec.rb &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:test_result_temp2_expertiza.jpg|Feature Test Result]]&lt;br /&gt;
&lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* ''7 examples, 0 failures'' imply that there are 7 test scenarios and none of them failed.&lt;br /&gt;
* The tests take around 35 seconds to run, which implies that they are fast.&lt;br /&gt;
* They are also repeatable as the assignments that are created in the ''before all'' block are also deleted in the ''after all'' block.&lt;br /&gt;
* They are also self-verifying as all the results are in green, which mean that all the cases passed.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/shrenujgandhi/expertiza GitHub Link]&lt;br /&gt;
# [https://youtu.be/_58l0VPy04M YouTube Demo]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100959</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100959"/>
		<updated>2016-03-18T23:48:21Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* selenium */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is to Functional tests for Calibration function. &lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The instructor does expert reviews first, then after students review calibration assignments and submit peer review results, they can check the expert review. Instructor can check &amp;quot;calibration results&amp;quot; to check the calibration results of the whole class. Currently, there is no feature test for calibration function. The goal is to understand the flow of the calibration function by mock this flow in the '''Feature Tests''' using '''RSpec''' and '''Capybara''' framework.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the functionality from users perspective. '''Feature spec''' allows testing of your application's functionality from the outside either by simulating a browser or by headless browser simulation. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.&lt;br /&gt;
&lt;br /&gt;
===Flow of the calibration function===&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in assignment submission by student on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid student username and password&lt;br /&gt;
# Click on an assignment to submit&lt;br /&gt;
# Click on &amp;quot;Your Work&amp;quot;&lt;br /&gt;
# Paste the link or browse to the file containing your work&lt;br /&gt;
# Click on &amp;quot;Upload Link&amp;quot; or &amp;quot;Upload File&amp;quot; to submit deliverable&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
The gems used in feature testing are '''rspec-rails''', '''capybara''' and '''selenium'''.&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====selenium====&lt;br /&gt;
Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It is the default javascript webdriver for Capybara.&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
Based on the steps involved in manual submission of the assignment, the following test scenarios are considered:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to login&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have text content &amp;lt;b&amp;gt;Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to submit valid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit invalid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;http://&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should display flash message with text &amp;lt;b&amp;gt;URI is not valid&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit valid link to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Page should not have &amp;lt;b&amp;gt;Upload link&amp;lt;/b&amp;gt; button&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able upload file to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the feature test consist in two files:&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/assignment_setup.rb assignment_setup.rb] which contains method for creating assignments using controller calls.&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/features/student_submission_spec.rb student_assignment_submission.rb] which contain calls to assignment_setup, scenarios to test assignment submission and commands to delete the created assignments. &lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;require&amp;lt;/b&amp;gt; files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RSpec.feature 'assignment submission when student' do&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::create assignments for submission&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:each) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::capybara steps to login&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;after(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::delete assignments created&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;scenario 'submits only valid link to ongoing assignment' do&amp;lt;/b&amp;gt;&lt;br /&gt;
::mock steps using capybara&lt;br /&gt;
::make assertions&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sample Scenario====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
require 'assignment_setup'&lt;br /&gt;
&lt;br /&gt;
RSpec.feature 'assignment submission when student' do&lt;br /&gt;
&lt;br /&gt;
  active_assignment=&amp;quot;FeatureTest&amp;quot;&lt;br /&gt;
  expired_assignment=&amp;quot;LibraryRailsApp&amp;quot;&lt;br /&gt;
  d = Date.parse(Time.now.to_s)&lt;br /&gt;
  due_date1=(d &amp;gt;&amp;gt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
  due_date2=(d &amp;lt;&amp;lt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  # Before all block runs once before all the scenarios are tested&lt;br /&gt;
  before(:all) do&lt;br /&gt;
    # Create active/ongoing assignment&lt;br /&gt;
    create_assignment(active_assignment, due_date1)&lt;br /&gt;
&lt;br /&gt;
    # Create expired/finished assignment&lt;br /&gt;
    create_assignment(expired_assignment, due_date2)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Before each block runs before every scenario&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    # Login as a student before each scenario&lt;br /&gt;
    visit root_path&lt;br /&gt;
    fill_in 'User Name', :with =&amp;gt; 'student13'&lt;br /&gt;
    fill_in 'Password', :with =&amp;gt; 'password'&lt;br /&gt;
    click_on 'SIGN IN'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # After all block runs after all the scenarios are tested&lt;br /&gt;
  after(:all)do&lt;br /&gt;
    # Delete active/ongoing assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(active_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
&lt;br /&gt;
    # Delete expired/finished assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(expired_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Scenario to check whether student is able to submit valid link to an ongoing assignment&lt;br /&gt;
  scenario 'submits only valid link to ongoing assignment' do&lt;br /&gt;
    click_on active_assignment&lt;br /&gt;
    click_on 'Your work'&lt;br /&gt;
    fill_in 'submission', :with =&amp;gt; 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
    click_on 'Upload link'&lt;br /&gt;
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ mkdir review&lt;br /&gt;
$ cd review&lt;br /&gt;
$ git clone https://github.com/shrenujgandhi/expertiza.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case you don't have a database with student and instructor entries then download the dump from https://drive.google.com/a/ncsu.edu/file/d/0B2vDvVjH76uESEkzSWpJRnhGbmc/view. Extract its contents.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:create:all&lt;br /&gt;
$ cd Downloads/&lt;br /&gt;
$ mysql -u root -p expertiza_development &amp;lt; expertiza_scrubbed_2015_08_14.sql&lt;br /&gt;
password:&lt;br /&gt;
&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:migrate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/student_submission_spec.rb &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:test_result_temp2_expertiza.jpg|Feature Test Result]]&lt;br /&gt;
&lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* ''7 examples, 0 failures'' imply that there are 7 test scenarios and none of them failed.&lt;br /&gt;
* The tests take around 35 seconds to run, which implies that they are fast.&lt;br /&gt;
* They are also repeatable as the assignments that are created in the ''before all'' block are also deleted in the ''after all'' block.&lt;br /&gt;
* They are also self-verifying as all the results are in green, which mean that all the cases passed.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/shrenujgandhi/expertiza GitHub Link]&lt;br /&gt;
# [https://youtu.be/_58l0VPy04M YouTube Demo]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100958</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100958"/>
		<updated>2016-03-18T21:12:16Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* flow of the calibration function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is to Functional tests for Calibration function. &lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The instructor does expert reviews first, then after students review calibration assignments and submit peer review results, they can check the expert review. Instructor can check &amp;quot;calibration results&amp;quot; to check the calibration results of the whole class. Currently, there is no feature test for calibration function. The goal is to understand the flow of the calibration function by mock this flow in the '''Feature Tests''' using '''RSpec''' and '''Capybara''' framework.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the functionality from users perspective. '''Feature spec''' allows testing of your application's functionality from the outside either by simulating a browser or by headless browser simulation. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.&lt;br /&gt;
&lt;br /&gt;
===Flow of the calibration function===&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in assignment submission by student on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid student username and password&lt;br /&gt;
# Click on an assignment to submit&lt;br /&gt;
# Click on &amp;quot;Your Work&amp;quot;&lt;br /&gt;
# Paste the link or browse to the file containing your work&lt;br /&gt;
# Click on &amp;quot;Upload Link&amp;quot; or &amp;quot;Upload File&amp;quot; to submit deliverable&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
The gems used in feature testing are '''rspec-rails''', '''capybara''' and '''selenium'''.&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====selenium====&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
Based on the steps involved in manual submission of the assignment, the following test scenarios are considered:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to login&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have text content &amp;lt;b&amp;gt;Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to submit valid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit invalid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;http://&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should display flash message with text &amp;lt;b&amp;gt;URI is not valid&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit valid link to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Page should not have &amp;lt;b&amp;gt;Upload link&amp;lt;/b&amp;gt; button&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able upload file to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the feature test consist in two files:&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/assignment_setup.rb assignment_setup.rb] which contains method for creating assignments using controller calls.&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/features/student_submission_spec.rb student_assignment_submission.rb] which contain calls to assignment_setup, scenarios to test assignment submission and commands to delete the created assignments. &lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;require&amp;lt;/b&amp;gt; files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RSpec.feature 'assignment submission when student' do&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::create assignments for submission&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:each) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::capybara steps to login&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;after(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::delete assignments created&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;scenario 'submits only valid link to ongoing assignment' do&amp;lt;/b&amp;gt;&lt;br /&gt;
::mock steps using capybara&lt;br /&gt;
::make assertions&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sample Scenario====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
require 'assignment_setup'&lt;br /&gt;
&lt;br /&gt;
RSpec.feature 'assignment submission when student' do&lt;br /&gt;
&lt;br /&gt;
  active_assignment=&amp;quot;FeatureTest&amp;quot;&lt;br /&gt;
  expired_assignment=&amp;quot;LibraryRailsApp&amp;quot;&lt;br /&gt;
  d = Date.parse(Time.now.to_s)&lt;br /&gt;
  due_date1=(d &amp;gt;&amp;gt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
  due_date2=(d &amp;lt;&amp;lt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  # Before all block runs once before all the scenarios are tested&lt;br /&gt;
  before(:all) do&lt;br /&gt;
    # Create active/ongoing assignment&lt;br /&gt;
    create_assignment(active_assignment, due_date1)&lt;br /&gt;
&lt;br /&gt;
    # Create expired/finished assignment&lt;br /&gt;
    create_assignment(expired_assignment, due_date2)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Before each block runs before every scenario&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    # Login as a student before each scenario&lt;br /&gt;
    visit root_path&lt;br /&gt;
    fill_in 'User Name', :with =&amp;gt; 'student13'&lt;br /&gt;
    fill_in 'Password', :with =&amp;gt; 'password'&lt;br /&gt;
    click_on 'SIGN IN'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # After all block runs after all the scenarios are tested&lt;br /&gt;
  after(:all)do&lt;br /&gt;
    # Delete active/ongoing assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(active_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
&lt;br /&gt;
    # Delete expired/finished assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(expired_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Scenario to check whether student is able to submit valid link to an ongoing assignment&lt;br /&gt;
  scenario 'submits only valid link to ongoing assignment' do&lt;br /&gt;
    click_on active_assignment&lt;br /&gt;
    click_on 'Your work'&lt;br /&gt;
    fill_in 'submission', :with =&amp;gt; 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
    click_on 'Upload link'&lt;br /&gt;
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ mkdir review&lt;br /&gt;
$ cd review&lt;br /&gt;
$ git clone https://github.com/shrenujgandhi/expertiza.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case you don't have a database with student and instructor entries then download the dump from https://drive.google.com/a/ncsu.edu/file/d/0B2vDvVjH76uESEkzSWpJRnhGbmc/view. Extract its contents.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:create:all&lt;br /&gt;
$ cd Downloads/&lt;br /&gt;
$ mysql -u root -p expertiza_development &amp;lt; expertiza_scrubbed_2015_08_14.sql&lt;br /&gt;
password:&lt;br /&gt;
&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:migrate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/student_submission_spec.rb &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:test_result_temp2_expertiza.jpg|Feature Test Result]]&lt;br /&gt;
&lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* ''7 examples, 0 failures'' imply that there are 7 test scenarios and none of them failed.&lt;br /&gt;
* The tests take around 35 seconds to run, which implies that they are fast.&lt;br /&gt;
* They are also repeatable as the assignments that are created in the ''before all'' block are also deleted in the ''after all'' block.&lt;br /&gt;
* They are also self-verifying as all the results are in green, which mean that all the cases passed.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/shrenujgandhi/expertiza GitHub Link]&lt;br /&gt;
# [https://youtu.be/_58l0VPy04M YouTube Demo]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100957</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100957"/>
		<updated>2016-03-18T21:12:04Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Steps for manual submission */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is to Functional tests for Calibration function. &lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The instructor does expert reviews first, then after students review calibration assignments and submit peer review results, they can check the expert review. Instructor can check &amp;quot;calibration results&amp;quot; to check the calibration results of the whole class. Currently, there is no feature test for calibration function. The goal is to understand the flow of the calibration function by mock this flow in the '''Feature Tests''' using '''RSpec''' and '''Capybara''' framework.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the functionality from users perspective. '''Feature spec''' allows testing of your application's functionality from the outside either by simulating a browser or by headless browser simulation. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.&lt;br /&gt;
&lt;br /&gt;
===flow of the calibration function===&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in assignment submission by student on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid student username and password&lt;br /&gt;
# Click on an assignment to submit&lt;br /&gt;
# Click on &amp;quot;Your Work&amp;quot;&lt;br /&gt;
# Paste the link or browse to the file containing your work&lt;br /&gt;
# Click on &amp;quot;Upload Link&amp;quot; or &amp;quot;Upload File&amp;quot; to submit deliverable&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
The gems used in feature testing are '''rspec-rails''', '''capybara''' and '''selenium'''.&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====selenium====&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
Based on the steps involved in manual submission of the assignment, the following test scenarios are considered:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to login&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have text content &amp;lt;b&amp;gt;Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to submit valid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit invalid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;http://&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should display flash message with text &amp;lt;b&amp;gt;URI is not valid&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit valid link to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Page should not have &amp;lt;b&amp;gt;Upload link&amp;lt;/b&amp;gt; button&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able upload file to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the feature test consist in two files:&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/assignment_setup.rb assignment_setup.rb] which contains method for creating assignments using controller calls.&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/features/student_submission_spec.rb student_assignment_submission.rb] which contain calls to assignment_setup, scenarios to test assignment submission and commands to delete the created assignments. &lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;require&amp;lt;/b&amp;gt; files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RSpec.feature 'assignment submission when student' do&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::create assignments for submission&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:each) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::capybara steps to login&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;after(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::delete assignments created&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;scenario 'submits only valid link to ongoing assignment' do&amp;lt;/b&amp;gt;&lt;br /&gt;
::mock steps using capybara&lt;br /&gt;
::make assertions&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sample Scenario====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
require 'assignment_setup'&lt;br /&gt;
&lt;br /&gt;
RSpec.feature 'assignment submission when student' do&lt;br /&gt;
&lt;br /&gt;
  active_assignment=&amp;quot;FeatureTest&amp;quot;&lt;br /&gt;
  expired_assignment=&amp;quot;LibraryRailsApp&amp;quot;&lt;br /&gt;
  d = Date.parse(Time.now.to_s)&lt;br /&gt;
  due_date1=(d &amp;gt;&amp;gt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
  due_date2=(d &amp;lt;&amp;lt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  # Before all block runs once before all the scenarios are tested&lt;br /&gt;
  before(:all) do&lt;br /&gt;
    # Create active/ongoing assignment&lt;br /&gt;
    create_assignment(active_assignment, due_date1)&lt;br /&gt;
&lt;br /&gt;
    # Create expired/finished assignment&lt;br /&gt;
    create_assignment(expired_assignment, due_date2)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Before each block runs before every scenario&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    # Login as a student before each scenario&lt;br /&gt;
    visit root_path&lt;br /&gt;
    fill_in 'User Name', :with =&amp;gt; 'student13'&lt;br /&gt;
    fill_in 'Password', :with =&amp;gt; 'password'&lt;br /&gt;
    click_on 'SIGN IN'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # After all block runs after all the scenarios are tested&lt;br /&gt;
  after(:all)do&lt;br /&gt;
    # Delete active/ongoing assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(active_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
&lt;br /&gt;
    # Delete expired/finished assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(expired_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Scenario to check whether student is able to submit valid link to an ongoing assignment&lt;br /&gt;
  scenario 'submits only valid link to ongoing assignment' do&lt;br /&gt;
    click_on active_assignment&lt;br /&gt;
    click_on 'Your work'&lt;br /&gt;
    fill_in 'submission', :with =&amp;gt; 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
    click_on 'Upload link'&lt;br /&gt;
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ mkdir review&lt;br /&gt;
$ cd review&lt;br /&gt;
$ git clone https://github.com/shrenujgandhi/expertiza.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case you don't have a database with student and instructor entries then download the dump from https://drive.google.com/a/ncsu.edu/file/d/0B2vDvVjH76uESEkzSWpJRnhGbmc/view. Extract its contents.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:create:all&lt;br /&gt;
$ cd Downloads/&lt;br /&gt;
$ mysql -u root -p expertiza_development &amp;lt; expertiza_scrubbed_2015_08_14.sql&lt;br /&gt;
password:&lt;br /&gt;
&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:migrate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/student_submission_spec.rb &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:test_result_temp2_expertiza.jpg|Feature Test Result]]&lt;br /&gt;
&lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* ''7 examples, 0 failures'' imply that there are 7 test scenarios and none of them failed.&lt;br /&gt;
* The tests take around 35 seconds to run, which implies that they are fast.&lt;br /&gt;
* They are also repeatable as the assignments that are created in the ''before all'' block are also deleted in the ''after all'' block.&lt;br /&gt;
* They are also self-verifying as all the results are in green, which mean that all the cases passed.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/shrenujgandhi/expertiza GitHub Link]&lt;br /&gt;
# [https://youtu.be/_58l0VPy04M YouTube Demo]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100956</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100956"/>
		<updated>2016-03-18T21:10:39Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Future Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is to Functional tests for Calibration function. &lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The instructor does expert reviews first, then after students review calibration assignments and submit peer review results, they can check the expert review. Instructor can check &amp;quot;calibration results&amp;quot; to check the calibration results of the whole class. Currently, there is no feature test for calibration function. The goal is to understand the flow of the calibration function by mock this flow in the '''Feature Tests''' using '''RSpec''' and '''Capybara''' framework.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the functionality from users perspective. '''Feature spec''' allows testing of your application's functionality from the outside either by simulating a browser or by headless browser simulation. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.&lt;br /&gt;
&lt;br /&gt;
===Steps for manual submission===&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in assignment submission by student on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid student username and password&lt;br /&gt;
# Click on an assignment to submit&lt;br /&gt;
# Click on &amp;quot;Your Work&amp;quot;&lt;br /&gt;
# Paste the link or browse to the file containing your work&lt;br /&gt;
# Click on &amp;quot;Upload Link&amp;quot; or &amp;quot;Upload File&amp;quot; to submit deliverable&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
The gems used in feature testing are '''rspec-rails''', '''capybara''' and '''selenium'''.&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====selenium====&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
Based on the steps involved in manual submission of the assignment, the following test scenarios are considered:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to login&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have text content &amp;lt;b&amp;gt;Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to submit valid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit invalid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;http://&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should display flash message with text &amp;lt;b&amp;gt;URI is not valid&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit valid link to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Page should not have &amp;lt;b&amp;gt;Upload link&amp;lt;/b&amp;gt; button&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able upload file to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the feature test consist in two files:&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/assignment_setup.rb assignment_setup.rb] which contains method for creating assignments using controller calls.&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/features/student_submission_spec.rb student_assignment_submission.rb] which contain calls to assignment_setup, scenarios to test assignment submission and commands to delete the created assignments. &lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;require&amp;lt;/b&amp;gt; files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RSpec.feature 'assignment submission when student' do&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::create assignments for submission&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:each) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::capybara steps to login&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;after(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::delete assignments created&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;scenario 'submits only valid link to ongoing assignment' do&amp;lt;/b&amp;gt;&lt;br /&gt;
::mock steps using capybara&lt;br /&gt;
::make assertions&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sample Scenario====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
require 'assignment_setup'&lt;br /&gt;
&lt;br /&gt;
RSpec.feature 'assignment submission when student' do&lt;br /&gt;
&lt;br /&gt;
  active_assignment=&amp;quot;FeatureTest&amp;quot;&lt;br /&gt;
  expired_assignment=&amp;quot;LibraryRailsApp&amp;quot;&lt;br /&gt;
  d = Date.parse(Time.now.to_s)&lt;br /&gt;
  due_date1=(d &amp;gt;&amp;gt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
  due_date2=(d &amp;lt;&amp;lt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  # Before all block runs once before all the scenarios are tested&lt;br /&gt;
  before(:all) do&lt;br /&gt;
    # Create active/ongoing assignment&lt;br /&gt;
    create_assignment(active_assignment, due_date1)&lt;br /&gt;
&lt;br /&gt;
    # Create expired/finished assignment&lt;br /&gt;
    create_assignment(expired_assignment, due_date2)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Before each block runs before every scenario&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    # Login as a student before each scenario&lt;br /&gt;
    visit root_path&lt;br /&gt;
    fill_in 'User Name', :with =&amp;gt; 'student13'&lt;br /&gt;
    fill_in 'Password', :with =&amp;gt; 'password'&lt;br /&gt;
    click_on 'SIGN IN'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # After all block runs after all the scenarios are tested&lt;br /&gt;
  after(:all)do&lt;br /&gt;
    # Delete active/ongoing assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(active_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
&lt;br /&gt;
    # Delete expired/finished assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(expired_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Scenario to check whether student is able to submit valid link to an ongoing assignment&lt;br /&gt;
  scenario 'submits only valid link to ongoing assignment' do&lt;br /&gt;
    click_on active_assignment&lt;br /&gt;
    click_on 'Your work'&lt;br /&gt;
    fill_in 'submission', :with =&amp;gt; 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
    click_on 'Upload link'&lt;br /&gt;
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ mkdir review&lt;br /&gt;
$ cd review&lt;br /&gt;
$ git clone https://github.com/shrenujgandhi/expertiza.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case you don't have a database with student and instructor entries then download the dump from https://drive.google.com/a/ncsu.edu/file/d/0B2vDvVjH76uESEkzSWpJRnhGbmc/view. Extract its contents.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:create:all&lt;br /&gt;
$ cd Downloads/&lt;br /&gt;
$ mysql -u root -p expertiza_development &amp;lt; expertiza_scrubbed_2015_08_14.sql&lt;br /&gt;
password:&lt;br /&gt;
&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:migrate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/student_submission_spec.rb &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:test_result_temp2_expertiza.jpg|Feature Test Result]]&lt;br /&gt;
&lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* ''7 examples, 0 failures'' imply that there are 7 test scenarios and none of them failed.&lt;br /&gt;
* The tests take around 35 seconds to run, which implies that they are fast.&lt;br /&gt;
* They are also repeatable as the assignments that are created in the ''before all'' block are also deleted in the ''after all'' block.&lt;br /&gt;
* They are also self-verifying as all the results are in green, which mean that all the cases passed.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/shrenujgandhi/expertiza GitHub Link]&lt;br /&gt;
# [https://youtu.be/_58l0VPy04M YouTube Demo]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100955</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100955"/>
		<updated>2016-03-18T21:10:16Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Existing Bugs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is to Functional tests for Calibration function. &lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The instructor does expert reviews first, then after students review calibration assignments and submit peer review results, they can check the expert review. Instructor can check &amp;quot;calibration results&amp;quot; to check the calibration results of the whole class. Currently, there is no feature test for calibration function. The goal is to understand the flow of the calibration function by mock this flow in the '''Feature Tests''' using '''RSpec''' and '''Capybara''' framework.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the functionality from users perspective. '''Feature spec''' allows testing of your application's functionality from the outside either by simulating a browser or by headless browser simulation. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.&lt;br /&gt;
&lt;br /&gt;
===Steps for manual submission===&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in assignment submission by student on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid student username and password&lt;br /&gt;
# Click on an assignment to submit&lt;br /&gt;
# Click on &amp;quot;Your Work&amp;quot;&lt;br /&gt;
# Paste the link or browse to the file containing your work&lt;br /&gt;
# Click on &amp;quot;Upload Link&amp;quot; or &amp;quot;Upload File&amp;quot; to submit deliverable&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
The gems used in feature testing are '''rspec-rails''', '''capybara''' and '''selenium'''.&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====selenium====&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
Based on the steps involved in manual submission of the assignment, the following test scenarios are considered:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to login&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have text content &amp;lt;b&amp;gt;Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to submit valid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit invalid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;http://&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should display flash message with text &amp;lt;b&amp;gt;URI is not valid&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit valid link to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Page should not have &amp;lt;b&amp;gt;Upload link&amp;lt;/b&amp;gt; button&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able upload file to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the feature test consist in two files:&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/assignment_setup.rb assignment_setup.rb] which contains method for creating assignments using controller calls.&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/features/student_submission_spec.rb student_assignment_submission.rb] which contain calls to assignment_setup, scenarios to test assignment submission and commands to delete the created assignments. &lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;require&amp;lt;/b&amp;gt; files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RSpec.feature 'assignment submission when student' do&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::create assignments for submission&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:each) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::capybara steps to login&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;after(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::delete assignments created&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;scenario 'submits only valid link to ongoing assignment' do&amp;lt;/b&amp;gt;&lt;br /&gt;
::mock steps using capybara&lt;br /&gt;
::make assertions&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sample Scenario====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
require 'assignment_setup'&lt;br /&gt;
&lt;br /&gt;
RSpec.feature 'assignment submission when student' do&lt;br /&gt;
&lt;br /&gt;
  active_assignment=&amp;quot;FeatureTest&amp;quot;&lt;br /&gt;
  expired_assignment=&amp;quot;LibraryRailsApp&amp;quot;&lt;br /&gt;
  d = Date.parse(Time.now.to_s)&lt;br /&gt;
  due_date1=(d &amp;gt;&amp;gt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
  due_date2=(d &amp;lt;&amp;lt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  # Before all block runs once before all the scenarios are tested&lt;br /&gt;
  before(:all) do&lt;br /&gt;
    # Create active/ongoing assignment&lt;br /&gt;
    create_assignment(active_assignment, due_date1)&lt;br /&gt;
&lt;br /&gt;
    # Create expired/finished assignment&lt;br /&gt;
    create_assignment(expired_assignment, due_date2)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Before each block runs before every scenario&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    # Login as a student before each scenario&lt;br /&gt;
    visit root_path&lt;br /&gt;
    fill_in 'User Name', :with =&amp;gt; 'student13'&lt;br /&gt;
    fill_in 'Password', :with =&amp;gt; 'password'&lt;br /&gt;
    click_on 'SIGN IN'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # After all block runs after all the scenarios are tested&lt;br /&gt;
  after(:all)do&lt;br /&gt;
    # Delete active/ongoing assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(active_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
&lt;br /&gt;
    # Delete expired/finished assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(expired_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Scenario to check whether student is able to submit valid link to an ongoing assignment&lt;br /&gt;
  scenario 'submits only valid link to ongoing assignment' do&lt;br /&gt;
    click_on active_assignment&lt;br /&gt;
    click_on 'Your work'&lt;br /&gt;
    fill_in 'submission', :with =&amp;gt; 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
    click_on 'Upload link'&lt;br /&gt;
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ mkdir review&lt;br /&gt;
$ cd review&lt;br /&gt;
$ git clone https://github.com/shrenujgandhi/expertiza.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case you don't have a database with student and instructor entries then download the dump from https://drive.google.com/a/ncsu.edu/file/d/0B2vDvVjH76uESEkzSWpJRnhGbmc/view. Extract its contents.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:create:all&lt;br /&gt;
$ cd Downloads/&lt;br /&gt;
$ mysql -u root -p expertiza_development &amp;lt; expertiza_scrubbed_2015_08_14.sql&lt;br /&gt;
password:&lt;br /&gt;
&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:migrate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/student_submission_spec.rb &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:test_result_temp2_expertiza.jpg|Feature Test Result]]&lt;br /&gt;
&lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* ''7 examples, 0 failures'' imply that there are 7 test scenarios and none of them failed.&lt;br /&gt;
* The tests take around 35 seconds to run, which implies that they are fast.&lt;br /&gt;
* They are also repeatable as the assignments that are created in the ''before all'' block are also deleted in the ''after all'' block.&lt;br /&gt;
* They are also self-verifying as all the results are in green, which mean that all the cases passed.&lt;br /&gt;
&lt;br /&gt;
=== Future Work ===&lt;br /&gt;
&lt;br /&gt;
* To prevent students from uploading a file to a finished assignment, like the upload link button, remove the upload file button.&lt;br /&gt;
* Executable files can sometimes be a part of the assignment. To there needs to be a check while creating the assignment whether .exe files are allowed or not.&lt;br /&gt;
* To run the test on test database using factories and fixtures, so that the tests are completely independent.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/shrenujgandhi/expertiza GitHub Link]&lt;br /&gt;
# [https://youtu.be/_58l0VPy04M YouTube Demo]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100954</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100954"/>
		<updated>2016-03-18T21:10:03Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Existing Bugs */ deleted&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is to Functional tests for Calibration function. &lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The instructor does expert reviews first, then after students review calibration assignments and submit peer review results, they can check the expert review. Instructor can check &amp;quot;calibration results&amp;quot; to check the calibration results of the whole class. Currently, there is no feature test for calibration function. The goal is to understand the flow of the calibration function by mock this flow in the '''Feature Tests''' using '''RSpec''' and '''Capybara''' framework.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the functionality from users perspective. '''Feature spec''' allows testing of your application's functionality from the outside either by simulating a browser or by headless browser simulation. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.&lt;br /&gt;
&lt;br /&gt;
===Steps for manual submission===&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in assignment submission by student on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid student username and password&lt;br /&gt;
# Click on an assignment to submit&lt;br /&gt;
# Click on &amp;quot;Your Work&amp;quot;&lt;br /&gt;
# Paste the link or browse to the file containing your work&lt;br /&gt;
# Click on &amp;quot;Upload Link&amp;quot; or &amp;quot;Upload File&amp;quot; to submit deliverable&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
The gems used in feature testing are '''rspec-rails''', '''capybara''' and '''selenium'''.&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====selenium====&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
Based on the steps involved in manual submission of the assignment, the following test scenarios are considered:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to login&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have text content &amp;lt;b&amp;gt;Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to submit valid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit invalid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;http://&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should display flash message with text &amp;lt;b&amp;gt;URI is not valid&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit valid link to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Page should not have &amp;lt;b&amp;gt;Upload link&amp;lt;/b&amp;gt; button&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able upload file to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the feature test consist in two files:&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/assignment_setup.rb assignment_setup.rb] which contains method for creating assignments using controller calls.&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/features/student_submission_spec.rb student_assignment_submission.rb] which contain calls to assignment_setup, scenarios to test assignment submission and commands to delete the created assignments. &lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;require&amp;lt;/b&amp;gt; files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RSpec.feature 'assignment submission when student' do&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::create assignments for submission&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:each) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::capybara steps to login&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;after(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::delete assignments created&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;scenario 'submits only valid link to ongoing assignment' do&amp;lt;/b&amp;gt;&lt;br /&gt;
::mock steps using capybara&lt;br /&gt;
::make assertions&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sample Scenario====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
require 'assignment_setup'&lt;br /&gt;
&lt;br /&gt;
RSpec.feature 'assignment submission when student' do&lt;br /&gt;
&lt;br /&gt;
  active_assignment=&amp;quot;FeatureTest&amp;quot;&lt;br /&gt;
  expired_assignment=&amp;quot;LibraryRailsApp&amp;quot;&lt;br /&gt;
  d = Date.parse(Time.now.to_s)&lt;br /&gt;
  due_date1=(d &amp;gt;&amp;gt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
  due_date2=(d &amp;lt;&amp;lt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  # Before all block runs once before all the scenarios are tested&lt;br /&gt;
  before(:all) do&lt;br /&gt;
    # Create active/ongoing assignment&lt;br /&gt;
    create_assignment(active_assignment, due_date1)&lt;br /&gt;
&lt;br /&gt;
    # Create expired/finished assignment&lt;br /&gt;
    create_assignment(expired_assignment, due_date2)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Before each block runs before every scenario&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    # Login as a student before each scenario&lt;br /&gt;
    visit root_path&lt;br /&gt;
    fill_in 'User Name', :with =&amp;gt; 'student13'&lt;br /&gt;
    fill_in 'Password', :with =&amp;gt; 'password'&lt;br /&gt;
    click_on 'SIGN IN'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # After all block runs after all the scenarios are tested&lt;br /&gt;
  after(:all)do&lt;br /&gt;
    # Delete active/ongoing assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(active_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
&lt;br /&gt;
    # Delete expired/finished assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(expired_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Scenario to check whether student is able to submit valid link to an ongoing assignment&lt;br /&gt;
  scenario 'submits only valid link to ongoing assignment' do&lt;br /&gt;
    click_on active_assignment&lt;br /&gt;
    click_on 'Your work'&lt;br /&gt;
    fill_in 'submission', :with =&amp;gt; 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
    click_on 'Upload link'&lt;br /&gt;
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ mkdir review&lt;br /&gt;
$ cd review&lt;br /&gt;
$ git clone https://github.com/shrenujgandhi/expertiza.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case you don't have a database with student and instructor entries then download the dump from https://drive.google.com/a/ncsu.edu/file/d/0B2vDvVjH76uESEkzSWpJRnhGbmc/view. Extract its contents.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:create:all&lt;br /&gt;
$ cd Downloads/&lt;br /&gt;
$ mysql -u root -p expertiza_development &amp;lt; expertiza_scrubbed_2015_08_14.sql&lt;br /&gt;
password:&lt;br /&gt;
&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:migrate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/student_submission_spec.rb &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:test_result_temp2_expertiza.jpg|Feature Test Result]]&lt;br /&gt;
&lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* ''7 examples, 0 failures'' imply that there are 7 test scenarios and none of them failed.&lt;br /&gt;
* The tests take around 35 seconds to run, which implies that they are fast.&lt;br /&gt;
* They are also repeatable as the assignments that are created in the ''before all'' block are also deleted in the ''after all'' block.&lt;br /&gt;
* They are also self-verifying as all the results are in green, which mean that all the cases passed.&lt;br /&gt;
&lt;br /&gt;
=== Existing Bugs ===&lt;br /&gt;
&lt;br /&gt;
=== Future Work ===&lt;br /&gt;
&lt;br /&gt;
* To prevent students from uploading a file to a finished assignment, like the upload link button, remove the upload file button.&lt;br /&gt;
* Executable files can sometimes be a part of the assignment. To there needs to be a check while creating the assignment whether .exe files are allowed or not.&lt;br /&gt;
* To run the test on test database using factories and fixtures, so that the tests are completely independent.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/shrenujgandhi/expertiza GitHub Link]&lt;br /&gt;
# [https://youtu.be/_58l0VPy04M YouTube Demo]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100953</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100953"/>
		<updated>2016-03-18T21:07:45Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Gems involved */ update on selenium section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is to Functional tests for Calibration function. &lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The instructor does expert reviews first, then after students review calibration assignments and submit peer review results, they can check the expert review. Instructor can check &amp;quot;calibration results&amp;quot; to check the calibration results of the whole class. Currently, there is no feature test for calibration function. The goal is to understand the flow of the calibration function by mock this flow in the '''Feature Tests''' using '''RSpec''' and '''Capybara''' framework.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the functionality from users perspective. '''Feature spec''' allows testing of your application's functionality from the outside either by simulating a browser or by headless browser simulation. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.&lt;br /&gt;
&lt;br /&gt;
===Steps for manual submission===&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in assignment submission by student on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid student username and password&lt;br /&gt;
# Click on an assignment to submit&lt;br /&gt;
# Click on &amp;quot;Your Work&amp;quot;&lt;br /&gt;
# Paste the link or browse to the file containing your work&lt;br /&gt;
# Click on &amp;quot;Upload Link&amp;quot; or &amp;quot;Upload File&amp;quot; to submit deliverable&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
The gems used in feature testing are '''rspec-rails''', '''capybara''' and '''selenium'''.&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====selenium====&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
Based on the steps involved in manual submission of the assignment, the following test scenarios are considered:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to login&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have text content &amp;lt;b&amp;gt;Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to submit valid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit invalid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;http://&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should display flash message with text &amp;lt;b&amp;gt;URI is not valid&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit valid link to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Page should not have &amp;lt;b&amp;gt;Upload link&amp;lt;/b&amp;gt; button&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able upload file to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the feature test consist in two files:&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/assignment_setup.rb assignment_setup.rb] which contains method for creating assignments using controller calls.&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/features/student_submission_spec.rb student_assignment_submission.rb] which contain calls to assignment_setup, scenarios to test assignment submission and commands to delete the created assignments. &lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;require&amp;lt;/b&amp;gt; files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RSpec.feature 'assignment submission when student' do&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::create assignments for submission&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:each) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::capybara steps to login&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;after(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::delete assignments created&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;scenario 'submits only valid link to ongoing assignment' do&amp;lt;/b&amp;gt;&lt;br /&gt;
::mock steps using capybara&lt;br /&gt;
::make assertions&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sample Scenario====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
require 'assignment_setup'&lt;br /&gt;
&lt;br /&gt;
RSpec.feature 'assignment submission when student' do&lt;br /&gt;
&lt;br /&gt;
  active_assignment=&amp;quot;FeatureTest&amp;quot;&lt;br /&gt;
  expired_assignment=&amp;quot;LibraryRailsApp&amp;quot;&lt;br /&gt;
  d = Date.parse(Time.now.to_s)&lt;br /&gt;
  due_date1=(d &amp;gt;&amp;gt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
  due_date2=(d &amp;lt;&amp;lt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  # Before all block runs once before all the scenarios are tested&lt;br /&gt;
  before(:all) do&lt;br /&gt;
    # Create active/ongoing assignment&lt;br /&gt;
    create_assignment(active_assignment, due_date1)&lt;br /&gt;
&lt;br /&gt;
    # Create expired/finished assignment&lt;br /&gt;
    create_assignment(expired_assignment, due_date2)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Before each block runs before every scenario&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    # Login as a student before each scenario&lt;br /&gt;
    visit root_path&lt;br /&gt;
    fill_in 'User Name', :with =&amp;gt; 'student13'&lt;br /&gt;
    fill_in 'Password', :with =&amp;gt; 'password'&lt;br /&gt;
    click_on 'SIGN IN'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # After all block runs after all the scenarios are tested&lt;br /&gt;
  after(:all)do&lt;br /&gt;
    # Delete active/ongoing assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(active_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
&lt;br /&gt;
    # Delete expired/finished assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(expired_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Scenario to check whether student is able to submit valid link to an ongoing assignment&lt;br /&gt;
  scenario 'submits only valid link to ongoing assignment' do&lt;br /&gt;
    click_on active_assignment&lt;br /&gt;
    click_on 'Your work'&lt;br /&gt;
    fill_in 'submission', :with =&amp;gt; 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
    click_on 'Upload link'&lt;br /&gt;
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ mkdir review&lt;br /&gt;
$ cd review&lt;br /&gt;
$ git clone https://github.com/shrenujgandhi/expertiza.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case you don't have a database with student and instructor entries then download the dump from https://drive.google.com/a/ncsu.edu/file/d/0B2vDvVjH76uESEkzSWpJRnhGbmc/view. Extract its contents.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:create:all&lt;br /&gt;
$ cd Downloads/&lt;br /&gt;
$ mysql -u root -p expertiza_development &amp;lt; expertiza_scrubbed_2015_08_14.sql&lt;br /&gt;
password:&lt;br /&gt;
&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:migrate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/student_submission_spec.rb &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:test_result_temp2_expertiza.jpg|Feature Test Result]]&lt;br /&gt;
&lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* ''7 examples, 0 failures'' imply that there are 7 test scenarios and none of them failed.&lt;br /&gt;
* The tests take around 35 seconds to run, which implies that they are fast.&lt;br /&gt;
* They are also repeatable as the assignments that are created in the ''before all'' block are also deleted in the ''after all'' block.&lt;br /&gt;
* They are also self-verifying as all the results are in green, which mean that all the cases passed.&lt;br /&gt;
&lt;br /&gt;
=== Existing Bugs ===&lt;br /&gt;
During the course of our testing, we encountered two potential bugs in the Expertiza system. These are:&lt;br /&gt;
# A student can upload file even after the assignment is finished.&lt;br /&gt;
# A student can upload an .exe file to any assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following screenshots show these bugs on the current version of Expertiza used by the batch of Fall 2015.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:one_screenshot_expertiza.jpg|List of Assignments in Expertiza with Current Stage]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows the list of assignments along with their current stage in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:two_screenshot_expertiza.jpg|Select file for finished assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can select a file in a finished assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:three_screenshot_expertiza.jpg|Uploaded file for finished assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can upload a file in a finished assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:four_screenshot_expertiza.jpg|Select .exe file for ongoing assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can select an .exe file in any assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:five_screenshot_expertiza.jpg|Uploaded .exe file for ongoing assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can upload an .exe file in any assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Future Work ===&lt;br /&gt;
&lt;br /&gt;
* To prevent students from uploading a file to a finished assignment, like the upload link button, remove the upload file button.&lt;br /&gt;
* Executable files can sometimes be a part of the assignment. To there needs to be a check while creating the assignment whether .exe files are allowed or not.&lt;br /&gt;
* To run the test on test database using factories and fixtures, so that the tests are completely independent.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/shrenujgandhi/expertiza GitHub Link]&lt;br /&gt;
# [https://youtu.be/_58l0VPy04M YouTube Demo]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100952</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100952"/>
		<updated>2016-03-18T21:07:13Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Gems involved */ Update on Gem invovled&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is to Functional tests for Calibration function. &lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The instructor does expert reviews first, then after students review calibration assignments and submit peer review results, they can check the expert review. Instructor can check &amp;quot;calibration results&amp;quot; to check the calibration results of the whole class. Currently, there is no feature test for calibration function. The goal is to understand the flow of the calibration function by mock this flow in the '''Feature Tests''' using '''RSpec''' and '''Capybara''' framework.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the functionality from users perspective. '''Feature spec''' allows testing of your application's functionality from the outside either by simulating a browser or by headless browser simulation. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.&lt;br /&gt;
&lt;br /&gt;
===Steps for manual submission===&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in assignment submission by student on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid student username and password&lt;br /&gt;
# Click on an assignment to submit&lt;br /&gt;
# Click on &amp;quot;Your Work&amp;quot;&lt;br /&gt;
# Paste the link or browse to the file containing your work&lt;br /&gt;
# Click on &amp;quot;Upload Link&amp;quot; or &amp;quot;Upload File&amp;quot; to submit deliverable&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
The gems used in feature testing are '''rspec-rails''', '''capybara''' and '''selenium'''.&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
Based on the steps involved in manual submission of the assignment, the following test scenarios are considered:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to login&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have text content &amp;lt;b&amp;gt;Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to submit valid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit invalid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;http://&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should display flash message with text &amp;lt;b&amp;gt;URI is not valid&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit valid link to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Page should not have &amp;lt;b&amp;gt;Upload link&amp;lt;/b&amp;gt; button&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able upload file to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the feature test consist in two files:&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/assignment_setup.rb assignment_setup.rb] which contains method for creating assignments using controller calls.&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/features/student_submission_spec.rb student_assignment_submission.rb] which contain calls to assignment_setup, scenarios to test assignment submission and commands to delete the created assignments. &lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;require&amp;lt;/b&amp;gt; files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RSpec.feature 'assignment submission when student' do&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::create assignments for submission&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:each) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::capybara steps to login&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;after(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::delete assignments created&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;scenario 'submits only valid link to ongoing assignment' do&amp;lt;/b&amp;gt;&lt;br /&gt;
::mock steps using capybara&lt;br /&gt;
::make assertions&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sample Scenario====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
require 'assignment_setup'&lt;br /&gt;
&lt;br /&gt;
RSpec.feature 'assignment submission when student' do&lt;br /&gt;
&lt;br /&gt;
  active_assignment=&amp;quot;FeatureTest&amp;quot;&lt;br /&gt;
  expired_assignment=&amp;quot;LibraryRailsApp&amp;quot;&lt;br /&gt;
  d = Date.parse(Time.now.to_s)&lt;br /&gt;
  due_date1=(d &amp;gt;&amp;gt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
  due_date2=(d &amp;lt;&amp;lt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  # Before all block runs once before all the scenarios are tested&lt;br /&gt;
  before(:all) do&lt;br /&gt;
    # Create active/ongoing assignment&lt;br /&gt;
    create_assignment(active_assignment, due_date1)&lt;br /&gt;
&lt;br /&gt;
    # Create expired/finished assignment&lt;br /&gt;
    create_assignment(expired_assignment, due_date2)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Before each block runs before every scenario&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    # Login as a student before each scenario&lt;br /&gt;
    visit root_path&lt;br /&gt;
    fill_in 'User Name', :with =&amp;gt; 'student13'&lt;br /&gt;
    fill_in 'Password', :with =&amp;gt; 'password'&lt;br /&gt;
    click_on 'SIGN IN'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # After all block runs after all the scenarios are tested&lt;br /&gt;
  after(:all)do&lt;br /&gt;
    # Delete active/ongoing assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(active_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
&lt;br /&gt;
    # Delete expired/finished assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(expired_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Scenario to check whether student is able to submit valid link to an ongoing assignment&lt;br /&gt;
  scenario 'submits only valid link to ongoing assignment' do&lt;br /&gt;
    click_on active_assignment&lt;br /&gt;
    click_on 'Your work'&lt;br /&gt;
    fill_in 'submission', :with =&amp;gt; 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
    click_on 'Upload link'&lt;br /&gt;
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ mkdir review&lt;br /&gt;
$ cd review&lt;br /&gt;
$ git clone https://github.com/shrenujgandhi/expertiza.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case you don't have a database with student and instructor entries then download the dump from https://drive.google.com/a/ncsu.edu/file/d/0B2vDvVjH76uESEkzSWpJRnhGbmc/view. Extract its contents.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:create:all&lt;br /&gt;
$ cd Downloads/&lt;br /&gt;
$ mysql -u root -p expertiza_development &amp;lt; expertiza_scrubbed_2015_08_14.sql&lt;br /&gt;
password:&lt;br /&gt;
&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:migrate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/student_submission_spec.rb &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:test_result_temp2_expertiza.jpg|Feature Test Result]]&lt;br /&gt;
&lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* ''7 examples, 0 failures'' imply that there are 7 test scenarios and none of them failed.&lt;br /&gt;
* The tests take around 35 seconds to run, which implies that they are fast.&lt;br /&gt;
* They are also repeatable as the assignments that are created in the ''before all'' block are also deleted in the ''after all'' block.&lt;br /&gt;
* They are also self-verifying as all the results are in green, which mean that all the cases passed.&lt;br /&gt;
&lt;br /&gt;
=== Existing Bugs ===&lt;br /&gt;
During the course of our testing, we encountered two potential bugs in the Expertiza system. These are:&lt;br /&gt;
# A student can upload file even after the assignment is finished.&lt;br /&gt;
# A student can upload an .exe file to any assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following screenshots show these bugs on the current version of Expertiza used by the batch of Fall 2015.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:one_screenshot_expertiza.jpg|List of Assignments in Expertiza with Current Stage]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows the list of assignments along with their current stage in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:two_screenshot_expertiza.jpg|Select file for finished assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can select a file in a finished assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:three_screenshot_expertiza.jpg|Uploaded file for finished assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can upload a file in a finished assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:four_screenshot_expertiza.jpg|Select .exe file for ongoing assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can select an .exe file in any assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:five_screenshot_expertiza.jpg|Uploaded .exe file for ongoing assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can upload an .exe file in any assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Future Work ===&lt;br /&gt;
&lt;br /&gt;
* To prevent students from uploading a file to a finished assignment, like the upload link button, remove the upload file button.&lt;br /&gt;
* Executable files can sometimes be a part of the assignment. To there needs to be a check while creating the assignment whether .exe files are allowed or not.&lt;br /&gt;
* To run the test on test database using factories and fixtures, so that the tests are completely independent.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/shrenujgandhi/expertiza GitHub Link]&lt;br /&gt;
# [https://youtu.be/_58l0VPy04M YouTube Demo]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100951</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100951"/>
		<updated>2016-03-18T21:05:17Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Assumptions */ delete assumption&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is to Functional tests for Calibration function. &lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The instructor does expert reviews first, then after students review calibration assignments and submit peer review results, they can check the expert review. Instructor can check &amp;quot;calibration results&amp;quot; to check the calibration results of the whole class. Currently, there is no feature test for calibration function. The goal is to understand the flow of the calibration function by mock this flow in the '''Feature Tests''' using '''RSpec''' and '''Capybara''' framework.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the functionality from users perspective. '''Feature spec''' allows testing of your application's functionality from the outside either by simulating a browser or by headless browser simulation. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.&lt;br /&gt;
&lt;br /&gt;
===Steps for manual submission===&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in assignment submission by student on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid student username and password&lt;br /&gt;
# Click on an assignment to submit&lt;br /&gt;
# Click on &amp;quot;Your Work&amp;quot;&lt;br /&gt;
# Paste the link or browse to the file containing your work&lt;br /&gt;
# Click on &amp;quot;Upload Link&amp;quot; or &amp;quot;Upload File&amp;quot; to submit deliverable&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
The gems used in feature testing are '''rspec-rails''' and '''capybara'''&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
Based on the steps involved in manual submission of the assignment, the following test scenarios are considered:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to login&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have text content &amp;lt;b&amp;gt;Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to submit valid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit invalid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;http://&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should display flash message with text &amp;lt;b&amp;gt;URI is not valid&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit valid link to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Page should not have &amp;lt;b&amp;gt;Upload link&amp;lt;/b&amp;gt; button&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able upload file to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the feature test consist in two files:&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/assignment_setup.rb assignment_setup.rb] which contains method for creating assignments using controller calls.&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/features/student_submission_spec.rb student_assignment_submission.rb] which contain calls to assignment_setup, scenarios to test assignment submission and commands to delete the created assignments. &lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;require&amp;lt;/b&amp;gt; files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RSpec.feature 'assignment submission when student' do&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::create assignments for submission&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:each) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::capybara steps to login&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;after(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::delete assignments created&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;scenario 'submits only valid link to ongoing assignment' do&amp;lt;/b&amp;gt;&lt;br /&gt;
::mock steps using capybara&lt;br /&gt;
::make assertions&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sample Scenario====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
require 'assignment_setup'&lt;br /&gt;
&lt;br /&gt;
RSpec.feature 'assignment submission when student' do&lt;br /&gt;
&lt;br /&gt;
  active_assignment=&amp;quot;FeatureTest&amp;quot;&lt;br /&gt;
  expired_assignment=&amp;quot;LibraryRailsApp&amp;quot;&lt;br /&gt;
  d = Date.parse(Time.now.to_s)&lt;br /&gt;
  due_date1=(d &amp;gt;&amp;gt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
  due_date2=(d &amp;lt;&amp;lt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  # Before all block runs once before all the scenarios are tested&lt;br /&gt;
  before(:all) do&lt;br /&gt;
    # Create active/ongoing assignment&lt;br /&gt;
    create_assignment(active_assignment, due_date1)&lt;br /&gt;
&lt;br /&gt;
    # Create expired/finished assignment&lt;br /&gt;
    create_assignment(expired_assignment, due_date2)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Before each block runs before every scenario&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    # Login as a student before each scenario&lt;br /&gt;
    visit root_path&lt;br /&gt;
    fill_in 'User Name', :with =&amp;gt; 'student13'&lt;br /&gt;
    fill_in 'Password', :with =&amp;gt; 'password'&lt;br /&gt;
    click_on 'SIGN IN'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # After all block runs after all the scenarios are tested&lt;br /&gt;
  after(:all)do&lt;br /&gt;
    # Delete active/ongoing assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(active_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
&lt;br /&gt;
    # Delete expired/finished assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(expired_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Scenario to check whether student is able to submit valid link to an ongoing assignment&lt;br /&gt;
  scenario 'submits only valid link to ongoing assignment' do&lt;br /&gt;
    click_on active_assignment&lt;br /&gt;
    click_on 'Your work'&lt;br /&gt;
    fill_in 'submission', :with =&amp;gt; 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
    click_on 'Upload link'&lt;br /&gt;
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ mkdir review&lt;br /&gt;
$ cd review&lt;br /&gt;
$ git clone https://github.com/shrenujgandhi/expertiza.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case you don't have a database with student and instructor entries then download the dump from https://drive.google.com/a/ncsu.edu/file/d/0B2vDvVjH76uESEkzSWpJRnhGbmc/view. Extract its contents.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:create:all&lt;br /&gt;
$ cd Downloads/&lt;br /&gt;
$ mysql -u root -p expertiza_development &amp;lt; expertiza_scrubbed_2015_08_14.sql&lt;br /&gt;
password:&lt;br /&gt;
&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:migrate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/student_submission_spec.rb &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:test_result_temp2_expertiza.jpg|Feature Test Result]]&lt;br /&gt;
&lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* ''7 examples, 0 failures'' imply that there are 7 test scenarios and none of them failed.&lt;br /&gt;
* The tests take around 35 seconds to run, which implies that they are fast.&lt;br /&gt;
* They are also repeatable as the assignments that are created in the ''before all'' block are also deleted in the ''after all'' block.&lt;br /&gt;
* They are also self-verifying as all the results are in green, which mean that all the cases passed.&lt;br /&gt;
&lt;br /&gt;
=== Existing Bugs ===&lt;br /&gt;
During the course of our testing, we encountered two potential bugs in the Expertiza system. These are:&lt;br /&gt;
# A student can upload file even after the assignment is finished.&lt;br /&gt;
# A student can upload an .exe file to any assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following screenshots show these bugs on the current version of Expertiza used by the batch of Fall 2015.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:one_screenshot_expertiza.jpg|List of Assignments in Expertiza with Current Stage]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows the list of assignments along with their current stage in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:two_screenshot_expertiza.jpg|Select file for finished assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can select a file in a finished assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:three_screenshot_expertiza.jpg|Uploaded file for finished assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can upload a file in a finished assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:four_screenshot_expertiza.jpg|Select .exe file for ongoing assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can select an .exe file in any assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:five_screenshot_expertiza.jpg|Uploaded .exe file for ongoing assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can upload an .exe file in any assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Future Work ===&lt;br /&gt;
&lt;br /&gt;
* To prevent students from uploading a file to a finished assignment, like the upload link button, remove the upload file button.&lt;br /&gt;
* Executable files can sometimes be a part of the assignment. To there needs to be a check while creating the assignment whether .exe files are allowed or not.&lt;br /&gt;
* To run the test on test database using factories and fixtures, so that the tests are completely independent.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/shrenujgandhi/expertiza GitHub Link]&lt;br /&gt;
# [https://youtu.be/_58l0VPy04M YouTube Demo]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100950</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100950"/>
		<updated>2016-03-18T21:03:42Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is to Functional tests for Calibration function. &lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The instructor does expert reviews first, then after students review calibration assignments and submit peer review results, they can check the expert review. Instructor can check &amp;quot;calibration results&amp;quot; to check the calibration results of the whole class. Currently, there is no feature test for calibration function. The goal is to understand the flow of the calibration function by mock this flow in the '''Feature Tests''' using '''RSpec''' and '''Capybara''' framework.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the functionality from users perspective. '''Feature spec''' allows testing of your application's functionality from the outside either by simulating a browser or by headless browser simulation. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.&lt;br /&gt;
&lt;br /&gt;
===Assumptions===&lt;br /&gt;
To successfully implement each scenario in the test, the following assumptions are taken:&lt;br /&gt;
# The feature test will use the development environment. In particular, it will use the '''expertiza_development''' database.&lt;br /&gt;
# An instructor entry is assumed to be present in the database. The credentials for this instructor is '''instructor6''' as username and '''password''' as password.&lt;br /&gt;
# A student entry is also assumed to be present in the database. The credentials for this student is '''student13''' as username and '''password''' as password.&lt;br /&gt;
# The assignment created for testing contain no teams and topic for selection.&lt;br /&gt;
&lt;br /&gt;
===Steps for manual submission===&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in assignment submission by student on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid student username and password&lt;br /&gt;
# Click on an assignment to submit&lt;br /&gt;
# Click on &amp;quot;Your Work&amp;quot;&lt;br /&gt;
# Paste the link or browse to the file containing your work&lt;br /&gt;
# Click on &amp;quot;Upload Link&amp;quot; or &amp;quot;Upload File&amp;quot; to submit deliverable&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
The gems used in feature testing are '''rspec-rails''' and '''capybara'''&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
Based on the steps involved in manual submission of the assignment, the following test scenarios are considered:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to login&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have text content &amp;lt;b&amp;gt;Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to submit valid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit invalid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;http://&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should display flash message with text &amp;lt;b&amp;gt;URI is not valid&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit valid link to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Page should not have &amp;lt;b&amp;gt;Upload link&amp;lt;/b&amp;gt; button&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able upload file to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the feature test consist in two files:&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/assignment_setup.rb assignment_setup.rb] which contains method for creating assignments using controller calls.&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/features/student_submission_spec.rb student_assignment_submission.rb] which contain calls to assignment_setup, scenarios to test assignment submission and commands to delete the created assignments. &lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;require&amp;lt;/b&amp;gt; files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RSpec.feature 'assignment submission when student' do&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::create assignments for submission&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:each) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::capybara steps to login&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;after(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::delete assignments created&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;scenario 'submits only valid link to ongoing assignment' do&amp;lt;/b&amp;gt;&lt;br /&gt;
::mock steps using capybara&lt;br /&gt;
::make assertions&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sample Scenario====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
require 'assignment_setup'&lt;br /&gt;
&lt;br /&gt;
RSpec.feature 'assignment submission when student' do&lt;br /&gt;
&lt;br /&gt;
  active_assignment=&amp;quot;FeatureTest&amp;quot;&lt;br /&gt;
  expired_assignment=&amp;quot;LibraryRailsApp&amp;quot;&lt;br /&gt;
  d = Date.parse(Time.now.to_s)&lt;br /&gt;
  due_date1=(d &amp;gt;&amp;gt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
  due_date2=(d &amp;lt;&amp;lt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  # Before all block runs once before all the scenarios are tested&lt;br /&gt;
  before(:all) do&lt;br /&gt;
    # Create active/ongoing assignment&lt;br /&gt;
    create_assignment(active_assignment, due_date1)&lt;br /&gt;
&lt;br /&gt;
    # Create expired/finished assignment&lt;br /&gt;
    create_assignment(expired_assignment, due_date2)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Before each block runs before every scenario&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    # Login as a student before each scenario&lt;br /&gt;
    visit root_path&lt;br /&gt;
    fill_in 'User Name', :with =&amp;gt; 'student13'&lt;br /&gt;
    fill_in 'Password', :with =&amp;gt; 'password'&lt;br /&gt;
    click_on 'SIGN IN'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # After all block runs after all the scenarios are tested&lt;br /&gt;
  after(:all)do&lt;br /&gt;
    # Delete active/ongoing assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(active_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
&lt;br /&gt;
    # Delete expired/finished assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(expired_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Scenario to check whether student is able to submit valid link to an ongoing assignment&lt;br /&gt;
  scenario 'submits only valid link to ongoing assignment' do&lt;br /&gt;
    click_on active_assignment&lt;br /&gt;
    click_on 'Your work'&lt;br /&gt;
    fill_in 'submission', :with =&amp;gt; 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
    click_on 'Upload link'&lt;br /&gt;
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ mkdir review&lt;br /&gt;
$ cd review&lt;br /&gt;
$ git clone https://github.com/shrenujgandhi/expertiza.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case you don't have a database with student and instructor entries then download the dump from https://drive.google.com/a/ncsu.edu/file/d/0B2vDvVjH76uESEkzSWpJRnhGbmc/view. Extract its contents.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:create:all&lt;br /&gt;
$ cd Downloads/&lt;br /&gt;
$ mysql -u root -p expertiza_development &amp;lt; expertiza_scrubbed_2015_08_14.sql&lt;br /&gt;
password:&lt;br /&gt;
&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:migrate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/student_submission_spec.rb &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:test_result_temp2_expertiza.jpg|Feature Test Result]]&lt;br /&gt;
&lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* ''7 examples, 0 failures'' imply that there are 7 test scenarios and none of them failed.&lt;br /&gt;
* The tests take around 35 seconds to run, which implies that they are fast.&lt;br /&gt;
* They are also repeatable as the assignments that are created in the ''before all'' block are also deleted in the ''after all'' block.&lt;br /&gt;
* They are also self-verifying as all the results are in green, which mean that all the cases passed.&lt;br /&gt;
&lt;br /&gt;
=== Existing Bugs ===&lt;br /&gt;
During the course of our testing, we encountered two potential bugs in the Expertiza system. These are:&lt;br /&gt;
# A student can upload file even after the assignment is finished.&lt;br /&gt;
# A student can upload an .exe file to any assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following screenshots show these bugs on the current version of Expertiza used by the batch of Fall 2015.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:one_screenshot_expertiza.jpg|List of Assignments in Expertiza with Current Stage]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows the list of assignments along with their current stage in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:two_screenshot_expertiza.jpg|Select file for finished assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can select a file in a finished assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:three_screenshot_expertiza.jpg|Uploaded file for finished assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can upload a file in a finished assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:four_screenshot_expertiza.jpg|Select .exe file for ongoing assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can select an .exe file in any assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:five_screenshot_expertiza.jpg|Uploaded .exe file for ongoing assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can upload an .exe file in any assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Future Work ===&lt;br /&gt;
&lt;br /&gt;
* To prevent students from uploading a file to a finished assignment, like the upload link button, remove the upload file button.&lt;br /&gt;
* Executable files can sometimes be a part of the assignment. To there needs to be a check while creating the assignment whether .exe files are allowed or not.&lt;br /&gt;
* To run the test on test database using factories and fixtures, so that the tests are completely independent.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/shrenujgandhi/expertiza GitHub Link]&lt;br /&gt;
# [https://youtu.be/_58l0VPy04M YouTube Demo]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100949</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100949"/>
		<updated>2016-03-18T20:54:35Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Introduction */ update on introduction&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is to Functional tests for Calibration function. &lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
Once an assignment is created by the instructor the only call to action for the student is to submit the assignment. Currently, there is no feature test for assignment submission. The goal is to understand the flow of the assignment submission by student manually and mock this flow in the '''Feature Tests''' using '''RSpec''' and '''Capybara''' framework.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the functionality from users perspective. '''Feature spec''' allows testing of your application's functionality from the outside either by simulating a browser or by headless browser simulation. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.&lt;br /&gt;
&lt;br /&gt;
===Assumptions===&lt;br /&gt;
To successfully implement each scenario in the test, the following assumptions are taken:&lt;br /&gt;
# The feature test will use the development environment. In particular, it will use the '''expertiza_development''' database.&lt;br /&gt;
# An instructor entry is assumed to be present in the database. The credentials for this instructor is '''instructor6''' as username and '''password''' as password.&lt;br /&gt;
# A student entry is also assumed to be present in the database. The credentials for this student is '''student13''' as username and '''password''' as password.&lt;br /&gt;
# The assignment created for testing contain no teams and topic for selection.&lt;br /&gt;
&lt;br /&gt;
===Steps for manual submission===&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in assignment submission by student on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid student username and password&lt;br /&gt;
# Click on an assignment to submit&lt;br /&gt;
# Click on &amp;quot;Your Work&amp;quot;&lt;br /&gt;
# Paste the link or browse to the file containing your work&lt;br /&gt;
# Click on &amp;quot;Upload Link&amp;quot; or &amp;quot;Upload File&amp;quot; to submit deliverable&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
The gems used in feature testing are '''rspec-rails''' and '''capybara'''&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
Based on the steps involved in manual submission of the assignment, the following test scenarios are considered:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to login&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have text content &amp;lt;b&amp;gt;Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to submit valid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit invalid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;http://&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should display flash message with text &amp;lt;b&amp;gt;URI is not valid&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit valid link to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Page should not have &amp;lt;b&amp;gt;Upload link&amp;lt;/b&amp;gt; button&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able upload file to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the feature test consist in two files:&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/assignment_setup.rb assignment_setup.rb] which contains method for creating assignments using controller calls.&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/features/student_submission_spec.rb student_assignment_submission.rb] which contain calls to assignment_setup, scenarios to test assignment submission and commands to delete the created assignments. &lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;require&amp;lt;/b&amp;gt; files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RSpec.feature 'assignment submission when student' do&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::create assignments for submission&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:each) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::capybara steps to login&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;after(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::delete assignments created&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;scenario 'submits only valid link to ongoing assignment' do&amp;lt;/b&amp;gt;&lt;br /&gt;
::mock steps using capybara&lt;br /&gt;
::make assertions&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sample Scenario====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
require 'assignment_setup'&lt;br /&gt;
&lt;br /&gt;
RSpec.feature 'assignment submission when student' do&lt;br /&gt;
&lt;br /&gt;
  active_assignment=&amp;quot;FeatureTest&amp;quot;&lt;br /&gt;
  expired_assignment=&amp;quot;LibraryRailsApp&amp;quot;&lt;br /&gt;
  d = Date.parse(Time.now.to_s)&lt;br /&gt;
  due_date1=(d &amp;gt;&amp;gt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
  due_date2=(d &amp;lt;&amp;lt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  # Before all block runs once before all the scenarios are tested&lt;br /&gt;
  before(:all) do&lt;br /&gt;
    # Create active/ongoing assignment&lt;br /&gt;
    create_assignment(active_assignment, due_date1)&lt;br /&gt;
&lt;br /&gt;
    # Create expired/finished assignment&lt;br /&gt;
    create_assignment(expired_assignment, due_date2)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Before each block runs before every scenario&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    # Login as a student before each scenario&lt;br /&gt;
    visit root_path&lt;br /&gt;
    fill_in 'User Name', :with =&amp;gt; 'student13'&lt;br /&gt;
    fill_in 'Password', :with =&amp;gt; 'password'&lt;br /&gt;
    click_on 'SIGN IN'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # After all block runs after all the scenarios are tested&lt;br /&gt;
  after(:all)do&lt;br /&gt;
    # Delete active/ongoing assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(active_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
&lt;br /&gt;
    # Delete expired/finished assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(expired_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Scenario to check whether student is able to submit valid link to an ongoing assignment&lt;br /&gt;
  scenario 'submits only valid link to ongoing assignment' do&lt;br /&gt;
    click_on active_assignment&lt;br /&gt;
    click_on 'Your work'&lt;br /&gt;
    fill_in 'submission', :with =&amp;gt; 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
    click_on 'Upload link'&lt;br /&gt;
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ mkdir review&lt;br /&gt;
$ cd review&lt;br /&gt;
$ git clone https://github.com/shrenujgandhi/expertiza.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case you don't have a database with student and instructor entries then download the dump from https://drive.google.com/a/ncsu.edu/file/d/0B2vDvVjH76uESEkzSWpJRnhGbmc/view. Extract its contents.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:create:all&lt;br /&gt;
$ cd Downloads/&lt;br /&gt;
$ mysql -u root -p expertiza_development &amp;lt; expertiza_scrubbed_2015_08_14.sql&lt;br /&gt;
password:&lt;br /&gt;
&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:migrate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/student_submission_spec.rb &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:test_result_temp2_expertiza.jpg|Feature Test Result]]&lt;br /&gt;
&lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* ''7 examples, 0 failures'' imply that there are 7 test scenarios and none of them failed.&lt;br /&gt;
* The tests take around 35 seconds to run, which implies that they are fast.&lt;br /&gt;
* They are also repeatable as the assignments that are created in the ''before all'' block are also deleted in the ''after all'' block.&lt;br /&gt;
* They are also self-verifying as all the results are in green, which mean that all the cases passed.&lt;br /&gt;
&lt;br /&gt;
=== Existing Bugs ===&lt;br /&gt;
During the course of our testing, we encountered two potential bugs in the Expertiza system. These are:&lt;br /&gt;
# A student can upload file even after the assignment is finished.&lt;br /&gt;
# A student can upload an .exe file to any assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following screenshots show these bugs on the current version of Expertiza used by the batch of Fall 2015.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:one_screenshot_expertiza.jpg|List of Assignments in Expertiza with Current Stage]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows the list of assignments along with their current stage in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:two_screenshot_expertiza.jpg|Select file for finished assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can select a file in a finished assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:three_screenshot_expertiza.jpg|Uploaded file for finished assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can upload a file in a finished assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:four_screenshot_expertiza.jpg|Select .exe file for ongoing assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can select an .exe file in any assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:five_screenshot_expertiza.jpg|Uploaded .exe file for ongoing assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can upload an .exe file in any assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Future Work ===&lt;br /&gt;
&lt;br /&gt;
* To prevent students from uploading a file to a finished assignment, like the upload link button, remove the upload file button.&lt;br /&gt;
* Executable files can sometimes be a part of the assignment. To there needs to be a check while creating the assignment whether .exe files are allowed or not.&lt;br /&gt;
* To run the test on test database using factories and fixtures, so that the tests are completely independent.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/shrenujgandhi/expertiza GitHub Link]&lt;br /&gt;
# [https://youtu.be/_58l0VPy04M YouTube Demo]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100948</id>
		<title>User:Ewhorton</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ewhorton&amp;diff=100948"/>
		<updated>2016-03-18T20:38:33Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: Created page with &amp;quot;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by ...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Expertiza''' is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our contribution to this project is toFunctional tests for Calibration function. The tests would mock steps taken by the student when he/she manually submit the assignment.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
Once an assignment is created by the instructor the only call to action for the student is to submit the assignment. Currently, there is no feature test for assignment submission. The goal is to understand the flow of the assignment submission by student manually and mock this flow in the '''Feature Tests''' using '''RSpec''' and '''Capybara''' framework.&lt;br /&gt;
&lt;br /&gt;
===Motivation===&lt;br /&gt;
Once the application is built, it is necessary to test its functionality. More importantly, it is essential to test the functionality from users perspective. '''Feature spec''' allows testing of your application's functionality from the outside either by simulating a browser or by headless browser simulation. By manually clicking on the interface, the tests can discover bugs in the system and so has ours.&lt;br /&gt;
&lt;br /&gt;
===Assumptions===&lt;br /&gt;
To successfully implement each scenario in the test, the following assumptions are taken:&lt;br /&gt;
# The feature test will use the development environment. In particular, it will use the '''expertiza_development''' database.&lt;br /&gt;
# An instructor entry is assumed to be present in the database. The credentials for this instructor is '''instructor6''' as username and '''password''' as password.&lt;br /&gt;
# A student entry is also assumed to be present in the database. The credentials for this student is '''student13''' as username and '''password''' as password.&lt;br /&gt;
# The assignment created for testing contain no teams and topic for selection.&lt;br /&gt;
&lt;br /&gt;
===Steps for manual submission===&lt;br /&gt;
Before analyzing code, one must familiarize themselves with the steps involved in assignment submission by student on Expertiza. The steps involved are:&lt;br /&gt;
# Login with valid student username and password&lt;br /&gt;
# Click on an assignment to submit&lt;br /&gt;
# Click on &amp;quot;Your Work&amp;quot;&lt;br /&gt;
# Paste the link or browse to the file containing your work&lt;br /&gt;
# Click on &amp;quot;Upload Link&amp;quot; or &amp;quot;Upload File&amp;quot; to submit deliverable&lt;br /&gt;
&lt;br /&gt;
== Creating the Tests==&lt;br /&gt;
&lt;br /&gt;
===Gems involved===&lt;br /&gt;
The gems used in feature testing are '''rspec-rails''' and '''capybara'''&lt;br /&gt;
&lt;br /&gt;
====rspec-rails====&lt;br /&gt;
Rspec-rails is a testing framework for Rails 3.x and 4.x. It supports testing of models, controllers, requests, features, views and routes. It does this by accepting test scenarios called specs.&amp;lt;ref&amp;gt;[https://github.com/rspec/rspec-rails rpsce-rails on GitHub]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====capybara====&lt;br /&gt;
Capybara helps you test web applications by simulating how a real user would interact with your application. It comes with built in Rack::Test and Selenium support. WebKit is supported through an external gem.&amp;lt;ref&amp;gt;[https://github.com/jnicklas/capybara capybara on GitHub]&amp;lt;/ref&amp;gt; To control the environments in which the scenarios are run, it provides before and after hooks.&amp;lt;ref&amp;gt;[https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks Before and after hooks]&amp;lt;/ref&amp;gt;&lt;br /&gt;
*before(:each) blocks are run before each scenario in the group&lt;br /&gt;
*before(:all) blocks are run once before all of the scenarios in the group&lt;br /&gt;
*after(:each) blocks are run after each scenario in the group &lt;br /&gt;
*after(:all) blocks are run once after all of the scenarios in the group&lt;br /&gt;
&lt;br /&gt;
===Test Scenarios===&lt;br /&gt;
Based on the steps involved in manual submission of the assignment, the following test scenarios are considered:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to login&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have text content &amp;lt;b&amp;gt;Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to submit valid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit invalid link to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;http://&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should display flash message with text &amp;lt;b&amp;gt;URI is not valid&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able to upload valid link and a file to an ongoing assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;OnGoing Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should have link &amp;lt;b&amp;gt;&amp;lt;nowiki&amp;gt;http://www.csc.ncsu.edu/faculty/efg/517/f15/assignments&amp;lt;/nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;users_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is not able submit valid link to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Page should not have &amp;lt;b&amp;gt;Upload link&amp;lt;/b&amp;gt; button&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:20px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
Scenario to check whether student is able upload file to a finished assignment&amp;lt;br&amp;gt;&lt;br /&gt;
:Login with &amp;lt;b&amp;gt;student13&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;password&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Sign In&amp;lt;/b&amp;gt; button&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Finished Assignment&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Click on &amp;lt;b&amp;gt;Your work&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Upload file &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
:Updated page should contain filename &amp;lt;b&amp;gt;student_submission_spec.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code=== &lt;br /&gt;
Code for the feature test consist in two files:&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/assignment_setup.rb assignment_setup.rb] which contains method for creating assignments using controller calls.&lt;br /&gt;
* [https://github.com/shrenujgandhi/expertiza/blob/master/spec/features/student_submission_spec.rb student_assignment_submission.rb] which contain calls to assignment_setup, scenarios to test assignment submission and commands to delete the created assignments. &lt;br /&gt;
&lt;br /&gt;
====Structure====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;require&amp;lt;/b&amp;gt; files&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;RSpec.feature 'assignment submission when student' do&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::create assignments for submission&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;before(:each) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::capybara steps to login&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;after(:all) do&amp;lt;/b&amp;gt;&lt;br /&gt;
::delete assignments created&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;b&amp;gt;scenario 'submits only valid link to ongoing assignment' do&amp;lt;/b&amp;gt;&lt;br /&gt;
::mock steps using capybara&lt;br /&gt;
::make assertions&lt;br /&gt;
:&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
:....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Sample Scenario====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
require 'assignment_setup'&lt;br /&gt;
&lt;br /&gt;
RSpec.feature 'assignment submission when student' do&lt;br /&gt;
&lt;br /&gt;
  active_assignment=&amp;quot;FeatureTest&amp;quot;&lt;br /&gt;
  expired_assignment=&amp;quot;LibraryRailsApp&amp;quot;&lt;br /&gt;
  d = Date.parse(Time.now.to_s)&lt;br /&gt;
  due_date1=(d &amp;gt;&amp;gt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
  due_date2=(d &amp;lt;&amp;lt; 1).strftime(&amp;quot;%Y-%m-%d %H:%M:00&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  # Before all block runs once before all the scenarios are tested&lt;br /&gt;
  before(:all) do&lt;br /&gt;
    # Create active/ongoing assignment&lt;br /&gt;
    create_assignment(active_assignment, due_date1)&lt;br /&gt;
&lt;br /&gt;
    # Create expired/finished assignment&lt;br /&gt;
    create_assignment(expired_assignment, due_date2)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Before each block runs before every scenario&lt;br /&gt;
  before(:each) do&lt;br /&gt;
    # Login as a student before each scenario&lt;br /&gt;
    visit root_path&lt;br /&gt;
    fill_in 'User Name', :with =&amp;gt; 'student13'&lt;br /&gt;
    fill_in 'Password', :with =&amp;gt; 'password'&lt;br /&gt;
    click_on 'SIGN IN'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # After all block runs after all the scenarios are tested&lt;br /&gt;
  after(:all)do&lt;br /&gt;
    # Delete active/ongoing assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(active_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
&lt;br /&gt;
    # Delete expired/finished assignment created by the test&lt;br /&gt;
    assignment = Assignment.find_by_name(expired_assignment)&lt;br /&gt;
    assignment.delete&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Scenario to check whether student is able to submit valid link to an ongoing assignment&lt;br /&gt;
  scenario 'submits only valid link to ongoing assignment' do&lt;br /&gt;
    click_on active_assignment&lt;br /&gt;
    click_on 'Your work'&lt;br /&gt;
    fill_in 'submission', :with =&amp;gt; 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
    click_on 'Upload link'&lt;br /&gt;
    expect(page).to have_content 'http://www.csc.ncsu.edu/faculty/efg/517/f15/schedule'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running  the tests==&lt;br /&gt;
&lt;br /&gt;
The following are steps required to run the test&lt;br /&gt;
&lt;br /&gt;
* Clone the repository in a new directory&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ mkdir review&lt;br /&gt;
$ cd review&lt;br /&gt;
$ git clone https://github.com/shrenujgandhi/expertiza.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case you don't have a database with student and instructor entries then download the dump from https://drive.google.com/a/ncsu.edu/file/d/0B2vDvVjH76uESEkzSWpJRnhGbmc/view. Extract its contents.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:create:all&lt;br /&gt;
$ cd Downloads/&lt;br /&gt;
$ mysql -u root -p expertiza_development &amp;lt; expertiza_scrubbed_2015_08_14.sql&lt;br /&gt;
password:&lt;br /&gt;
&lt;br /&gt;
$ cd expertiza&lt;br /&gt;
$ rake db:migrate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Type the command to run tests for assignment submission&lt;br /&gt;
&amp;lt;pre style=&amp;quot;font-size:12.5px; width:750px; margin-top:10px; border:1px solid lightgrey; background:ivory; color:black; padding-left:15px; padding-top:15px; padding-bottom:15px;&amp;quot;&amp;gt;&lt;br /&gt;
rspec spec/features/student_submission_spec.rb &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Results==&lt;br /&gt;
&lt;br /&gt;
The following screenshot shows the result of the rspec command.&lt;br /&gt;
&lt;br /&gt;
[[File:test_result_temp2_expertiza.jpg|Feature Test Result]]&lt;br /&gt;
&lt;br /&gt;
=== Test Analysis ===&lt;br /&gt;
&lt;br /&gt;
* ''7 examples, 0 failures'' imply that there are 7 test scenarios and none of them failed.&lt;br /&gt;
* The tests take around 35 seconds to run, which implies that they are fast.&lt;br /&gt;
* They are also repeatable as the assignments that are created in the ''before all'' block are also deleted in the ''after all'' block.&lt;br /&gt;
* They are also self-verifying as all the results are in green, which mean that all the cases passed.&lt;br /&gt;
&lt;br /&gt;
=== Existing Bugs ===&lt;br /&gt;
During the course of our testing, we encountered two potential bugs in the Expertiza system. These are:&lt;br /&gt;
# A student can upload file even after the assignment is finished.&lt;br /&gt;
# A student can upload an .exe file to any assignment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following screenshots show these bugs on the current version of Expertiza used by the batch of Fall 2015.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:one_screenshot_expertiza.jpg|List of Assignments in Expertiza with Current Stage]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows the list of assignments along with their current stage in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:two_screenshot_expertiza.jpg|Select file for finished assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can select a file in a finished assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:three_screenshot_expertiza.jpg|Uploaded file for finished assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can upload a file in a finished assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:four_screenshot_expertiza.jpg|Select .exe file for ongoing assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can select an .exe file in any assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:five_screenshot_expertiza.jpg|Uploaded .exe file for ongoing assignment]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;'''Figure''': This screenshot shows that a student can upload an .exe file in any assignment in Expertiza.&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Future Work ===&lt;br /&gt;
&lt;br /&gt;
* To prevent students from uploading a file to a finished assignment, like the upload link button, remove the upload file button.&lt;br /&gt;
* Executable files can sometimes be a part of the assignment. To there needs to be a check while creating the assignment whether .exe files are allowed or not.&lt;br /&gt;
* To run the test on test database using factories and fixtures, so that the tests are completely independent.&lt;br /&gt;
&lt;br /&gt;
==Project Resources==&lt;br /&gt;
# [https://github.com/shrenujgandhi/expertiza GitHub Link]&lt;br /&gt;
# [https://youtu.be/_58l0VPy04M YouTube Demo]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=External links=&lt;br /&gt;
* [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Documentation]&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100933</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100933"/>
		<updated>2016-02-14T21:59:51Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Introduction''' ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts various queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletters, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is an interface which you can work with common queueing backends. &lt;br /&gt;
The reason to have Active Job in place is to make sure Rails apps can have a job infrastructure. Other existing gems can build on this framework without the limitation of API difference between different job runners such as Delayed Job and Resque. With this feature choosing queueing backends can become an operational concern. Also, switching between those queueing backends without rewrite jobs become possible.&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems[https://en.wikipedia.org/wiki/RubyGems] you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub[https://en.wikipedia.org/wiki/GitHub], as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting to carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and views need to be set in order to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher[https://rubygems.org/gems/mailcatcher/versions/0.6.1] is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''External links'''==&lt;br /&gt;
&lt;br /&gt;
*[http://www.rubyonrails.org/ Ruby on Rails official website] – rubyonrails.org&lt;br /&gt;
*[http://railscasts.com/ Railscasts.com] – (defunct) Short Screencasts that focus on Ruby on Rails technique&lt;br /&gt;
*[http://rubycasts.io/ Rubycasts.io] – Weekly 15 minute screencasts on the whole Ruby/Rails development stack&lt;br /&gt;
*[http://www.railstutorial.org/ The Rails Tutorial] – The Ruby on Rails Tutorial book and screencast series teach you how to develop and deploy Ruby on Rails apps&lt;br /&gt;
*[https://github.com/rails/rails Rails source code]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100932</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100932"/>
		<updated>2016-02-14T21:59:02Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* External links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts various queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletters, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is an interface which you can work with common queueing backends. &lt;br /&gt;
The reason to have Active Job in place is to make sure Rails apps can have a job infrastructure. Other existing gems can build on this framework without the limitation of API difference between different job runners such as Delayed Job and Resque. With this feature choosing queueing backends can become an operational concern. Also, switching between those queueing backends without rewrite jobs become possible.&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems[https://en.wikipedia.org/wiki/RubyGems] you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub[https://en.wikipedia.org/wiki/GitHub], as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting to carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and views need to be set in order to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher[https://rubygems.org/gems/mailcatcher/versions/0.6.1] is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
&lt;br /&gt;
*[http://www.rubyonrails.org/ Ruby on Rails official website] – rubyonrails.org&lt;br /&gt;
*[http://railscasts.com/ Railscasts.com] – (defunct) Short Screencasts that focus on Ruby on Rails technique&lt;br /&gt;
*[http://rubycasts.io/ Rubycasts.io] – Weekly 15 minute screencasts on the whole Ruby/Rails development stack&lt;br /&gt;
*[http://www.railstutorial.org/ The Rails Tutorial] – The Ruby on Rails Tutorial book and screencast series teach you how to develop and deploy Ruby on Rails apps&lt;br /&gt;
*[https://github.com/rails/rails Rails source code]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100931</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100931"/>
		<updated>2016-02-14T21:58:46Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts various queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletters, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is an interface which you can work with common queueing backends. &lt;br /&gt;
The reason to have Active Job in place is to make sure Rails apps can have a job infrastructure. Other existing gems can build on this framework without the limitation of API difference between different job runners such as Delayed Job and Resque. With this feature choosing queueing backends can become an operational concern. Also, switching between those queueing backends without rewrite jobs become possible.&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems[https://en.wikipedia.org/wiki/RubyGems] you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub[https://en.wikipedia.org/wiki/GitHub], as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting to carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and views need to be set in order to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher[https://rubygems.org/gems/mailcatcher/versions/0.6.1] is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
&lt;br /&gt;
{{Wikibooks|Ruby on Rails}}&lt;br /&gt;
*[http://www.rubyonrails.org/ Ruby on Rails official website] – rubyonrails.org&lt;br /&gt;
*[http://railscasts.com/ Railscasts.com] – (defunct) Short Screencasts that focus on Ruby on Rails technique&lt;br /&gt;
*[http://rubycasts.io/ Rubycasts.io] – Weekly 15 minute screencasts on the whole Ruby/Rails development stack&lt;br /&gt;
*[http://www.railstutorial.org/ The Rails Tutorial] – The Ruby on Rails Tutorial book and screencast series teach you how to develop and deploy Ruby on Rails apps&lt;br /&gt;
*[https://github.com/rails/rails Rails source code]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100930</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100930"/>
		<updated>2016-02-14T21:53:18Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts various queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletters, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is an interface which you can work with common queueing backends. &lt;br /&gt;
The reason to have Active Job in place is to make sure Rails apps can have a job infrastructure. Other existing gems can build on this framework without the limitation of API difference between different job runners such as Delayed Job and Resque. With this feature choosing queueing backends can become an operational concern. Also, switching between those queueing backends without rewrite jobs become possible.&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems[https://en.wikipedia.org/wiki/RubyGems] you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub[https://en.wikipedia.org/wiki/GitHub], as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting to carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and views need to be set in order to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher[https://rubygems.org/gems/mailcatcher/versions/0.6.1] is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100929</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100929"/>
		<updated>2016-02-14T21:52:55Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts various queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletters, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is an interface which you can work with common queueing backends.&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; &lt;br /&gt;
The reason to have Active Job in place is to make sure Rails apps can have a job infrastructure. Other existing gems can build on this framework without the limitation of API difference between different job runners such as Delayed Job and Resque. With this feature choosing queueing backends can become an operational concern. Also, switching between those queueing backends without rewrite jobs become possible.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems[https://en.wikipedia.org/wiki/RubyGems] you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub[https://en.wikipedia.org/wiki/GitHub], as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting to carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and views need to be set in order to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher[https://rubygems.org/gems/mailcatcher/versions/0.6.1] is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100928</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100928"/>
		<updated>2016-02-14T21:52:20Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Introduction */ introduction update&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts various queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletters, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is an interface which you can work with common queueing backends.&lt;br /&gt;
The reason to have Active Job in place is to make sure Rails apps can have a job infrastructure. Other existing gems can build on this framework without the limitation of API difference between different job runners such as Delayed Job and Resque. With this feature choosing queueing backends can become an operational concern. Also, switching between those queueing backends without rewrite jobs become possible.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems[https://en.wikipedia.org/wiki/RubyGems] you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub[https://en.wikipedia.org/wiki/GitHub], as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting to carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and views need to be set in order to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher[https://rubygems.org/gems/mailcatcher/versions/0.6.1] is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100927</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100927"/>
		<updated>2016-02-14T21:30:50Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* 5. Try execution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts various queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletters, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is an interface which you can work with common queueing backends.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems[https://en.wikipedia.org/wiki/RubyGems] you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub[https://en.wikipedia.org/wiki/GitHub], as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting to carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and views need to be set in order to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher[https://rubygems.org/gems/mailcatcher/versions/0.6.1] is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100873</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100873"/>
		<updated>2016-02-12T21:56:44Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Create a Job */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts various queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletters, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is an interface which you can work with common queueing backends.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems[https://en.wikipedia.org/wiki/RubyGems] you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub[https://en.wikipedia.org/wiki/GitHub], as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting to carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and views need to be set in order to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100872</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100872"/>
		<updated>2016-02-12T21:56:04Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts various queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletters, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is an interface which you can work with common queueing backends.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems[https://en.wikipedia.org/wiki/RubyGems] you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub[https://en.wikipedia.org/wiki/GitHub], as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting for carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and views need to be set in order to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100871</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100871"/>
		<updated>2016-02-12T21:52:25Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* 4. Active JobRails Guides “Active Job Basics” 2014 */ grammar correction&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts different queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletter, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is a interface which you can work with common queues.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems[https://en.wikipedia.org/wiki/RubyGems] you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub[https://en.wikipedia.org/wiki/GitHub], as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting for carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and views need to be set in order to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100870</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100870"/>
		<updated>2016-02-12T21:51:02Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Download */ github link added&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts different queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletter, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is a interface which you can work with common queues.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems[https://en.wikipedia.org/wiki/RubyGems] you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub[https://en.wikipedia.org/wiki/GitHub], as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting for carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and view need to set to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100869</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100869"/>
		<updated>2016-02-12T21:50:18Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Download */ RubyGem link added&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts different queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletter, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is a interface which you can work with common queues.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems[https://en.wikipedia.org/wiki/RubyGems] you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub, as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting for carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and view need to set to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100868</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100868"/>
		<updated>2016-02-12T21:49:15Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* How to use http://guides.rubyonrails.org/active_job_basics.html */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts different queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletter, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is a interface which you can work with common queues.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to create a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub, as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting for carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and view need to set to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100867</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100867"/>
		<updated>2016-02-12T21:48:58Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers to write codes and run them on the background automatically under different scenarios. It’s an interface that adapts different queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletter, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is a interface which you can work with common queues.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to creating a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub, as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting for carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and view need to set to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100866</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100866"/>
		<updated>2016-02-12T21:47:47Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* 5. Try execution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers writing codes and run them on the background automatically under different scenarios. It’s an interface that adapts different queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletter, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is a interface which you can work with common queues.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to creating a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub, as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting for carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and view need to set to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before trying the Mailer, MailCatcher is needed for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, one need to add the following into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser and visit localhost:3000/users/new. Then sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100865</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100865"/>
		<updated>2016-02-12T21:46:12Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Examples */ grammar correction&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers writing codes and run them on the background automatically under different scenarios. It’s an interface that adapts different queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletter, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is a interface which you can work with common queues.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to creating a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub, as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting for carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
Send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
This example uses [https://github.com/resque/resque Resque] as the enqueuing backend. It'll need  [http://redis.io/ Redis] before running Resque. Redis can be installed using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or  download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but it can be found  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now a UserController is in place to put the job into the queue for later execution. Set the email to be sent one minute later for testing.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and view need to set to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before we try the Mailer, we need MailCatcher for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, add following things into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser, visit localhost:3000/users/new and sign up as a new user. One minute later Resque scheduler has following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100864</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100864"/>
		<updated>2016-02-12T21:42:30Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: grammar error correction&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers writing codes and run them on the background automatically under different scenarios. It’s an interface that adapts different queueing backends like [https://github.com/nesquena/backburner Backburner], [https://github.com/collectiveidea/delayed_job Delayed Job], [https://github.com/bkeepers/qu Qu] and so on. Jobs can vary from schedule newsletter, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is a interface which you can work with common queues.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
This chapter is an introduction on how to creating a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub, as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting for carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
Enqueue the Job so it can be processed as soon as the queuing system is free:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, this example uses the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Control a job to run on a queue by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
You can send emails asynchronously with Action Mailer which Active Job is already integrated in.&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
We will use [https://github.com/resque/resque Resque] as the enqueuing backend. You need to install [http://redis.io/ Redis] before you can run Resque. You can get Redis using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft [https://en.wikipedia.org/wiki/Microsoft_Windows Windows] platform, but you can find  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we can use a UserController to put the job into the queue for later execution. Here we set the email to be sent one minute later for test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and view need to set to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before we try the Mailer, we need MailCatcher for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, add following things into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser, visit localhost:3000/users/new and sign up as a new user. One minute later you can see following in Resque scheduler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100759</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100759"/>
		<updated>2016-02-06T02:41:45Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers writing codes and run them on the background automatically under different scenarios. It’s an interface that adapts different queueing backends like Backburner[https://github.com/nesquena/backburner], Delayed Job[https://github.com/collectiveidea/delayed_job], Qu[https://github.com/bkeepers/qu] and so on. Jobs can vary from schedule newsletter, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is a interface which you can work with common queues.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
We will introduce how to creating a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub, as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting for carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
If you wish your Job be processed as soon as the queuing system is free, you can enqueue a Job like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you want your Job be performed a week from now, most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, in this example we use the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can control a job to run on a queue you like, by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, a example is provided to demonstrate how to use ActiveJob in practice.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
You can send emails asynchronously with Action Mailer which Active Job is already integrated in&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt;. Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
We will use [https://github.com/resque/resque Resque] as the enqueuing backend. You need to install [http://redis.io/ Redis] before you can run Resque. You can get Redis using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft Windows[https://en.wikipedia.org/wiki/Microsoft_Windows] platform, but you can find  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we can use a UserController to put the job into the queue for later execution. Here we set the email to be sent one minute later for test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and view need to set to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before we try the Mailer, we need MailCatcher for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, add following things into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser, visit localhost:3000/users/new and sign up as a new user. One minute later you can see following in Resque scheduler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100756</id>
		<title>Active Job</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Active_Job&amp;diff=100756"/>
		<updated>2016-02-06T02:32:36Z</updated>

		<summary type="html">&lt;p&gt;Ychen71: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Active Job is a framework that helps developers writing codes and run them on the background automatically under different scenarios. It’s an interface that adapts different queueing backends like Backburner[https://github.com/nesquena/backburner], Delayed Job[https://github.com/collectiveidea/delayed_job], Qu[https://github.com/bkeepers/qu] and so on. Jobs can vary from schedule newsletter, follow-up emails to database housekeeping. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” ]&amp;lt;/ref&amp;gt; Overall, Active Job is a interface which you can work with common queues.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
====Ruby On Rails versions support Active Job====&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;float:left;&amp;quot;&lt;br /&gt;
|+ Version history&lt;br /&gt;
|-&lt;br /&gt;
! Version !! Date&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || 2014/12/19&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.5 || 2015/11/13&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
====Active Job adapters&amp;lt;ref name=&amp;quot;Active-Job-Adapter&amp;quot;&amp;gt;Active Job Adapter[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html&amp;quot;Active Job Adapter&amp;quot; ]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
List of queueing backends Active Job support:&lt;br /&gt;
*Backburner[https://github.com/nesquena/backburner]&lt;br /&gt;
*Delayed Job[https://github.com/collectiveidea/delayed_job]&lt;br /&gt;
*Qu[https://github.com/bkeepers/qu]&lt;br /&gt;
*Que[https://github.com/chanks/que]&lt;br /&gt;
*queue_classic[https://github.com/QueueClassic/queue_classic]&lt;br /&gt;
*Resque 1.x[https://github.com/resque/resque]&lt;br /&gt;
*Sidekiq[http://sidekiq.org/]&lt;br /&gt;
*Sneakers[https://github.com/jondot/sneakers]&lt;br /&gt;
*Sucker Punch[https://github.com/brandonhilkert/sucker_punch]&lt;br /&gt;
*Active Job Async Job&lt;br /&gt;
*Active Job Inline[http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html]&lt;br /&gt;
&lt;br /&gt;
=='''How to use &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/active_job_basics.html&amp;lt;/ref&amp;gt;'''==&lt;br /&gt;
We will introduce how to creating a job and and how to add the job into a queue. &amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
=== Download ===&lt;br /&gt;
With RubyGems you can install Active Job:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gem install activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/rails/rails/tree/master/activejob Souce code of Active Job] available on GitHub, as part of Rails.&amp;lt;ref&amp;gt; GitHub [https://github.com/rails/rails/tree/master/activejob “Active Job -- Make work happen later” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create a Job ===&lt;br /&gt;
In Active Job, a process inserted in a queue and waiting for carry out is called “Job”. It’s possible to generate a Job using the Generator provided by Rails. You can create a Job in app/jobs. By doing the following, we created a Job called “update_wiki”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki&lt;br /&gt;
  invoke  test_unit&lt;br /&gt;
  create  test/jobs/update_wiki_job_test.rb&lt;br /&gt;
  create  app/jobs/update_wiki_job.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Active Job provides the ability to run your Job on a specific queue by creating a job:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job update_wiki --queue urgent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Files inside of app/jobs can be created manually, instead of using a generator. In Rails 4.2 an ActiveJob class inherits from ActiveJob::Base. In Rails 5.0, it has changed to now inherit from ApplicationJob. When upgrading from Rails 4.2 to Rails 5.0, an application_job.rb file is needed to be created in app/jobs/ and add the following content:&amp;lt;ref&amp;gt; Rails Guides [http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 “A Guide for Upgrading Ruby on Rails” 2015] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationJob &amp;lt; ActiveJob::Base&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Rails 4.2 a Job class defined a perform method and set a “queue_as” value:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :default&lt;br /&gt;
 &lt;br /&gt;
  def perform(*wiki)&lt;br /&gt;
   # Do something later&lt;br /&gt;
  wiki.update_contents&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
There is a perform method to be called when the Job was first enqueued. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding a Job to the queue ===&lt;br /&gt;
If you wish your Job be processed as soon as the queuing system is free, you can enqueue a Job like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.perform_later wiki&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can add a Job be performed tomorrow at noon:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait_until: Date.tomorrow.noon).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you want your Job be performed a week from now, most of the queueing backends ( Sidekiq&lt;br /&gt;
, Delayed Job, etc. ) allow you to set a delay time.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UpdateWikiJob.set(wait: 1.week).perform_later(wiki)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Execution of Job ===&lt;br /&gt;
Active Job provides adapters for multiple queueing backends ([https://github.com/mperham/sidekiq/wiki Sidekiq], [https://github.com/resque/resque Resque], [https://github.com/collectiveidea/delayed_job Delayed Job] and [http://edgeapi.rubyonrails.org/classes/ActiveJob/QueueAdapters.html others]).&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt; Without setting any adapter, the job would be performed immediately.&amp;lt;br&amp;gt;&lt;br /&gt;
Queueing backend can be set at: /config/application.rb, in this example we use the Sidekiq.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    # Be sure to have the adapter's gem in your Gemfile and follow&lt;br /&gt;
    # the adapter's specific installation and deployment instructions.&lt;br /&gt;
    config.active_job.queue_adapter = :sidekiq&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Play with Queues ===&lt;br /&gt;
Active Job allows to schedule the job to be processed on a specific queue, this became helpful as common adapters support multiple queues.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Queue name can be prefixed for all jobs using config.active_job.queue_name_prefixin application.rb:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# config/application.rb&lt;br /&gt;
module YourApp&lt;br /&gt;
  class Application &amp;lt; Rails::Application&lt;br /&gt;
    config.active_job.queue_name_prefix = Rails.env&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# app/jobs/update_wiki_job.rb&lt;br /&gt;
class UpdateWikiJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :low_priority&lt;br /&gt;
  #....&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Now your job will run on queue production_low_priority on your&lt;br /&gt;
# production environment and on staging_low_priority on your staging&lt;br /&gt;
# environment&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can control a job to run on a queue you like, by passing a :queue option to #set :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyJob.set(queue: :another_queue).perform_later(record)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the code snippets are referred from the source&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
In this section, some examples are provided to demonstrate how to use ActiveJob in practices.&lt;br /&gt;
=== Background Mail Sender ===&lt;br /&gt;
You can send emails asynchronously with Action Mailer which Active Job is already integrated in&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt;. Here in this example, we try to use Active Job with Action Mailer.&amp;lt;br&amp;gt;&lt;br /&gt;
==== 1. Getting started with Rails&amp;lt;ref name= &amp;quot;Welcome_to_Rails&amp;quot;&amp;gt;GitHub [https://github.com/rails/rails “Welcome to Rails” 2015]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Install Rails if you haven’t done it yet:&lt;br /&gt;
$ gem install rails&lt;br /&gt;
&lt;br /&gt;
# Create a new Rails application, “myapp_activejob”&lt;br /&gt;
# is the name of the application:&lt;br /&gt;
$ rails new myapp_activejob&lt;br /&gt;
&lt;br /&gt;
# Change your directory to myapp_activejob&lt;br /&gt;
$ cd myapp_activejob&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit the Gemfile in the folder, add following into it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'responders'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run “ $ bundle update “ and make sure “$ rails server” works.&lt;br /&gt;
&lt;br /&gt;
==== 2. Resque setup&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
We will use [https://github.com/resque/resque Resque] as the enqueuing backend. You need to install [http://redis.io/ Redis] before you can run Resque. You can get Redis using [http://brew.sh/ Homebrew]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ brew install redis&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or you can download, extract and compile Redis using:&amp;lt;ref name= &amp;quot;Download_Redis&amp;quot;&amp;gt;Redis [http://redis.io/download “Download Redis” 2016]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz&lt;br /&gt;
$ tar xzf redis-3.0.7.tar.gz&lt;br /&gt;
$ cd redis-3.0.7&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Redis does not officially support Microsoft Windows[https://en.wikipedia.org/wiki/Microsoft_Windows] platform, but you can find  [https://github.com/MSOpenTech/redis Redis on Windows] by Microsoft Open Tech group.&amp;lt;br&amp;gt;&lt;br /&gt;
Next get Resque be installed. To use resque with Active Job, we also need resque-scheduler.&lt;br /&gt;
Add the following into Gemfile, and run “$ bundle install”.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'resque'&lt;br /&gt;
gem 'resque-scheduler'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the installation, create a Resque configuration file resque.rb in config/initializers/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/resque.rb&lt;br /&gt;
&lt;br /&gt;
Resque.redis = Redis.new(host: 'localhost', post: 6379)&lt;br /&gt;
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the Resque tasks and Resque Scheduler rake tasks are needed in this example, we need to create a resque.rake file in lib/tasks/:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#lib/tasks/resque.rake&lt;br /&gt;
&lt;br /&gt;
require 'resque/tasks'&lt;br /&gt;
require 'resque/scheduler/tasks'&lt;br /&gt;
&lt;br /&gt;
namespace :resque do&lt;br /&gt;
  task setup: :environment do&lt;br /&gt;
    ENV['TERM_CHILD'] ||= '1'&lt;br /&gt;
    ENV['QUEUE'] ||= '*'&lt;br /&gt;
    require 'resque'&lt;br /&gt;
    require 'resque-scheduler'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 3. Creating a Mailer&amp;lt;ref name= &amp;quot;Action-Mailer-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/action_mailer_basics.html “Action Mailer Basics” 2014]&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
By doing the things above, we already have our Rails project and the Resque for queuing get set. Next we will create a Mailer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate mailer user_mailer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a method and a view for sending the email.&amp;lt;br&amp;gt;&lt;br /&gt;
In app/mailer/user_mailer.rb:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/mailers/user_mailer.rb&lt;br /&gt;
&lt;br /&gt;
class UserMailer &amp;lt; ActionMailer::Base&lt;br /&gt;
  default from: 'from@example.com'&lt;br /&gt;
&lt;br /&gt;
  def test_email(email)&lt;br /&gt;
    mail(&lt;br /&gt;
      to: email,&lt;br /&gt;
      subject: 'We are testing Active Job!'&lt;br /&gt;
    )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In app/views/user_mailer/test_email.text&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/user_mailer/test_email.text&lt;br /&gt;
&lt;br /&gt;
Hey, we are testing Active Job!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 4. Active Job&amp;lt;ref name= &amp;quot;Active-Job-Basics&amp;quot;&amp;gt;Rails Guides [http://guides.rubyonrails.org/active_job_basics.html “Active Job Basics” 2014]&amp;lt;/ref&amp;gt;====&lt;br /&gt;
Create a configuration file active_job.rb in config/initializers/ , to set Resque as queue_adapter.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/initializers/active_job.rb&lt;br /&gt;
&lt;br /&gt;
ActiveJob::Base.queue_adapter = :resque&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a Job with generator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the generated file app/jobs/test_email_job.rb, define the perform method and set it’s queue_as.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/jobs/test_email_job.rb&lt;br /&gt;
&lt;br /&gt;
class TestEmailJob &amp;lt; ActiveJob::Base&lt;br /&gt;
  queue_as :email&lt;br /&gt;
&lt;br /&gt;
  def perform(email)&lt;br /&gt;
    UserMailer.test_email(email).deliver_now&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we can use a UserController to put the job into the queue for later execution. Here we set the email to be sent one minute later for test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ bin/rails generate job test_email&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/controllers/users_controller.rb&lt;br /&gt;
&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
    @user = User.new&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    @user = User.create(user_params)&lt;br /&gt;
    TestEmailJob.new(@user.email).deliver_later!(wait: 1.minute)&lt;br /&gt;
    # redirect somewhere&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Routes and view need to set to make it work.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/routes.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.routes.draw do&lt;br /&gt;
  resources :users, only: [:new, :create]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#app/views/users/new.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%= form_for @user do |f| %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.email_field :email %&amp;gt;&lt;br /&gt;
  &amp;lt;%= f.submit %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Try execution ====&lt;br /&gt;
Before we try the Mailer, we need MailCatcher for the test. Add following into Gemfile and “$ bundle install”&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'mailcatcher'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set the environment, add following things into config/environments/development.rb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#config/environments/development.rb&lt;br /&gt;
&lt;br /&gt;
Rails.application.configure do&lt;br /&gt;
  ...&lt;br /&gt;
  config.action_mailer.delivery_method = :smtp&lt;br /&gt;
  config.action_mailer.smtp_settings = { address: &amp;quot;localhost&amp;quot;, port: 1025 }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run it!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Start mailcatcher&lt;br /&gt;
$ mailcatcher&lt;br /&gt;
&lt;br /&gt;
# Start redis-server&lt;br /&gt;
$ redis-server&lt;br /&gt;
&lt;br /&gt;
# Start resque:work&lt;br /&gt;
$ bundle exec rake resque:work&lt;br /&gt;
&lt;br /&gt;
# Start resque:scheduler&lt;br /&gt;
$ rake environment resque:scheduler&lt;br /&gt;
&lt;br /&gt;
# Finally start rails server&lt;br /&gt;
$ rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the browser, visit localhost:3000/users/new and sign up as a new user. One minute later you can see following in Resque scheduler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resque-scheduler: [INFO] 2016-02-05T22:53:15+09:00: Processing Delayed Items&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And in MailCatcher:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
==&amp;gt; SMTP: Received message from '&amp;lt;from@example.com&amp;gt;' (315 bytes)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ychen71</name></author>
	</entry>
</feed>