Part 1: add a Director field to Movies
Create and apply a migration that adds the director field to the movies table. The director field should be a string containing the name of the movie’s director.
Hint: you may find useful the add_column method of ActiveRecord::Migration.
Remember that once the migration is applied, you also have to do bundle exec rails db:test:prepare to load the new post-migration schema into the test database.
Clearly, now that a new field has been added, we will have to modify the Views so that the user can see and enter values for that field. Do we also have to modify the model file in order for the new field to be "noticed"?
Nope. ActiveRecord infers the columns and their data types by inspecting the database. However, if we wanted to have a validation on that column, we'd have to specifically mention it in a validates call.
Look at the step definitions for the failing steps of the Cucumber scenarios. (Where would you find those definitions?) Based on the step definitions, which step(s) of the scenario file would you now expect to pass if you re-run Cucumber, and why?
Once this field is added, runningbundle exec cucumbershould allow theBackground:steps to pass, since they just use ActiveRecord directly to create movies with a director field. But the other scenarios all manipulate the user interface (the views), which you have not yet modified, so they will still fail.
Verify that the Cucumber steps you expect to pass actually do pass.
If you're still with us, the background steps now pass, but the very
first step of each scenario fails, because you're asking Cucumber to
"visit a page" but you haven't provided a mapping between the
human-readable name of the page (e.g. the edit page for "Alien")
and the actual path (URL) that would go to that page in
RottenPotatoes. Where will you need to add this mapping (in what
file and what method in that file)? (Hint:
read the error message carefully, and look for the implementation of the
When I visit... step def.)
The step def just calls the underlying Capybara methodvisit, but relies on a method calledpath_to(...)that is supposed to translate a plain-language phrase such as 'the edit page for "Alien"' into a URL. In some cases, an argument in the plain-language phrase is captured and substituted into the URL. This is the method where you must add a clause to handle the new feature.
Besides modifying the Views, will we have to modify anything in the controller? If so, what?
Yes: we have to add:directorto the list of movie attributes in thedef movie_paramsmethod inmovies_controller.rb. Otherwise, even if that value is available asparams["movie"]["director"], it will be "scrubbed" by therequireandpermitcalls onparamsbefore the controller actions are able to see it.
Which controller actions, specifically, would fail to work if we didn't make the above change?
createandupdatewould fail, since they are the ones that expect a form submission inparamsin whichparams["movies"]should appear. The other actions do not expect or manipulate this form (and do not call the helper functionmovie_params) so they would not be affected.
Based on the above self-checks, you should be able to modify the controller and views as needed to be “aware” of the new director field.