This app demonstrates the pitfalls of implementing fat controllers.
- Move code that belongs in the model out of the controller.
- You'll get the model spec examples to pass
- Use
ActiveRecord
methods to accomplish this. - You'll also need to create a migration!
- From the app's root directory, run:
$ bundle install
$ rake db:create
$ rake db:migrate
$ rake db:seed
$ rake db:test:prepare
rake db:test:prepare
just checks to see if there are any pending migrations for our test database, and make sure our test environment and development environment are in-sync when we run our tests.
- Take a look at the file
db/seeds.rb
to see how we are seeding the database
-
Note: Do this First
-
You'll need to create a migration that will add the
domain_name
field as astring
to thepeople
tablePro-tip: Make sure to run your migrations, and prepare the test database
-
Populate all instances of
People
with the appropriatedomain_name
Hint: What current property of
people
has data you could draw from?Hint: How could you modify that data to only capture the appropriate
domain_name
?Look at the current implementations in the
person_controller.rb
-
To get a quick refresher on how to generate a migration, check out the guides
- Your method should take one argument representing a
domain
. - The return of the method should be all instances of
Person
that match that given domain, or return everyone if passedAll
Research Rails Validations and Active Record Callbacks to look into how to control for user input
-
Make all the pending tests active by removing the
x
fromxit
on lines 60, 64, and 76 inspec/models/person_spec.rb
-
Get the appropriate tests to pass by defining
sanitize_email
andgenerate_domain_name
as instance methods.sanitize_email
should make all emails a uniform casegenerate_domain_name
will add adomain_name
to aperson
if they are created without one
-
Use these methods as Active Record callbacks.
Thanks http://www.briandunning.com/sample-data/ for the sample data!