When a user visits the new author page
And fills in 'Alan', 'Turing', and 'http://wikipedia.org/Alan_Turing', respectively
And submits the form
Then Alan Turing should be found in the database
Hints
Write a test that visits the new-author page, fills in the 'new author' form and submits it.
Use fill_in to enter data into input fields.
Submit the form using the find and click methods.
Try a new it block in new_author_spec.rb.
Make the failing test pass by saving the POSTed form data in a new Author database object.
This is the task of a create action in authors_controller.rb.
Make sure to set the :url option of the form_with, to control where the data will be POSTed to. Read up on "strong parameters" and whitelisting of required parameters.
Do not issue a redirect_to @author, as this will error (there is no code for showing authors yet). Instead you can redirect_to root_path, notice: 'Success!'.
Tips:
Your browser's dev tools are helpful in debugging and inspecting HTML.
rails console allows you to interact with stored object in an interactive shell, e.g. Author.count shows the amount of stored authors.
Scenario
When a user visits the new author page And fills in 'Alan', 'Turing', and 'http://wikipedia.org/Alan_Turing', respectively And submits the form Then Alan Turing should be found in the database
Hints
Write a test that visits the new-author page, fills in the 'new author' form and submits it. Use
fill_in
to enter data into input fields. Submit the form using thefind
andclick
methods. Try a newit
block innew_author_spec.rb
.Here is the relevant section in the guide.
Make the failing test pass by saving the POSTed form data in a new Author database object. This is the task of a
create
action inauthors_controller.rb
. Make sure to set the:url
option of theform_with
, to control where the data will be POSTed to. Read up on "strong parameters" and whitelisting of required parameters.Do not issue a
redirect_to @author
, as this will error (there is no code for showing authors yet). Instead you canredirect_to root_path, notice: 'Success!'
.Tips:
rails console
allows you to interact with stored object in an interactive shell, e.g.Author.count
shows the amount of stored authors.Error
6/44 exercise tests have passed