Read Sections 1, 2, 4, 5, 6, and 7 of the Rails Guide on Testing. These are the kinds of tests that we write most frequently.
Then, take a stab at writing some System tests to lock down the current functionality of the application. After you've spent 20-30 minutes on it, you're allowed to look at the example specs in test/system/example_movies_test.rb
.
- Anywhere you see the old
Hash
syntax (:symbol
keys with hash rockets=>
): switch to the newHash
syntax. - Anywhere you see optional curly braces around
Hash
arguments: remove them. - Where possible, drop
render
statements. - When providing keys to
params
, useSymbol
s. (Unlike with most hashes, you can useString
s andSymbol
s interchangeably as keys toparams
.)
- Re-write routes using more succinct forms of
get
,post
,patch
,delete
, and, ultimately,resources
.
- Replace all references to URLs outside of
config/routes.rb
with route helper methods. - Replace all
<a>
elements in view templates withlink_to
methods.
- Replace all
<form>
elements in view templates withform_with
methods. - Replace all
<input>
elements withtext_field_tag
,number_field_tag
,text_area_tag
, etc.
- Change the names of inputs so that values in the
params
hash are nested within an inner hash. - Assign all of the values at once using ActiveRecord's mass assignment ability via
new
orupdate
. - Whitelist which attributes you want to allow to be mass assigned from
params
withparams.require(:movie).permit(:title, :description)
. - Switch from
form_with(url:)
toform_with(model:)
- Switch from
text_field_tag
, etc; toform.text_field
, etc. - Move form to partial and re-use wherever possible.