<?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=Wemorrow</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=Wemorrow"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Wemorrow"/>
	<updated>2026-10-01T13:44:15Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1401_lmn&amp;diff=84852</id>
		<title>CSC/ECE 517 Spring 2014/oss E1401 lmn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1401_lmn&amp;diff=84852"/>
		<updated>2014-05-05T13:18:41Z</updated>

		<summary type="html">&lt;p&gt;Wemorrow: /* Future Work */ struck out things completed in final projects&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
Assignments in Expertiza have many components--due dates and topics, for example.  Due dates and topics are objects in their own right (DueDate, SignupTopic); we need a way to have sets of due dates and topics associated with an assignment.&lt;br /&gt;
There are also separate forms to create and edit an Assignment and its components (Topics, Due Dates), these forms should be unified into one form for every component of an Assignment.&lt;br /&gt;
Also, it'd be nice if we could sort assignment due dates in order of next due.&lt;br /&gt;
===What Needs to be Done===&lt;br /&gt;
* Remove the separate New and Edit forms for assignment&lt;br /&gt;
* Create a form object to encapsulate the creation and editing of Assignments, Due Dates, and Topics&lt;br /&gt;
* Add the ability to sort Due Dates&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/due_date_controller.rb&lt;br /&gt;
* controllers/sign_up_sheet_controller.rb&lt;br /&gt;
* models/due_date.rb&lt;br /&gt;
* models/sign_up_topic.rb&lt;br /&gt;
&lt;br /&gt;
====Objectives====&lt;br /&gt;
* All CUD (Create, Update, Delete) operations on Assignments, Due Dates, and Topics should be performed through an AssignmentFormObject&lt;br /&gt;
* Assignment, Due Date, and Topic views and controllers should be subsumed into a combined AssignmentFormObject view and controller&lt;br /&gt;
==Design and Implementation==&lt;br /&gt;
As a bit of background, form objects&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/&amp;lt;/ref&amp;gt; could be thought of as a fake model that is not itself persisted but persists all its component models. The name comes from the idea that in many cases forms require information for several models at a time, rather than just one. Creating a series of forms to work with each model at a time is tedious and frustrating, both for the coder and for the end user. A form object fixes this problem by acting like a model. It can have validations, persistence strategies, and a save method that returns the object if and when it is saved, just like a model. Behind the scenes it is intelligently manipulating other models to provide this functionality transparently, encapsulating the required logic.&lt;br /&gt;
&lt;br /&gt;
Our design uses one form object, AssignmentFormObject, to store data about the base Assignment model, Due Date, and Topic models associated to that Assignment. In this way we can achieve both objectives, utilizing the form object to create, update, and delete Assignments and associated Due Date and Topics without having to have separate controllers and views for each.&lt;br /&gt;
&lt;br /&gt;
The form object inherits from ActiveRecord (though is not a subclass of) in order to be able to mass-assign attributes and create custom validations and Virtus&amp;lt;ref&amp;gt;https://github.com/solnic/virtus&amp;lt;/ref&amp;gt; to handle attributes like a normal model. We need these custom validations because the attributes of the form object include arrays of attributes for models, something the default validations cannot handle on their own. In addition, we need to run validations on the parameters passed in for each of the models contained within the form object, again something that the default validations cannot do.&lt;br /&gt;
&lt;br /&gt;
The logic behind persisting a form object is somewhat more complicated than a normal model (in which you very rarely have to override the default save operation). This is because form objects must persist several models at once, as shown below.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;Assignment.transaction do&lt;br /&gt;
      if @assignment.save&lt;br /&gt;
&lt;br /&gt;
        topics_list.each do |a|&lt;br /&gt;
          a.assignment = @assignment&lt;br /&gt;
          if !a.save&lt;br /&gt;
            raise ActiveRecord::Rollback&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        due_dates_list.each do |a|&lt;br /&gt;
          a.assignment = @assignment&lt;br /&gt;
          if !a.save&lt;br /&gt;
            raise ActiveRecord::Rollback&lt;br /&gt;
          end&lt;br /&gt;
        end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The form object starts a transaction (in order to guarantee that either everything or nothing is saved) then attempts to create (or update) the Assignment. If this succeeds, it moves on to the components of the Assignment, doing the same. If any one of these operations fails (for instance, if a topic is not able to be saved), the entire operation is rolled back, removing all of the partially saved changes and reverting to before the form object attempted to persist. In this way we make sure that the save operation is atomic like a normal model's save operation.&lt;br /&gt;
&lt;br /&gt;
Because the form object can be treated like a model, writing a controller to populate views with it is just as easy as with a normal model, as shown.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    @assignment_form_object = AssignmentFormObject.new(params)&lt;br /&gt;
    if @assignment_form_object.save&lt;br /&gt;
      alert(&amp;quot;Form saved&amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      alert(&amp;quot;Error saving form&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes to the View===&lt;br /&gt;
Basically, we have added the ability to add most of the same attributes to a new assignment as when editing an existing assignment. Previously, you could only&lt;br /&gt;
provide an assignment name, then you had to add due dates, etc. There are still some limitations to this process due to the complicated relationships between &lt;br /&gt;
models. To view the changes, navigate to &amp;quot;~/assignments/new&amp;quot;. The addition of Rubrics and Review Strategies is currently not implemented for new assignments, and &lt;br /&gt;
this should be addressed in future works. In addition, you may only add one topic to a new assignment, then you must add more topics at the edit page. &lt;br /&gt;
The addition of due dates uses a partial view that is in need of refactoring. In addition some validation is necessary for date times. For submission due dates&lt;br /&gt;
and review due dates, please provide a date time. &lt;br /&gt;
&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/due_date.rb&lt;br /&gt;
* views/assignments/new.html.erb&lt;br /&gt;
* views/assignments/edit.html.erb&lt;br /&gt;
* views/assignments/edit/_add_signup_topics.html.erb&lt;br /&gt;
* views/assignments/edit/_due_dates.html.erb&lt;br /&gt;
* views/assignments/edit/_general.html.erb&lt;br /&gt;
* views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
Added classes&lt;br /&gt;
* models/AssignmentFormObject.rb&lt;br /&gt;
* controllers/assignment_form_object_controller.rb&lt;br /&gt;
* helpers/assignment_form_object_helper.rb&lt;br /&gt;
* views/assignment_form_object/new.erb&lt;br /&gt;
* views/assignments/new/_add_signup_topics.html.erb&lt;br /&gt;
* views/assignments/new/_due_dates.html.erb&lt;br /&gt;
* views/assignments/new/_general.html.erb&lt;br /&gt;
* views/assignments/new/_late_policy.html.erb&lt;br /&gt;
* views/assignments/new/_review_strategy.html.erb&lt;br /&gt;
* views/assignments/new/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
==Running the Project Locally==&lt;br /&gt;
In order to run the project locally (for feature testing or for running unit tests) please follow&lt;br /&gt;
these steps:&lt;br /&gt;
1. Clone the GitHub repository (https://github.com/losmescaleros/expertiza)&lt;br /&gt;
2. Run &amp;quot;bundle install&amp;quot;&lt;br /&gt;
3. Run &amp;quot;rake db:create:all&amp;quot;&lt;br /&gt;
4. If you have a database dump, run it. For this project, we used the one located here:&lt;br /&gt;
http://courses.ncsu.edu/csc517/common/homework/OSS/expertiza_scrubbed_2014_03_14.sql.zip&lt;br /&gt;
&amp;quot;mysql -u root pg_development &amp;lt; expertiza-scrubbed.sql&amp;quot;&lt;br /&gt;
Note that this may not be the name of the zipped dump, but you can customize to your needs. You may&lt;br /&gt;
also need to specify your mysql password using &amp;quot;mysql -u root -p ...&amp;quot; depending on your mysql setup.&lt;br /&gt;
5. Run &amp;quot;exec rake db:migrate&amp;quot;&lt;br /&gt;
6. Run the rails server using &amp;quot;rails server -p 3000&amp;quot;. You may substitute 3000 with a port number of&lt;br /&gt;
your choice. &lt;br /&gt;
&lt;br /&gt;
===Running Tests===&lt;br /&gt;
For this project, we used RSpec for unit tests. These are located at spec/models/assignment_form_object_spec.rb. The tests&lt;br /&gt;
are primarily unit tests for the model, and it required a lot of testing of other models that were not well tested (or tested&lt;br /&gt;
at all) elsewhere. &lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
As with every project there are always more things to be done. With the use of a form object there are side benefits that we can take advantage of with more effort that we just didn't have time for. There are also some problematic areas we uncovered during the project that could use cleaning up. The following additional steps (or features) should be taken (or implemented) by anyone continuing with the project.&lt;br /&gt;
Struck out lines indicate features that have already been added in continuing work.&lt;br /&gt;
* &amp;lt;del&amp;gt;Ability to add multiple sign up topics from a new form&amp;lt;/del&amp;gt;&lt;br /&gt;
* Ability to add rubric details from a new form&lt;br /&gt;
* Redo the due dates partial to be more readable and use rails conventions rather than JavaScript&lt;br /&gt;
* Redo the due dates partial in general, it is very messy and difficult to work with&lt;br /&gt;
* Relocate JavaScript scripts to another.js resource file rather than in-line in the html&lt;br /&gt;
* &amp;lt;del&amp;gt;Eliminate the need to have multiple calls to the same controller methods for every table entry for due dates on the edit pages&amp;lt;/del&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Wemorrow</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1401_lmn&amp;diff=84211</id>
		<title>CSC/ECE 517 Spring 2014/oss E1401 lmn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1401_lmn&amp;diff=84211"/>
		<updated>2014-04-01T00:36:21Z</updated>

		<summary type="html">&lt;p&gt;Wemorrow: /* Design and Implementation */  Added more detail to the explanation of the form object implementation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
Assignments in Expertiza have many components--due dates and topics, for example.  Due dates and topics are objects in their own right (DueDate, SignupTopic); we need a way to have sets of due dates and topics associated with an assignment.&lt;br /&gt;
There are also separate forms to create and edit an Assignment and its components (Topics, Due Dates), these forms should be unified into one form for every component of an Assignment.&lt;br /&gt;
Also, it'd be nice if we could sort assignment due dates in order of next due.&lt;br /&gt;
===What Needs to be Done===&lt;br /&gt;
* Remove the separate New and Edit forms for assignment&lt;br /&gt;
* Create a form object to encapsulate the creation and editing of Assignments, Due Dates, and Topics&lt;br /&gt;
* Add the ability to sort Due Dates&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/due_date_controller.rb&lt;br /&gt;
* controllers/sign_up_sheet_controller.rb&lt;br /&gt;
* models/due_date.rb&lt;br /&gt;
* models/sign_up_topic.rb&lt;br /&gt;
&lt;br /&gt;
====Objectives====&lt;br /&gt;
* All CUD (Create, Update, Delete) operations on Assignments, Due Dates, and Topics should be performed through an AssignmentFormObject&lt;br /&gt;
* Assignment, Due Date, and Topic views and controllers should be subsumed into a combined AssignmentFormObject view and controller&lt;br /&gt;
==Design and Implementation==&lt;br /&gt;
As a bit of background, form objects&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/&amp;lt;/ref&amp;gt; could be thought of as a fake model that is not itself persisted but persists all its component models. The name comes from the idea that in many cases forms require information for several models at a time, rather than just one. Creating a series of forms to work with each model at a time is tedious and frustrating, both for the coder and for the end user. A form object fixes this problem by acting like a model. It can have validations, persistence strategies, and a save method that returns the object if and when it is saved, just like a model. Behind the scenes it is intelligently manipulating other models to provide this functionality transparently, encapsulating the required logic.&lt;br /&gt;
&lt;br /&gt;
Our design uses one form object, AssignmentFormObject, to store data about the base Assignment model, Due Date, and Topic models associated to that Assignment. In this way we can achieve both objectives, utilizing the form object to create, update, and delete Assignments and associated Due Date and Topics without having to have separate controllers and views for each.&lt;br /&gt;
&lt;br /&gt;
The form object inherits from ActiveRecord (though is not a subclass of) in order to be able to mass-assign attributes and create custom validations and Virtus&amp;lt;ref&amp;gt;https://github.com/solnic/virtus&amp;lt;/ref&amp;gt; to handle attributes like a normal model. We need these custom validations because the attributes of the form object include arrays of attributes for models, something the default validations cannot handle on their own. In addition, we need to run validations on the parameters passed in for each of the models contained within the form object, again something that the default validations cannot do.&lt;br /&gt;
&lt;br /&gt;
The logic behind persisting a form object is somewhat more complicated than a normal model (in which you very rarely have to override the default save operation). This is because form objects must persist several models at once, as shown below.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;Assignment.transaction do&lt;br /&gt;
      if @assignment.save&lt;br /&gt;
&lt;br /&gt;
        topics_list.each do |a|&lt;br /&gt;
          a.assignment = @assignment&lt;br /&gt;
          if !a.save&lt;br /&gt;
            raise ActiveRecord::Rollback&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        due_dates_list.each do |a|&lt;br /&gt;
          a.assignment = @assignment&lt;br /&gt;
          if !a.save&lt;br /&gt;
            raise ActiveRecord::Rollback&lt;br /&gt;
          end&lt;br /&gt;
        end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The form object starts a transaction (in order to guarantee that either everything or nothing is saved) then attempts to create (or update) the Assignment. If this succeeds, it moves on to the components of the Assignment, doing the same. If any one of these operations fails (for instance, if a topic is not able to be saved), the entire operation is rolled back, removing all of the partially saved changes and reverting to before the form object attempted to persist. In this way we make sure that the save operation is atomic like a normal model's save operation.&lt;br /&gt;
&lt;br /&gt;
Because the form object can be treated like a model, writing a controller to populate views with it is just as easy as with a normal model, as shown.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    @assignment_form_object = AssignmentFormObject.new(params)&lt;br /&gt;
    if @assignment_form_object.save&lt;br /&gt;
      alert(&amp;quot;Form saved&amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      alert(&amp;quot;Error saving form&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/due_date.rb&lt;br /&gt;
* views/assignments/new.html.erb&lt;br /&gt;
* views/assignments/edit.html.erb&lt;br /&gt;
* views/assignments/edit/_add_signup_topics.html.erb&lt;br /&gt;
* views/assignments/edit/_due_dates.html.erb&lt;br /&gt;
* views/assignments/edit/_general.html.erb&lt;br /&gt;
* views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
Added classes&lt;br /&gt;
* models/AssignmentFormObject.rb&lt;br /&gt;
* controllers/assignment_form_object_controller.rb&lt;br /&gt;
* helpers/assignment_form_object_helper.rb&lt;br /&gt;
* views/assignment_form_object/new.erb&lt;br /&gt;
* views/assignments/new/_add_signup_topics.html.erb&lt;br /&gt;
* views/assignments/new/_due_dates.html.erb&lt;br /&gt;
* views/assignments/new/_general.html.erb&lt;br /&gt;
* views/assignments/new/_late_policy.html.erb&lt;br /&gt;
* views/assignments/new/_review_strategy.html.erb&lt;br /&gt;
* views/assignments/new/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
As with every project there are always more things to be done. With the use of a form object there are side benefits that we can take advantage of with more effort that we just didn't have time for. There are also some problematic areas we uncovered during the project that could use cleaning up. The following additional steps (or features) should be taken (or implemented) by anyone continuing with the project.&lt;br /&gt;
* Ability to add multiple sign up topics from a new form&lt;br /&gt;
* Ability to add rubric details from a new form&lt;br /&gt;
* Redo the due dates partial to be more readable and use rails conventions rather than JavaScript&lt;br /&gt;
* Redo the due dates partial in general, it is very messy and difficult to work with&lt;br /&gt;
* Relocate JavaScript scripts to another.js resource file rather than in-line in the html&lt;br /&gt;
* Eliminate the need to have multiple calls to the same controller methods for every table entry for due dates on the edit pages&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Wemorrow</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1401_lmn&amp;diff=84140</id>
		<title>CSC/ECE 517 Spring 2014/oss E1401 lmn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1401_lmn&amp;diff=84140"/>
		<updated>2014-03-31T17:18:17Z</updated>

		<summary type="html">&lt;p&gt;Wemorrow: Added references, changed the format of the linked references to agree with the references tag&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
Assignments in Expertiza have many components--due dates and topics, for example.  Due dates and topics are objects in their own right (DueDate, SignupTopic); we need a way to have sets of due dates and topics associated with an assignment.&lt;br /&gt;
There are also separate forms to create and edit an Assignment and its components (Topics, Due Dates), these forms should be unified into one form for every component of an Assignment.&lt;br /&gt;
Also, it'd be nice if we could sort assignment due dates in order of next due.&lt;br /&gt;
===What Needs to be Done===&lt;br /&gt;
* Remove the separate New and Edit forms for assignment&lt;br /&gt;
* Create a form object to encapsulate the creation and editing of Assignments, Due Dates, and Topics&lt;br /&gt;
* Add the ability to sort Due Dates&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/due_date_controller.rb&lt;br /&gt;
* controllers/sign_up_sheet_controller.rb&lt;br /&gt;
* models/due_date.rb&lt;br /&gt;
* models/sign_up_topic.rb&lt;br /&gt;
&lt;br /&gt;
====Objectives====&lt;br /&gt;
* All CUD (Create, Update, Delete) operations on Assignments, Due Dates, and Topics should be performed through an AssignmentFormObject&lt;br /&gt;
* Assignment, Due Date, and Topic views and controllers should be subsumed into a combined AssignmentFormObject view and controller&lt;br /&gt;
==Design and Implementation==&lt;br /&gt;
As a bit of background, form objects&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/&amp;lt;/ref&amp;gt; could be thought of as a fake model that is not itself persisted but persists all its component models. The name comes from the idea that many times forms do not require information for just one model but several at a time. Creating a series of forms to work with each model at a time is tedious and frustrating. A form object fixes this problem by acting like a model. It can have validations, have persistence strategies, and return whether or not it is persisted, just like a model. Behind the scenes it is intelligently manipulating other models to provide this functionality transparently, encapsulating the required logic.&lt;br /&gt;
&lt;br /&gt;
Our design uses one form object, AssignmentFormObject, to store data about the base Assignment model and Due Date and Topic models associated to that Assignment. In this way we can achieve both objectives, utilizing the form object to create, update, and delete Assignments and associated Due Date and Topics without having to have separate controllers and views for each.&lt;br /&gt;
&lt;br /&gt;
Without knowing anything about form objects, it is easy to tell what is going on when you attempt to persist an AssignmentFormObject:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;Assignment.transaction do&lt;br /&gt;
      if @assignment.save&lt;br /&gt;
&lt;br /&gt;
        topics_list.each do |a|&lt;br /&gt;
          a.assignment = @assignment&lt;br /&gt;
          if !a.save&lt;br /&gt;
            raise ActiveRecord::Rollback&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        due_dates_list.each do |a|&lt;br /&gt;
          a.assignment = @assignment&lt;br /&gt;
          if !a.save&lt;br /&gt;
            raise ActiveRecord::Rollback&lt;br /&gt;
          end&lt;br /&gt;
        end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The form object starts a transaction (in order to guarantee that either everything or nothing is saved) then attempts to create (or update) the Assignment. If this succeeds, it moves on to the components of the Assignment, doing the same. These inputs are passed to the form object previously, using Virtus&amp;lt;ref&amp;gt;https://github.com/solnic/virtus&amp;lt;/ref&amp;gt; to create validations on the attributes passed.&lt;br /&gt;
&lt;br /&gt;
Because the form object can be treated like a model, writing a controller to populate views with it is just as easy as with a normal model, as shown.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    @assignment_form_object = AssignmentFormObject.new(params)&lt;br /&gt;
    if @assignment_form_object.save&lt;br /&gt;
      alert(&amp;quot;Form saved&amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      alert(&amp;quot;Error saving form&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/due_date.rb&lt;br /&gt;
* views/assignments/new.html.erb&lt;br /&gt;
* views/assignments/edit.html.erb&lt;br /&gt;
* views/assignments/edit/_add_signup_topics.html.erb&lt;br /&gt;
* views/assignments/edit/_due_dates.html.erb&lt;br /&gt;
* views/assignments/edit/_general.html.erb&lt;br /&gt;
* views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
Added classes&lt;br /&gt;
* models/AssignmentFormObject.rb&lt;br /&gt;
* controllers/assignment_form_object_controller.rb&lt;br /&gt;
* helpers/assignment_form_object_helper.rb&lt;br /&gt;
* views/assignment_form_object/new.erb&lt;br /&gt;
* views/assignments/new/_add_signup_topics.html.erb&lt;br /&gt;
* views/assignments/new/_due_dates.html.erb&lt;br /&gt;
* views/assignments/new/_general.html.erb&lt;br /&gt;
* views/assignments/new/_late_policy.html.erb&lt;br /&gt;
* views/assignments/new/_review_strategy.html.erb&lt;br /&gt;
* views/assignments/new/_rubrics.html.erb&lt;br /&gt;
==Future Work==&lt;br /&gt;
As with every project there are always more things to be done. With the use of a form object there are side benefits that we can take advantage of with more effort that we just didn't have time for. There are also some problematic areas we uncovered during the project that could use cleaning up. The following additional steps (or features) should be taken (or implemented) by anyone continuing with the project.&lt;br /&gt;
* Ability to add multiple sign up topics from a new form&lt;br /&gt;
* Ability to add rubric details from a new form&lt;br /&gt;
* Redo the due dates partial to be more readable and use rails conventions rather than JavaScript&lt;br /&gt;
* Redo the due dates partial in general, it is very messy and difficult to work with&lt;br /&gt;
* Relocate JavaScript scripts to another.js resource file rather than in-line in the html&lt;br /&gt;
* Eliminate the need to have multiple calls to the same controller methods for every table entry for due dates on the edit pages&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Wemorrow</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1401_lmn&amp;diff=84139</id>
		<title>CSC/ECE 517 Spring 2014/oss E1401 lmn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1401_lmn&amp;diff=84139"/>
		<updated>2014-03-31T17:12:42Z</updated>

		<summary type="html">&lt;p&gt;Wemorrow: /* Future Work */  filled in with Mitchell's list of suggestions for future work&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
Assignments in Expertiza have many components--due dates and topics, for example.  Due dates and topics are objects in their own right (DueDate, SignupTopic); we need a way to have sets of due dates and topics associated with an assignment.&lt;br /&gt;
There are also separate forms to create and edit an Assignment and its components (Topics, Due Dates), these forms should be unified into one form for every component of an Assignment.&lt;br /&gt;
Also, it'd be nice if we could sort assignment due dates in order of next due.&lt;br /&gt;
===What Needs to be Done===&lt;br /&gt;
* Remove the separate New and Edit forms for assignment&lt;br /&gt;
* Create a form object to encapsulate the creation and editing of Assignments, Due Dates, and Topics&lt;br /&gt;
* Add the ability to sort Due Dates&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/due_date_controller.rb&lt;br /&gt;
* controllers/sign_up_sheet_controller.rb&lt;br /&gt;
* models/due_date.rb&lt;br /&gt;
* models/sign_up_topic.rb&lt;br /&gt;
&lt;br /&gt;
====Objectives====&lt;br /&gt;
* All CUD (Create, Update, Delete) operations on Assignments, Due Dates, and Topics should be performed through an AssignmentFormObject&lt;br /&gt;
* Assignment, Due Date, and Topic views and controllers should be subsumed into a combined AssignmentFormObject view and controller&lt;br /&gt;
==Design and Implementation==&lt;br /&gt;
As a bit of background, form objects[http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/] could be thought of as a fake model that is not itself persisted but persists all its component models. The name comes from the idea that many times forms do not require information for just one model but several at a time. Creating a series of forms to work with each model at a time is tedious and frustrating. A form object fixes this problem by acting like a model. It can have validations, have persistence strategies, and return whether or not it is persisted, just like a model. Behind the scenes it is intelligently manipulating other models to provide this functionality transparently, encapsulating the required logic.&lt;br /&gt;
&lt;br /&gt;
Our design uses one form object, AssignmentFormObject, to store data about the base Assignment model and Due Date and Topic models associated to that Assignment. In this way we can achieve both objectives, utilizing the form object to create, update, and delete Assignments and associated Due Date and Topics without having to have separate controllers and views for each.&lt;br /&gt;
&lt;br /&gt;
Without knowing anything about form objects, it is easy to tell what is going on when you attempt to persist an AssignmentFormObject:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;Assignment.transaction do&lt;br /&gt;
      if @assignment.save&lt;br /&gt;
&lt;br /&gt;
        topics_list.each do |a|&lt;br /&gt;
          a.assignment = @assignment&lt;br /&gt;
          if !a.save&lt;br /&gt;
            raise ActiveRecord::Rollback&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        due_dates_list.each do |a|&lt;br /&gt;
          a.assignment = @assignment&lt;br /&gt;
          if !a.save&lt;br /&gt;
            raise ActiveRecord::Rollback&lt;br /&gt;
          end&lt;br /&gt;
        end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The form object starts a transaction (in order to guarantee that either everything or nothing is saved) then attempts to create (or update) the Assignment. If this succeeds, it moves on to the components of the Assignment, doing the same. These inputs are passed to the form object previously, using Virtus[https://github.com/solnic/virtus] to create validations on the attributes passed.&lt;br /&gt;
&lt;br /&gt;
Because the form object can be treated like a model, writing a controller to populate views with it is just as easy as with a normal model, as shown.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    @assignment_form_object = AssignmentFormObject.new(params)&lt;br /&gt;
    if @assignment_form_object.save&lt;br /&gt;
      alert(&amp;quot;Form saved&amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      alert(&amp;quot;Error saving form&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/due_date.rb&lt;br /&gt;
* views/assignments/new.html.erb&lt;br /&gt;
* views/assignments/edit.html.erb&lt;br /&gt;
* views/assignments/edit/_add_signup_topics.html.erb&lt;br /&gt;
* views/assignments/edit/_due_dates.html.erb&lt;br /&gt;
* views/assignments/edit/_general.html.erb&lt;br /&gt;
* views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
Added classes&lt;br /&gt;
* models/AssignmentFormObject.rb&lt;br /&gt;
* controllers/assignment_form_object_controller.rb&lt;br /&gt;
* helpers/assignment_form_object_helper.rb&lt;br /&gt;
* views/assignment_form_object/new.erb&lt;br /&gt;
* views/assignments/new/_add_signup_topics.html.erb&lt;br /&gt;
* views/assignments/new/_due_dates.html.erb&lt;br /&gt;
* views/assignments/new/_general.html.erb&lt;br /&gt;
* views/assignments/new/_late_policy.html.erb&lt;br /&gt;
* views/assignments/new/_review_strategy.html.erb&lt;br /&gt;
* views/assignments/new/_rubrics.html.erb&lt;br /&gt;
==Future Work==&lt;br /&gt;
As with every project there are always more things to be done. With the use of a form object there are side benefits that we can take advantage of with more effort that we just didn't have time for. There are also some problematic areas we uncovered during the project that could use cleaning up. The following additional steps (or features) should be taken (or implemented) by anyone continuing with the project.&lt;br /&gt;
* Ability to add multiple sign up topics from a new form&lt;br /&gt;
* Ability to add rubric details from a new form&lt;br /&gt;
* Redo the due dates partial to be more readable and use rails conventions rather than JavaScript&lt;br /&gt;
* Redo the due dates partial in general, it is very messy and difficult to work with&lt;br /&gt;
* Relocate JavaScript scripts to another.js resource file rather than in-line in the html&lt;br /&gt;
* Eliminate the need to have multiple calls to the same controller methods for every table entry for due dates on the edit pages&lt;/div&gt;</summary>
		<author><name>Wemorrow</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1401_lmn&amp;diff=84128</id>
		<title>CSC/ECE 517 Spring 2014/oss E1401 lmn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1401_lmn&amp;diff=84128"/>
		<updated>2014-03-31T14:57:34Z</updated>

		<summary type="html">&lt;p&gt;Wemorrow: Reorganized classes, updated design and implementation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
Assignments in Expertiza have many components--due dates and topics, for example.  Due dates and topics are objects in their own right (DueDate, SignupTopic); we need a way to have sets of due dates and topics associated with an assignment.&lt;br /&gt;
There are also separate forms to create and edit an Assignment and its components (Topics, Due Dates), these forms should be unified into one form for every component of an Assignment.&lt;br /&gt;
Also, it'd be nice if we could sort assignment due dates in order of next due.&lt;br /&gt;
===What Needs to be Done===&lt;br /&gt;
* Remove the separate New and Edit forms for assignment&lt;br /&gt;
* Create a form object to encapsulate the creation and editing of Assignments, Due Dates, and Topics&lt;br /&gt;
* Add the ability to sort Due Dates&lt;br /&gt;
====Classes====&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* controllers/due_date_controller.rb&lt;br /&gt;
* controllers/sign_up_sheet_controller.rb&lt;br /&gt;
* models/due_date.rb&lt;br /&gt;
* models/sign_up_topic.rb&lt;br /&gt;
&lt;br /&gt;
====Objectives====&lt;br /&gt;
* All CUD (Create, Update, Delete) operations on Assignments, Due Dates, and Topics should be performed through an AssignmentFormObject&lt;br /&gt;
* Assignment, Due Date, and Topic views and controllers should be subsumed into a combined AssignmentFormObject view and controller&lt;br /&gt;
==Design and Implementation==&lt;br /&gt;
As a bit of background, form objects[http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/] could be thought of as a fake model that is not itself persisted but persists all its component models. The name comes from the idea that many times forms do not require information for just one model but several at a time. Creating a series of forms to work with each model at a time is tedious and frustrating. A form object fixes this problem by acting like a model. It can have validations, have persistence strategies, and return whether or not it is persisted, just like a model. Behind the scenes it is intelligently manipulating other models to provide this functionality transparently, encapsulating the required logic.&lt;br /&gt;
&lt;br /&gt;
Our design uses one form object, AssignmentFormObject, to store data about the base Assignment model and Due Date and Topic models associated to that Assignment. In this way we can achieve both objectives, utilizing the form object to create, update, and delete Assignments and associated Due Date and Topics without having to have separate controllers and views for each.&lt;br /&gt;
&lt;br /&gt;
Without knowing anything about form objects, it is easy to tell what is going on when you attempt to persist an AssignmentFormObject:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;Assignment.transaction do&lt;br /&gt;
      if @assignment.save&lt;br /&gt;
&lt;br /&gt;
        topics_list.each do |a|&lt;br /&gt;
          a.assignment = @assignment&lt;br /&gt;
          if !a.save&lt;br /&gt;
            raise ActiveRecord::Rollback&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        due_dates_list.each do |a|&lt;br /&gt;
          a.assignment = @assignment&lt;br /&gt;
          if !a.save&lt;br /&gt;
            raise ActiveRecord::Rollback&lt;br /&gt;
          end&lt;br /&gt;
        end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The form object starts a transaction (in order to guarantee that either everything or nothing is saved) then attempts to create (or update) the Assignment. If this succeeds, it moves on to the components of the Assignment, doing the same. These inputs are passed to the form object previously, using Virtus[https://github.com/solnic/virtus] to create validations on the attributes passed.&lt;br /&gt;
&lt;br /&gt;
Because the form object can be treated like a model, writing a controller to populate views with it is just as easy as with a normal model, as shown.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    @assignment_form_object = AssignmentFormObject.new(params)&lt;br /&gt;
    if @assignment_form_object.save&lt;br /&gt;
      alert(&amp;quot;Form saved&amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      alert(&amp;quot;Error saving form&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
===Affected Classes===&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/due_date.rb&lt;br /&gt;
* views/assignments/new.html.erb&lt;br /&gt;
* views/assignments/edit.html.erb&lt;br /&gt;
* views/assignments/edit/_add_signup_topics.html.erb&lt;br /&gt;
* views/assignments/edit/_due_dates.html.erb&lt;br /&gt;
* views/assignments/edit/_general.html.erb&lt;br /&gt;
* views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
Added classes&lt;br /&gt;
* models/AssignmentFormObject.rb&lt;br /&gt;
* controllers/assignment_form_object_controller.rb&lt;br /&gt;
* helpers/assignment_form_object_helper.rb&lt;br /&gt;
* views/assignment_form_object/new.erb&lt;br /&gt;
* views/assignments/new/_add_signup_topics.html.erb&lt;br /&gt;
* views/assignments/new/_due_dates.html.erb&lt;br /&gt;
* views/assignments/new/_general.html.erb&lt;br /&gt;
* views/assignments/new/_late_policy.html.erb&lt;br /&gt;
* views/assignments/new/_review_strategy.html.erb&lt;br /&gt;
* views/assignments/new/_rubrics.html.erb&lt;br /&gt;
==Future Work==&lt;/div&gt;</summary>
		<author><name>Wemorrow</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1401_lmn&amp;diff=84126</id>
		<title>CSC/ECE 517 Spring 2014/oss E1401 lmn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1401_lmn&amp;diff=84126"/>
		<updated>2014-03-31T12:06:44Z</updated>

		<summary type="html">&lt;p&gt;Wemorrow: /* Classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
Assignments in Expertiza have many components--due dates and topics, for example.  Due dates and topics are objects in their own right (DueDate, SignupTopic); we need a way to have sets of due dates and topics associated with an assignment.&lt;br /&gt;
There are also separate forms to create and edit an Assignment and its components (Topics, Due Dates), these forms should be unified into one form for every component of an Assignment.&lt;br /&gt;
Also, it'd be nice if we could sort assignment due dates in order of next due.&lt;br /&gt;
===What Needs to be Done===&lt;br /&gt;
* Remove the separate New and Edit forms for assignment&lt;br /&gt;
* Create a form object to encapsulate the creation and editing of Assignments, Due Dates, and Topics&lt;br /&gt;
* Add the ability to sort Due Dates&lt;br /&gt;
====Classes====&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/due_date.rb&lt;br /&gt;
* views/assignments/new.html.erb&lt;br /&gt;
* views/assignments/edit.html.erb&lt;br /&gt;
* views/assignments/edit/_add_signup_topics.html.erb&lt;br /&gt;
* views/assignments/edit/_due_dates.html.erb&lt;br /&gt;
* views/assignments/edit/_general.html.erb&lt;br /&gt;
* views/assignments/edit/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
Added classes&lt;br /&gt;
* models/AssignmentFormObject.rb&lt;br /&gt;
* controllers/assignment_form_object_controller.rb&lt;br /&gt;
* helpers/assignment_form_object_helper.rb&lt;br /&gt;
* views/assignment_form_object/new.erb&lt;br /&gt;
* views/assignments/new/_add_signup_topics.html.erb&lt;br /&gt;
* views/assignments/new/_due_dates.html.erb&lt;br /&gt;
* views/assignments/new/_general.html.erb&lt;br /&gt;
* views/assignments/new/_late_policy.html.erb&lt;br /&gt;
* views/assignments/new/_review_strategy.html.erb&lt;br /&gt;
* views/assignments/new/_rubrics.html.erb&lt;br /&gt;
&lt;br /&gt;
====Objectives====&lt;br /&gt;
* All CUD (Create, Update, Delete) operations on Assignments, Due Dates, and Topics should be performed through an AssignmentFormObject&lt;br /&gt;
* Assignment, Due Date, and Topic views and controllers should be subsumed into a combined AssignmentFormObject view and controller&lt;br /&gt;
==Design and Implementation==&lt;br /&gt;
As a bit of background, form objects[http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/] could be thought of as a fake model that is not itself persisted but persists all its component models. A form object acts like a model in that it can have validations, have persistence strategies, and return whether or not it is persisted. Behind the scenes it is intelligently manipulating other models to provide this functionality transparently, encapsulating the required logic.&lt;br /&gt;
&lt;br /&gt;
Our design uses one form object, AssignmentFormObject, to store data about the base Assignment model and Due Date and Topic models associated to that Assignment. In this way we can achieve both objectives, utilizing the form object to create, update, and delete Assignments and associated Due Date and Topics without having to have separate controllers and views for each.&lt;br /&gt;
&lt;br /&gt;
Without knowing anything about form objects, it is easy to tell what is going on when you attempt to persist an AssignmentFormObject:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;Assignment.transaction do&lt;br /&gt;
      if @assignment.save&lt;br /&gt;
&lt;br /&gt;
        topics_list.each do |a|&lt;br /&gt;
          a.assignment = @assignment&lt;br /&gt;
          if !a.save&lt;br /&gt;
            raise ActiveRecord::Rollback&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        due_dates_list.each do |a|&lt;br /&gt;
          a.assignment = @assignment&lt;br /&gt;
          if !a.save&lt;br /&gt;
            raise ActiveRecord::Rollback&lt;br /&gt;
          end&lt;br /&gt;
        end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The form object starts a transaction (in order to guarantee that either everything or nothing is saved) then attempts to create (or update) the Assignment. If this succeeds, it moves on to the components of the Assignment, doing the same. These inputs are passed to the form object previously, using Virtus[https://github.com/solnic/virtus] to create validations on the attributes passed.&lt;br /&gt;
&lt;br /&gt;
Because the form object can be treated like a model, writing a controller to populate views with it is just as easy as with a normal model, as shown.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    @assignment_form_object = AssignmentFormObject.new(params)&lt;br /&gt;
    if @assignment_form_object.save&lt;br /&gt;
      alert(&amp;quot;Form saved&amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      alert(&amp;quot;Error saving form&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
==Future Work==&lt;/div&gt;</summary>
		<author><name>Wemorrow</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1401_lmn&amp;diff=84106</id>
		<title>CSC/ECE 517 Spring 2014/oss E1401 lmn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/oss_E1401_lmn&amp;diff=84106"/>
		<updated>2014-03-31T00:06:50Z</updated>

		<summary type="html">&lt;p&gt;Wemorrow: Initial writeup&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
===Background===&lt;br /&gt;
Assignments in Expertiza have many components--due dates and topics, for example.  Due dates and topics are objects in their own right (DueDate, SignupTopic); we need a way to have sets of due dates and topics associated with an assignment.&lt;br /&gt;
There are also separate forms to create and edit an Assignment and its components (Topics, Due Dates), these forms should be unified into one form for every component of an Assignment.&lt;br /&gt;
Also, it'd be nice if we could sort assignment due dates in order of next due.&lt;br /&gt;
===What Needs to be Done===&lt;br /&gt;
* Remove the separate New and Edit forms for assignment&lt;br /&gt;
* Create a form object to encapsulate the creation and editing of Assignments, Due Dates, and Topics&lt;br /&gt;
* Add the ability to sort Due Dates&lt;br /&gt;
====Classes====&lt;br /&gt;
Changed existent classes&lt;br /&gt;
* controllers/assignments_controller.rb&lt;br /&gt;
* models/due_date.rb&lt;br /&gt;
* views/assignments/new.html.erb&lt;br /&gt;
* views/assignments/edit.html.erb&lt;br /&gt;
Added classes&lt;br /&gt;
* models/AssignmentFormObject.rb&lt;br /&gt;
* controllers/assignment_form_object_controller.rb&lt;br /&gt;
* helpers/assignment_form_object_helper.rb&lt;br /&gt;
* views/assignments/new/_add_signup_topics.html.erb&lt;br /&gt;
* views/assignments/new/_due_dates.html.erb&lt;br /&gt;
* views/assignments/new/_general.html.erb&lt;br /&gt;
* views/assignments/new/_late_policy.html.erb&lt;br /&gt;
* views/assignments/new/_review_strategy.html.erb&lt;br /&gt;
* views/assignments/new/_rubrics.html.erb&lt;br /&gt;
====Objectives====&lt;br /&gt;
* All CUD (Create, Update, Delete) operations on Assignments, Due Dates, and Topics should be performed through an AssignmentFormObject&lt;br /&gt;
* Assignment, Due Date, and Topic views and controllers should be subsumed into a combined AssignmentFormObject view and controller&lt;br /&gt;
==Design and Implementation==&lt;br /&gt;
As a bit of background, form objects[http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/] could be thought of as a fake model that is not itself persisted but persists all its component models. A form object acts like a model in that it can have validations, have persistence strategies, and return whether or not it is persisted. Behind the scenes it is intelligently manipulating other models to provide this functionality transparently, encapsulating the required logic.&lt;br /&gt;
&lt;br /&gt;
Our design uses one form object, AssignmentFormObject, to store data about the base Assignment model and Due Date and Topic models associated to that Assignment. In this way we can achieve both objectives, utilizing the form object to create, update, and delete Assignments and associated Due Date and Topics without having to have separate controllers and views for each.&lt;br /&gt;
&lt;br /&gt;
Without knowing anything about form objects, it is easy to tell what is going on when you attempt to persist an AssignmentFormObject:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;Assignment.transaction do&lt;br /&gt;
      if @assignment.save&lt;br /&gt;
&lt;br /&gt;
        topics_list.each do |a|&lt;br /&gt;
          a.assignment = @assignment&lt;br /&gt;
          if !a.save&lt;br /&gt;
            raise ActiveRecord::Rollback&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        due_dates_list.each do |a|&lt;br /&gt;
          a.assignment = @assignment&lt;br /&gt;
          if !a.save&lt;br /&gt;
            raise ActiveRecord::Rollback&lt;br /&gt;
          end&lt;br /&gt;
        end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The form object starts a transaction (in order to guarantee that either everything or nothing is saved) then attempts to create (or update) the Assignment. If this succeeds, it moves on to the components of the Assignment, doing the same. These inputs are passed to the form object previously, using Virtus[https://github.com/solnic/virtus] to create validations on the attributes passed.&lt;br /&gt;
&lt;br /&gt;
Because the form object can be treated like a model, writing a controller to populate views with it is just as easy as with a normal model, as shown.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    @assignment_form_object = AssignmentFormObject.new(params)&lt;br /&gt;
    if @assignment_form_object.save&lt;br /&gt;
      alert(&amp;quot;Form saved&amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      alert(&amp;quot;Error saving form&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
==Future Work==&lt;/div&gt;</summary>
		<author><name>Wemorrow</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014&amp;diff=84097</id>
		<title>CSC/ECE 517 Spring 2014</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014&amp;diff=84097"/>
		<updated>2014-03-30T22:07:51Z</updated>

		<summary type="html">&lt;p&gt;Wemorrow: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2012/example_page]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1a 1e rm]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1 1w1h jg ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1 1w1b np]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1 1w1f mj]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1a 1d mm]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1a 1c yj]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1 1w1l m]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1 1w1m bm]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/ch1a 1p fy]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/oss E1401 lmn]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/oss E1402 mmb]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/oss E1404 mnp]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2014/oss E1406 st]]&lt;/div&gt;</summary>
		<author><name>Wemorrow</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1a_1k_wm&amp;diff=83578</id>
		<title>CSC/ECE 517 Spring 2014/ch1a 1k wm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1a_1k_wm&amp;diff=83578"/>
		<updated>2014-02-21T20:59:05Z</updated>

		<summary type="html">&lt;p&gt;Wemorrow: /* Example */ added some narrative about why DRY should hold for fixtures&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Factory Girl=&lt;br /&gt;
[https://docs.google.com/document/d/1XzVu0zEuk7LP4smGZV9lRpSx5-wri6oClpUAmGYPN44/edit# Assignment Spec]&lt;br /&gt;
==Background==&lt;br /&gt;
From Factory Girl's Ruby Toolbox page&amp;lt;ref&amp;gt;https://www.ruby-toolbox.com/projects/factory_girl&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;factory_girl provides a framework and DSL for defining and using factories - less error-prone, more explicit, and all-around easier to work with than fixtures.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
Also from the Factory Girl's github page&amp;lt;ref&amp;gt;https://github.com/thoughtbot/factory_girl&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;factory_girl is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Factory Girl's purpose is to expedite good testing by creating test fixtures for the developer, eliminating the need to create large fixtures by hand. There are two versions, one for use with regular Ruby (factory_girl) and one for use with Ruby on Rails (factory_girl_rails&amp;lt;ref&amp;gt;https://github.com/thoughtbot/factory_girl_rails&amp;lt;/ref&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
'''Test fixtures''' are used to create an application state through which you can test code.&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html#the-low-down-on-fixtures&amp;lt;/ref&amp;gt; In some cases, the application state you need to build is very simple. For example, in unit testing you are testing very small pieces of code, the state that you need to set up is very small (typically one or two instances of a single model class). In other cases the application state may be complicated and the data handled very large, in which case the fixture will also be very large. Large fixtures could be used in performance testing in order to load the system up and tax its resources.&lt;br /&gt;
&lt;br /&gt;
==Generic Examples==&lt;br /&gt;
All examples taken from the github project&amp;lt;ref&amp;gt;https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md&amp;lt;/ref&amp;gt;&lt;br /&gt;
===Factories===&lt;br /&gt;
Factories are the basic unit of Factory Girl, they wrap up a constructor into a single method call that can be used in multiple test fixtures.&lt;br /&gt;
A factory looks pretty similar to a normal constructor but can be used multiple times without having to specify any parameters, as shown below.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;FactoryGirl.define do&lt;br /&gt;
  factory :user do&lt;br /&gt;
    first_name &amp;quot;John&amp;quot;&lt;br /&gt;
    last_name  &amp;quot;Doe&amp;quot;&lt;br /&gt;
    admin false&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The above creates a factory for class User (inferred by Factory Girl from the name of the factory) that can then be called in many different ways.&lt;br /&gt;
You can also define factories using specific classes, not only inferred from the name of the factory, as below (in the same word as the above example).&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;FactoryGirl.define do&lt;br /&gt;
  factory :admin, class: User do&lt;br /&gt;
    first_name &amp;quot;Admin&amp;quot;&lt;br /&gt;
    last_name  &amp;quot;User&amp;quot;&lt;br /&gt;
    admin      true&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
===Using Factories===&lt;br /&gt;
You can use factories in a variety of ways, as shown. You can also overwrite predefined attributes on the fly by passing in a hash of attributes and values.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;# Returns a User instance that's not saved&lt;br /&gt;
user = build(:user)&lt;br /&gt;
&lt;br /&gt;
# Returns a saved User instance&lt;br /&gt;
user = create(:user)&lt;br /&gt;
&lt;br /&gt;
# Returns a hash of attributes that can be used to build a User instance&lt;br /&gt;
attrs = attributes_for(:user)&lt;br /&gt;
&lt;br /&gt;
# Returns an object with all defined attributes stubbed out&lt;br /&gt;
stub = build_stubbed(:user)&lt;br /&gt;
&lt;br /&gt;
# Passing a block to any of the methods above will yield the return object&lt;br /&gt;
create(:user) do |user|&lt;br /&gt;
  user.posts.create(attributes_for(:post))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# Build a User instance and override the first_name property&lt;br /&gt;
user = build(:user, first_name: &amp;quot;Joe&amp;quot;)&lt;br /&gt;
user.first_name&lt;br /&gt;
# =&amp;gt; &amp;quot;Joe&amp;quot;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Aliasing===&lt;br /&gt;
You can utilize aliases to make somewhat more specialized factories out of existing factories, as shown.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user, aliases: [:author, :commenter] do&lt;br /&gt;
  first_name    &amp;quot;John&amp;quot;&lt;br /&gt;
  last_name     &amp;quot;Doe&amp;quot;&lt;br /&gt;
  date_of_birth { 18.years.ago }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
factory :post do&lt;br /&gt;
  author&lt;br /&gt;
  # instead of&lt;br /&gt;
  # association :author, factory: :user&lt;br /&gt;
  title &amp;quot;How to read a book effectively&amp;quot;&lt;br /&gt;
  body  &amp;quot;There are five steps involved.&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
factory :comment do&lt;br /&gt;
  commenter&lt;br /&gt;
  # instead of&lt;br /&gt;
  # association :commenter, factory: :user&lt;br /&gt;
  body &amp;quot;Great article!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The above code creates a factory called '''user''' and then uses that factory to add users as attributes of post and comment with a different name (author and commenter).&lt;br /&gt;
&lt;br /&gt;
===Lazy, Dependent, and Transient Attributes===&lt;br /&gt;
Attributes need not be statically defined. There are several other ways to define attributes of factories, all termed '''lazy''' attributes because they acquire a value after the object has been instantianted.&lt;br /&gt;
The simplest case of lazy attributes is the simple lazy attribute, determined by a block rather than given as a static value.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user do&lt;br /&gt;
  # ...&lt;br /&gt;
  activation_code { User.generate_activation_code }&lt;br /&gt;
  date_of_birth   { 21.years.ago }&lt;br /&gt;
end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Dependent attributes are lazy attributes that use the values of other attributes in the factory to determine their value.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user do&lt;br /&gt;
  first_name &amp;quot;Joe&amp;quot;&lt;br /&gt;
  last_name  &amp;quot;Blow&amp;quot;&lt;br /&gt;
  email { &amp;quot;#{first_name}.#{last_name}@example.com&amp;quot;.downcase }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
create(:user, last_name: &amp;quot;Doe&amp;quot;).email&lt;br /&gt;
# =&amp;gt; &amp;quot;joe.doe@example.com&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, transient attributes allow you to further modify factories and prevent repetition of code, in a way passing arguments to the factory creation function.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user do&lt;br /&gt;
  ignore do&lt;br /&gt;
    rockstar true&lt;br /&gt;
    upcased  false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  name  { &amp;quot;John Doe#{&amp;quot; - Rockstar&amp;quot; if rockstar}&amp;quot; }&lt;br /&gt;
  email { &amp;quot;#{name.downcase}@example.com&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
  after(:create) do |user, evaluator|&lt;br /&gt;
    user.name.upcase! if evaluator.upcased&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
create(:user, upcased: true).name&lt;br /&gt;
#=&amp;gt; &amp;quot;JOHN DOE - ROCKSTAR&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Further Reading===&lt;br /&gt;
Factory Girl contains far more than can be expressed in so verbose a fashion in a summary page, so be sure to read the entirety of the [https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md Getting Started] guide.&lt;br /&gt;
This guide goes through all of the above and more, in detail, with code examples.&lt;br /&gt;
&lt;br /&gt;
==Using with Ruby on Rails==&lt;br /&gt;
As mentioned earlier, Factory Girl can be used in Ruby on Rails through the factory_girl_rails gem. All of the same benefits apply, including those not mentioned above.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
A typical test scenario is benchmarking the time a sort takes to complete on a random assortment of objects. A stock Rake test fixture implementation might look something like the following:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;  person1:&lt;br /&gt;
    id: 1&lt;br /&gt;
    name: Bob&lt;br /&gt;
    dob: 10-11-1990&lt;br /&gt;
&lt;br /&gt;
  person2:&lt;br /&gt;
    id: 2&lt;br /&gt;
    name: George&lt;br /&gt;
    dob: 9-8-1990&lt;br /&gt;
&lt;br /&gt;
  person3:&lt;br /&gt;
    id: 3&lt;br /&gt;
    name: Stanley&lt;br /&gt;
    dob: 1-9-1990&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This could get tedious with more than 3 values, so you could use ERb (Embedded Ruby)&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;  &amp;lt;% for i in 1..1000 %&amp;gt;&lt;br /&gt;
  fix_&amp;lt;%= i %&amp;gt;:&lt;br /&gt;
    id: &amp;lt;%= i %&amp;gt;&lt;br /&gt;
    name: guy_&amp;lt;%= 1 %&amp;gt;&lt;br /&gt;
    dob: &amp;lt;%= Date.today.strftime(&amp;quot;%Y-%m-%d&amp;quot;) %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, this is harder to maintain and is not very DRY-friendly: it's very repetitious and you must copy the entire block any time you need to put 1000 users into a fixture. Not only that, but if you did copy the code block, if at any point the class changes you'd have to go back and change all the places you copied that code. Instead, we could use Factory Girl and expedite the process, also making it more DRY while we're at it (using some Factory Girl features not shown above)!&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;FactoryGirl.define do&lt;br /&gt;
  sequence :email do |n|&lt;br /&gt;
    &amp;quot;person#{n}@example.com&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  sequence :id do |n|&lt;br /&gt;
    #{n}&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  sequence :dob do |n|&lt;br /&gt;
    (20.years.ago)+(Random.rand(20).months)#give random DOB from 20 years ago + 0..20 months&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  factory :user do&lt;br /&gt;
    id&lt;br /&gt;
    first_name &amp;quot;John&amp;quot;&lt;br /&gt;
    last_name  &amp;quot;Doe&amp;quot;&lt;br /&gt;
    email&lt;br /&gt;
    dob&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
built_users_2500 = build_list(:user, 2500) #make 2500 users with unique email addresses and id's and random DOB&lt;br /&gt;
built_users_10 = build_list(:user, 10) #make 10 more users&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By abstracting away the creation of unique IDs for our users and giving us a factory through which to create a list of users, we need not worry about the implementation of making a group of users in our fixtures. If at any time the class changes, we need only change the file that has the factory in it, all calls to the factory remain unchanged.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Wemorrow</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1a_1k_wm&amp;diff=83577</id>
		<title>CSC/ECE 517 Spring 2014/ch1a 1k wm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1a_1k_wm&amp;diff=83577"/>
		<updated>2014-02-21T19:58:37Z</updated>

		<summary type="html">&lt;p&gt;Wemorrow: /* Background */ updated the wording of the definition and explanation of test fixtures&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Factory Girl=&lt;br /&gt;
[https://docs.google.com/document/d/1XzVu0zEuk7LP4smGZV9lRpSx5-wri6oClpUAmGYPN44/edit# Assignment Spec]&lt;br /&gt;
==Background==&lt;br /&gt;
From Factory Girl's Ruby Toolbox page&amp;lt;ref&amp;gt;https://www.ruby-toolbox.com/projects/factory_girl&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;factory_girl provides a framework and DSL for defining and using factories - less error-prone, more explicit, and all-around easier to work with than fixtures.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
Also from the Factory Girl's github page&amp;lt;ref&amp;gt;https://github.com/thoughtbot/factory_girl&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;factory_girl is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Factory Girl's purpose is to expedite good testing by creating test fixtures for the developer, eliminating the need to create large fixtures by hand. There are two versions, one for use with regular Ruby (factory_girl) and one for use with Ruby on Rails (factory_girl_rails&amp;lt;ref&amp;gt;https://github.com/thoughtbot/factory_girl_rails&amp;lt;/ref&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
'''Test fixtures''' are used to create an application state through which you can test code.&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html#the-low-down-on-fixtures&amp;lt;/ref&amp;gt; In some cases, the application state you need to build is very simple. For example, in unit testing you are testing very small pieces of code, the state that you need to set up is very small (typically one or two instances of a single model class). In other cases the application state may be complicated and the data handled very large, in which case the fixture will also be very large. Large fixtures could be used in performance testing in order to load the system up and tax its resources.&lt;br /&gt;
&lt;br /&gt;
==Generic Examples==&lt;br /&gt;
All examples taken from the github project&amp;lt;ref&amp;gt;https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md&amp;lt;/ref&amp;gt;&lt;br /&gt;
===Factories===&lt;br /&gt;
Factories are the basic unit of Factory Girl, they wrap up a constructor into a single method call that can be used in multiple test fixtures.&lt;br /&gt;
A factory looks pretty similar to a normal constructor but can be used multiple times without having to specify any parameters, as shown below.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;FactoryGirl.define do&lt;br /&gt;
  factory :user do&lt;br /&gt;
    first_name &amp;quot;John&amp;quot;&lt;br /&gt;
    last_name  &amp;quot;Doe&amp;quot;&lt;br /&gt;
    admin false&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The above creates a factory for class User (inferred by Factory Girl from the name of the factory) that can then be called in many different ways.&lt;br /&gt;
You can also define factories using specific classes, not only inferred from the name of the factory, as below (in the same word as the above example).&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;FactoryGirl.define do&lt;br /&gt;
  factory :admin, class: User do&lt;br /&gt;
    first_name &amp;quot;Admin&amp;quot;&lt;br /&gt;
    last_name  &amp;quot;User&amp;quot;&lt;br /&gt;
    admin      true&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
===Using Factories===&lt;br /&gt;
You can use factories in a variety of ways, as shown. You can also overwrite predefined attributes on the fly by passing in a hash of attributes and values.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;# Returns a User instance that's not saved&lt;br /&gt;
user = build(:user)&lt;br /&gt;
&lt;br /&gt;
# Returns a saved User instance&lt;br /&gt;
user = create(:user)&lt;br /&gt;
&lt;br /&gt;
# Returns a hash of attributes that can be used to build a User instance&lt;br /&gt;
attrs = attributes_for(:user)&lt;br /&gt;
&lt;br /&gt;
# Returns an object with all defined attributes stubbed out&lt;br /&gt;
stub = build_stubbed(:user)&lt;br /&gt;
&lt;br /&gt;
# Passing a block to any of the methods above will yield the return object&lt;br /&gt;
create(:user) do |user|&lt;br /&gt;
  user.posts.create(attributes_for(:post))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# Build a User instance and override the first_name property&lt;br /&gt;
user = build(:user, first_name: &amp;quot;Joe&amp;quot;)&lt;br /&gt;
user.first_name&lt;br /&gt;
# =&amp;gt; &amp;quot;Joe&amp;quot;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Aliasing===&lt;br /&gt;
You can utilize aliases to make somewhat more specialized factories out of existing factories, as shown.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user, aliases: [:author, :commenter] do&lt;br /&gt;
  first_name    &amp;quot;John&amp;quot;&lt;br /&gt;
  last_name     &amp;quot;Doe&amp;quot;&lt;br /&gt;
  date_of_birth { 18.years.ago }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
factory :post do&lt;br /&gt;
  author&lt;br /&gt;
  # instead of&lt;br /&gt;
  # association :author, factory: :user&lt;br /&gt;
  title &amp;quot;How to read a book effectively&amp;quot;&lt;br /&gt;
  body  &amp;quot;There are five steps involved.&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
factory :comment do&lt;br /&gt;
  commenter&lt;br /&gt;
  # instead of&lt;br /&gt;
  # association :commenter, factory: :user&lt;br /&gt;
  body &amp;quot;Great article!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The above code creates a factory called '''user''' and then uses that factory to add users as attributes of post and comment with a different name (author and commenter).&lt;br /&gt;
&lt;br /&gt;
===Lazy, Dependent, and Transient Attributes===&lt;br /&gt;
Attributes need not be statically defined. There are several other ways to define attributes of factories, all termed '''lazy''' attributes because they acquire a value after the object has been instantianted.&lt;br /&gt;
The simplest case of lazy attributes is the simple lazy attribute, determined by a block rather than given as a static value.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user do&lt;br /&gt;
  # ...&lt;br /&gt;
  activation_code { User.generate_activation_code }&lt;br /&gt;
  date_of_birth   { 21.years.ago }&lt;br /&gt;
end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Dependent attributes are lazy attributes that use the values of other attributes in the factory to determine their value.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user do&lt;br /&gt;
  first_name &amp;quot;Joe&amp;quot;&lt;br /&gt;
  last_name  &amp;quot;Blow&amp;quot;&lt;br /&gt;
  email { &amp;quot;#{first_name}.#{last_name}@example.com&amp;quot;.downcase }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
create(:user, last_name: &amp;quot;Doe&amp;quot;).email&lt;br /&gt;
# =&amp;gt; &amp;quot;joe.doe@example.com&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, transient attributes allow you to further modify factories and prevent repetition of code, in a way passing arguments to the factory creation function.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user do&lt;br /&gt;
  ignore do&lt;br /&gt;
    rockstar true&lt;br /&gt;
    upcased  false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  name  { &amp;quot;John Doe#{&amp;quot; - Rockstar&amp;quot; if rockstar}&amp;quot; }&lt;br /&gt;
  email { &amp;quot;#{name.downcase}@example.com&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
  after(:create) do |user, evaluator|&lt;br /&gt;
    user.name.upcase! if evaluator.upcased&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
create(:user, upcased: true).name&lt;br /&gt;
#=&amp;gt; &amp;quot;JOHN DOE - ROCKSTAR&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Further Reading===&lt;br /&gt;
Factory Girl contains far more than can be expressed in so verbose a fashion in a summary page, so be sure to read the entirety of the [https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md Getting Started] guide.&lt;br /&gt;
This guide goes through all of the above and more, in detail, with code examples.&lt;br /&gt;
&lt;br /&gt;
==Using with Ruby on Rails==&lt;br /&gt;
As mentioned earlier, Factory Girl can be used in Ruby on Rails through the factory_girl_rails gem. All of the same benefits apply, including those not mentioned above.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
A typical test scenario is benchmarking the time a sort takes to complete on a random assortment of objects. A stock Rake test fixture implementation might look something like the following:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;  person1:&lt;br /&gt;
    id: 1&lt;br /&gt;
    name: Bob&lt;br /&gt;
    dob: 10-11-1990&lt;br /&gt;
&lt;br /&gt;
  person2:&lt;br /&gt;
    id: 2&lt;br /&gt;
    name: George&lt;br /&gt;
    dob: 9-8-1990&lt;br /&gt;
&lt;br /&gt;
  person3:&lt;br /&gt;
    id: 3&lt;br /&gt;
    name: Stanley&lt;br /&gt;
    dob: 1-9-1990&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This could get tedious with more than 3 values, so you could use ERb (Embedded Ruby)&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;  &amp;lt;% for i in 1..1000 %&amp;gt;&lt;br /&gt;
  fix_&amp;lt;%= i %&amp;gt;:&lt;br /&gt;
    id: &amp;lt;%= i %&amp;gt;&lt;br /&gt;
    name: guy_&amp;lt;%= 1 %&amp;gt;&lt;br /&gt;
    dob: &amp;lt;%= Date.today.strftime(&amp;quot;%Y-%m-%d&amp;quot;) %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, this is harder to maintain and is not very DRY-friendly. Instead, we could use Factory Girl and expedite the process, also making it more DRY while we're at it (using some Factory Girl features not shown above)!&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;FactoryGirl.define do&lt;br /&gt;
  sequence :email do |n|&lt;br /&gt;
    &amp;quot;person#{n}@example.com&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  sequence :id do |n|&lt;br /&gt;
    #{n}&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  sequence :dob do |n|&lt;br /&gt;
    (20.years.ago)+(Random.rand(20).months)#give random DOB from 20 years ago + 0..20 months&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  factory :user do&lt;br /&gt;
    id&lt;br /&gt;
    first_name &amp;quot;John&amp;quot;&lt;br /&gt;
    last_name  &amp;quot;Doe&amp;quot;&lt;br /&gt;
    email&lt;br /&gt;
    dob&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
built_users_2500 = build_list(:user, 2500) #make 2500 users with unique email addresses and id's and random DOB&lt;br /&gt;
built_users_10 = build_list(:user, 10) #make 10 more users&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Wemorrow</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1a_1k_wm&amp;diff=83384</id>
		<title>CSC/ECE 517 Spring 2014/ch1a 1k wm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1a_1k_wm&amp;diff=83384"/>
		<updated>2014-02-15T01:02:58Z</updated>

		<summary type="html">&lt;p&gt;Wemorrow: /* Factory Girl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Factory Girl=&lt;br /&gt;
[https://docs.google.com/document/d/1XzVu0zEuk7LP4smGZV9lRpSx5-wri6oClpUAmGYPN44/edit# Assignment Spec]&lt;br /&gt;
==Background==&lt;br /&gt;
From Factory Girl's Ruby Toolbox page&amp;lt;ref&amp;gt;https://www.ruby-toolbox.com/projects/factory_girl&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;factory_girl provides a framework and DSL for defining and using factories - less error-prone, more explicit, and all-around easier to work with than fixtures.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
Also from the Factory Girl's github page&amp;lt;ref&amp;gt;https://github.com/thoughtbot/factory_girl&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;factory_girl is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Factory Girl's purpose is to expedite good testing by creating test fixtures for the developer, eliminating the need to create large fixtures by hand. There are two versions, one for use with regular Ruby (factory_girl) and one for use with Ruby on Rails (factory_girl_rails&amp;lt;ref&amp;gt;https://github.com/thoughtbot/factory_girl_rails&amp;lt;/ref&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
'''Test fixtures''' are used to create an application state through which you can test code.&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html#the-low-down-on-fixtures&amp;lt;/ref&amp;gt; This can be as simple as constructing two objects with which to perform a comparison (testing the comparison operator) or as complicated as can be imagined.&lt;br /&gt;
&lt;br /&gt;
==Generic Examples==&lt;br /&gt;
All examples taken from the github project&amp;lt;ref&amp;gt;https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md&amp;lt;/ref&amp;gt;&lt;br /&gt;
===Factories===&lt;br /&gt;
Factories are the basic unit of Factory Girl, they wrap up a constructor into a single method call that can be used in multiple test fixtures.&lt;br /&gt;
A factory looks pretty similar to a normal constructor but can be used multiple times without having to specify any parameters, as shown below.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;FactoryGirl.define do&lt;br /&gt;
  factory :user do&lt;br /&gt;
    first_name &amp;quot;John&amp;quot;&lt;br /&gt;
    last_name  &amp;quot;Doe&amp;quot;&lt;br /&gt;
    admin false&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The above creates a factory for class User (inferred by Factory Girl from the name of the factory) that can then be called in many different ways.&lt;br /&gt;
You can also define factories using specific classes, not only inferred from the name of the factory, as below (in the same word as the above example).&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;FactoryGirl.define do&lt;br /&gt;
  factory :admin, class: User do&lt;br /&gt;
    first_name &amp;quot;Admin&amp;quot;&lt;br /&gt;
    last_name  &amp;quot;User&amp;quot;&lt;br /&gt;
    admin      true&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
===Using Factories===&lt;br /&gt;
You can use factories in a variety of ways, as shown. You can also overwrite predefined attributes on the fly by passing in a hash of attributes and values.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;# Returns a User instance that's not saved&lt;br /&gt;
user = build(:user)&lt;br /&gt;
&lt;br /&gt;
# Returns a saved User instance&lt;br /&gt;
user = create(:user)&lt;br /&gt;
&lt;br /&gt;
# Returns a hash of attributes that can be used to build a User instance&lt;br /&gt;
attrs = attributes_for(:user)&lt;br /&gt;
&lt;br /&gt;
# Returns an object with all defined attributes stubbed out&lt;br /&gt;
stub = build_stubbed(:user)&lt;br /&gt;
&lt;br /&gt;
# Passing a block to any of the methods above will yield the return object&lt;br /&gt;
create(:user) do |user|&lt;br /&gt;
  user.posts.create(attributes_for(:post))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# Build a User instance and override the first_name property&lt;br /&gt;
user = build(:user, first_name: &amp;quot;Joe&amp;quot;)&lt;br /&gt;
user.first_name&lt;br /&gt;
# =&amp;gt; &amp;quot;Joe&amp;quot;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Aliasing===&lt;br /&gt;
You can utilize aliases to make somewhat more specialized factories out of existing factories, as shown.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user, aliases: [:author, :commenter] do&lt;br /&gt;
  first_name    &amp;quot;John&amp;quot;&lt;br /&gt;
  last_name     &amp;quot;Doe&amp;quot;&lt;br /&gt;
  date_of_birth { 18.years.ago }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
factory :post do&lt;br /&gt;
  author&lt;br /&gt;
  # instead of&lt;br /&gt;
  # association :author, factory: :user&lt;br /&gt;
  title &amp;quot;How to read a book effectively&amp;quot;&lt;br /&gt;
  body  &amp;quot;There are five steps involved.&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
factory :comment do&lt;br /&gt;
  commenter&lt;br /&gt;
  # instead of&lt;br /&gt;
  # association :commenter, factory: :user&lt;br /&gt;
  body &amp;quot;Great article!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The above code creates a factory called '''user''' and then uses that factory to add users as attributes of post and comment with a different name (author and commenter).&lt;br /&gt;
&lt;br /&gt;
===Lazy, Dependent, and Transient Attributes===&lt;br /&gt;
Attributes need not be statically defined. There are several other ways to define attributes of factories, all termed '''lazy''' attributes because they acquire a value after the object has been instantianted.&lt;br /&gt;
The simplest case of lazy attributes is the simple lazy attribute, determined by a block rather than given as a static value.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user do&lt;br /&gt;
  # ...&lt;br /&gt;
  activation_code { User.generate_activation_code }&lt;br /&gt;
  date_of_birth   { 21.years.ago }&lt;br /&gt;
end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Dependent attributes are lazy attributes that use the values of other attributes in the factory to determine their value.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user do&lt;br /&gt;
  first_name &amp;quot;Joe&amp;quot;&lt;br /&gt;
  last_name  &amp;quot;Blow&amp;quot;&lt;br /&gt;
  email { &amp;quot;#{first_name}.#{last_name}@example.com&amp;quot;.downcase }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
create(:user, last_name: &amp;quot;Doe&amp;quot;).email&lt;br /&gt;
# =&amp;gt; &amp;quot;joe.doe@example.com&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, transient attributes allow you to further modify factories and prevent repetition of code, in a way passing arguments to the factory creation function.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user do&lt;br /&gt;
  ignore do&lt;br /&gt;
    rockstar true&lt;br /&gt;
    upcased  false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  name  { &amp;quot;John Doe#{&amp;quot; - Rockstar&amp;quot; if rockstar}&amp;quot; }&lt;br /&gt;
  email { &amp;quot;#{name.downcase}@example.com&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
  after(:create) do |user, evaluator|&lt;br /&gt;
    user.name.upcase! if evaluator.upcased&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
create(:user, upcased: true).name&lt;br /&gt;
#=&amp;gt; &amp;quot;JOHN DOE - ROCKSTAR&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Further Reading===&lt;br /&gt;
Factory Girl contains far more than can be expressed in so verbose a fashion in a summary page, so be sure to read the entirety of the [https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md Getting Started] guide.&lt;br /&gt;
This guide goes through all of the above and more, in detail, with code examples.&lt;br /&gt;
&lt;br /&gt;
==Using with Ruby on Rails==&lt;br /&gt;
As mentioned earlier, Factory Girl can be used in Ruby on Rails through the factory_girl_rails gem. All of the same benefits apply, including those not mentioned above.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
A typical test scenario is benchmarking the time a sort takes to complete on a random assortment of objects. A stock Rake test fixture implementation might look something like the following:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;  person1:&lt;br /&gt;
    id: 1&lt;br /&gt;
    name: Bob&lt;br /&gt;
    dob: 10-11-1990&lt;br /&gt;
&lt;br /&gt;
  person2:&lt;br /&gt;
    id: 2&lt;br /&gt;
    name: George&lt;br /&gt;
    dob: 9-8-1990&lt;br /&gt;
&lt;br /&gt;
  person3:&lt;br /&gt;
    id: 3&lt;br /&gt;
    name: Stanley&lt;br /&gt;
    dob: 1-9-1990&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This could get tedious with more than 3 values, so you could use ERb (Embedded Ruby)&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;  &amp;lt;% for i in 1..1000 %&amp;gt;&lt;br /&gt;
  fix_&amp;lt;%= i %&amp;gt;:&lt;br /&gt;
    id: &amp;lt;%= i %&amp;gt;&lt;br /&gt;
    name: guy_&amp;lt;%= 1 %&amp;gt;&lt;br /&gt;
    dob: &amp;lt;%= Date.today.strftime(&amp;quot;%Y-%m-%d&amp;quot;) %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, this is harder to maintain and is not very DRY-friendly. Instead, we could use Factory Girl and expedite the process, also making it more DRY while we're at it (using some Factory Girl features not shown above)!&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;FactoryGirl.define do&lt;br /&gt;
  sequence :email do |n|&lt;br /&gt;
    &amp;quot;person#{n}@example.com&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  sequence :id do |n|&lt;br /&gt;
    #{n}&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  sequence :dob do |n|&lt;br /&gt;
    (20.years.ago)+(Random.rand(20).months)#give random DOB from 20 years ago + 0..20 months&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  factory :user do&lt;br /&gt;
    id&lt;br /&gt;
    first_name &amp;quot;John&amp;quot;&lt;br /&gt;
    last_name  &amp;quot;Doe&amp;quot;&lt;br /&gt;
    email&lt;br /&gt;
    dob&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
built_users_2500 = build_list(:user, 2500) #make 2500 users with unique email addresses and id's and random DOB&lt;br /&gt;
built_users_10 = build_list(:user, 10) #make 10 more users&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Wemorrow</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1a_1k_wm&amp;diff=83383</id>
		<title>CSC/ECE 517 Spring 2014/ch1a 1k wm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2014/ch1a_1k_wm&amp;diff=83383"/>
		<updated>2014-02-15T01:01:15Z</updated>

		<summary type="html">&lt;p&gt;Wemorrow: Page creation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Factory Girl=&lt;br /&gt;
==Background==&lt;br /&gt;
From Factory Girl's Ruby Toolbox page&amp;lt;ref&amp;gt;https://www.ruby-toolbox.com/projects/factory_girl&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;factory_girl provides a framework and DSL for defining and using factories - less error-prone, more explicit, and all-around easier to work with than fixtures.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
Also from the Factory Girl's github page&amp;lt;ref&amp;gt;https://github.com/thoughtbot/factory_girl&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;factory_girl is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Factory Girl's purpose is to expedite good testing by creating test fixtures for the developer, eliminating the need to create large fixtures by hand. There are two versions, one for use with regular Ruby (factory_girl) and one for use with Ruby on Rails (factory_girl_rails&amp;lt;ref&amp;gt;https://github.com/thoughtbot/factory_girl_rails&amp;lt;/ref&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
'''Test fixtures''' are used to create an application state through which you can test code.&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html#the-low-down-on-fixtures&amp;lt;/ref&amp;gt; This can be as simple as constructing two objects with which to perform a comparison (testing the comparison operator) or as complicated as can be imagined.&lt;br /&gt;
&lt;br /&gt;
==Generic Examples==&lt;br /&gt;
All examples taken from the github project&amp;lt;ref&amp;gt;https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md&amp;lt;/ref&amp;gt;&lt;br /&gt;
===Factories===&lt;br /&gt;
Factories are the basic unit of Factory Girl, they wrap up a constructor into a single method call that can be used in multiple test fixtures.&lt;br /&gt;
A factory looks pretty similar to a normal constructor but can be used multiple times without having to specify any parameters, as shown below.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;FactoryGirl.define do&lt;br /&gt;
  factory :user do&lt;br /&gt;
    first_name &amp;quot;John&amp;quot;&lt;br /&gt;
    last_name  &amp;quot;Doe&amp;quot;&lt;br /&gt;
    admin false&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The above creates a factory for class User (inferred by Factory Girl from the name of the factory) that can then be called in many different ways.&lt;br /&gt;
You can also define factories using specific classes, not only inferred from the name of the factory, as below (in the same word as the above example).&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;FactoryGirl.define do&lt;br /&gt;
  factory :admin, class: User do&lt;br /&gt;
    first_name &amp;quot;Admin&amp;quot;&lt;br /&gt;
    last_name  &amp;quot;User&amp;quot;&lt;br /&gt;
    admin      true&lt;br /&gt;
  end&lt;br /&gt;
end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
===Using Factories===&lt;br /&gt;
You can use factories in a variety of ways, as shown. You can also overwrite predefined attributes on the fly by passing in a hash of attributes and values.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;# Returns a User instance that's not saved&lt;br /&gt;
user = build(:user)&lt;br /&gt;
&lt;br /&gt;
# Returns a saved User instance&lt;br /&gt;
user = create(:user)&lt;br /&gt;
&lt;br /&gt;
# Returns a hash of attributes that can be used to build a User instance&lt;br /&gt;
attrs = attributes_for(:user)&lt;br /&gt;
&lt;br /&gt;
# Returns an object with all defined attributes stubbed out&lt;br /&gt;
stub = build_stubbed(:user)&lt;br /&gt;
&lt;br /&gt;
# Passing a block to any of the methods above will yield the return object&lt;br /&gt;
create(:user) do |user|&lt;br /&gt;
  user.posts.create(attributes_for(:post))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# Build a User instance and override the first_name property&lt;br /&gt;
user = build(:user, first_name: &amp;quot;Joe&amp;quot;)&lt;br /&gt;
user.first_name&lt;br /&gt;
# =&amp;gt; &amp;quot;Joe&amp;quot;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Aliasing===&lt;br /&gt;
You can utilize aliases to make somewhat more specialized factories out of existing factories, as shown.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user, aliases: [:author, :commenter] do&lt;br /&gt;
  first_name    &amp;quot;John&amp;quot;&lt;br /&gt;
  last_name     &amp;quot;Doe&amp;quot;&lt;br /&gt;
  date_of_birth { 18.years.ago }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
factory :post do&lt;br /&gt;
  author&lt;br /&gt;
  # instead of&lt;br /&gt;
  # association :author, factory: :user&lt;br /&gt;
  title &amp;quot;How to read a book effectively&amp;quot;&lt;br /&gt;
  body  &amp;quot;There are five steps involved.&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
factory :comment do&lt;br /&gt;
  commenter&lt;br /&gt;
  # instead of&lt;br /&gt;
  # association :commenter, factory: :user&lt;br /&gt;
  body &amp;quot;Great article!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The above code creates a factory called '''user''' and then uses that factory to add users as attributes of post and comment with a different name (author and commenter).&lt;br /&gt;
&lt;br /&gt;
===Lazy, Dependent, and Transient Attributes===&lt;br /&gt;
Attributes need not be statically defined. There are several other ways to define attributes of factories, all termed '''lazy''' attributes because they acquire a value after the object has been instantianted.&lt;br /&gt;
The simplest case of lazy attributes is the simple lazy attribute, determined by a block rather than given as a static value.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user do&lt;br /&gt;
  # ...&lt;br /&gt;
  activation_code { User.generate_activation_code }&lt;br /&gt;
  date_of_birth   { 21.years.ago }&lt;br /&gt;
end&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Dependent attributes are lazy attributes that use the values of other attributes in the factory to determine their value.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user do&lt;br /&gt;
  first_name &amp;quot;Joe&amp;quot;&lt;br /&gt;
  last_name  &amp;quot;Blow&amp;quot;&lt;br /&gt;
  email { &amp;quot;#{first_name}.#{last_name}@example.com&amp;quot;.downcase }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
create(:user, last_name: &amp;quot;Doe&amp;quot;).email&lt;br /&gt;
# =&amp;gt; &amp;quot;joe.doe@example.com&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, transient attributes allow you to further modify factories and prevent repetition of code, in a way passing arguments to the factory creation function.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;factory :user do&lt;br /&gt;
  ignore do&lt;br /&gt;
    rockstar true&lt;br /&gt;
    upcased  false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  name  { &amp;quot;John Doe#{&amp;quot; - Rockstar&amp;quot; if rockstar}&amp;quot; }&lt;br /&gt;
  email { &amp;quot;#{name.downcase}@example.com&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
  after(:create) do |user, evaluator|&lt;br /&gt;
    user.name.upcase! if evaluator.upcased&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
create(:user, upcased: true).name&lt;br /&gt;
#=&amp;gt; &amp;quot;JOHN DOE - ROCKSTAR&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Further Reading===&lt;br /&gt;
Factory Girl contains far more than can be expressed in so verbose a fashion in a summary page, so be sure to read the entirety of the [https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md Getting Started] guide.&lt;br /&gt;
This guide goes through all of the above and more, in detail, with code examples.&lt;br /&gt;
&lt;br /&gt;
==Using with Ruby on Rails==&lt;br /&gt;
As mentioned earlier, Factory Girl can be used in Ruby on Rails through the factory_girl_rails gem. All of the same benefits apply, including those not mentioned above.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
A typical test scenario is benchmarking the time a sort takes to complete on a random assortment of objects. A stock Rake test fixture implementation might look something like the following:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;  person1:&lt;br /&gt;
    id: 1&lt;br /&gt;
    name: Bob&lt;br /&gt;
    dob: 10-11-1990&lt;br /&gt;
&lt;br /&gt;
  person2:&lt;br /&gt;
    id: 2&lt;br /&gt;
    name: George&lt;br /&gt;
    dob: 9-8-1990&lt;br /&gt;
&lt;br /&gt;
  person3:&lt;br /&gt;
    id: 3&lt;br /&gt;
    name: Stanley&lt;br /&gt;
    dob: 1-9-1990&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This could get tedious with more than 3 values, so you could use ERb (Embedded Ruby)&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;  &amp;lt;% for i in 1..1000 %&amp;gt;&lt;br /&gt;
  fix_&amp;lt;%= i %&amp;gt;:&lt;br /&gt;
    id: &amp;lt;%= i %&amp;gt;&lt;br /&gt;
    name: guy_&amp;lt;%= 1 %&amp;gt;&lt;br /&gt;
    dob: &amp;lt;%= Date.today.strftime(&amp;quot;%Y-%m-%d&amp;quot;) %&amp;gt;&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, this is harder to maintain and is not very DRY-friendly. Instead, we could use Factory Girl and expedite the process, also making it more DRY while we're at it (using some Factory Girl features not shown above)!&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;FactoryGirl.define do&lt;br /&gt;
  sequence :email do |n|&lt;br /&gt;
    &amp;quot;person#{n}@example.com&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  sequence :id do |n|&lt;br /&gt;
    #{n}&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  sequence :dob do |n|&lt;br /&gt;
    (20.years.ago)+(Random.rand(20).months)#give random DOB from 20 years ago + 0..20 months&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  factory :user do&lt;br /&gt;
    id&lt;br /&gt;
    first_name &amp;quot;John&amp;quot;&lt;br /&gt;
    last_name  &amp;quot;Doe&amp;quot;&lt;br /&gt;
    email&lt;br /&gt;
    dob&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
built_users_2500 = build_list(:user, 2500) #make 2500 users with unique email addresses and id's and random DOB&lt;br /&gt;
built_users_10 = build_list(:user, 10) #make 10 more users&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Wemorrow</name></author>
	</entry>
</feed>