WendyBeth/learn-api — pull request #2 by jonathanyeong (2014-12-03 08:32:01+00:00)
Title: Add validation to for artist id

Fixes issue #1.

Check if artist id has an existing artist. If it doesn't then the validation will fail. This prevents the album model saving an album with an invalid artist id. Previously, the album could be saved with an invalid artist id. However, when Album#index page was called it would throw an exception since there was no artist linked to the artist id.

- Add validation in Album model to check if artist id references a valid artist row.
- Make test suite pass by explicitly setting artist id to 1 in the necessary places. The active record fixture docs explain what happen when you don't explicitly set an id. See [Stable, Autogenerated IDs](http://api.rubyonrails.org/v3.2.8/classes/ActiveRecord/Fixtures.html)
- Add a new test to check that an album cannot be saved without a valid artist id.
- Reword testing the test for an empty artist id for readability.