swt2-intro-exercise / rails-exercise-18-Kenneth-Schroeder

rails-exercise-18-Kenneth-Schroeder created by GitHub Classroom
MIT License
1 stars 0 forks source link

New author page should save the author #5

Open swt2public opened 5 years ago

swt2public commented 5 years ago

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

To test this feature, you need to simulate a user filling in an authors's data into the 'new author' form and submitting it. In the test, after visiting the new-author page, you can use fill_in to enter data into the input fields. Using the find and click methods, you can submit the form.

visit new_author_path
page.fill_in 'author[last_name]', with: 'Dijkstra'
...
find('input[type="submit"]').click

A new it block in spec/features/author/new_author_spec.rb might be helpful. For more information, see the Capybara reference.

After writing the now failing test, we need to save the form data that is sent to the AuthorsController in an object in the database. This is the task of a create action in the app/controllers/authors_controller.rb controller file. Here is the relevant section in the Ruby on Rails guide. Don't forget about strong parameter and to whitelist the required parameters.

You can can the amount of authors in the database using the rails console (rails console): Author.count. If you issue a redirect to the author instance (redirect_to), this will lead to an error, as there is no code for showing authors yet.

Error

Got ActiveRecord::RecordNotFound: Couldn't find Author

Estimated progress: 17% complete