Skip to content

Instantly share code, notes, and snippets.

@emilford
Last active March 10, 2017 20:52
Show Gist options
  • Save emilford/503969b3251db29d64de603526e89ac6 to your computer and use it in GitHub Desktop.
Save emilford/503969b3251db29d64de603526e89ac6 to your computer and use it in GitHub Desktop.
03-10-2017 Pairing w/ Meredith

03-10-2017

Feature Tests

  • They are a good choice for happy path tests. Sad paths are often times tested elsewhere (e.g., a controller test).
  • They are like using a browser (just a headless one) and exercise the entire application stack.
  • They are generally slower to run than other types of tests.
  • They assert expectations mostly from the user's perspective (e.g., things visible to the user), but will occasionally need to assert an expectation against something only the application knows (e.g., Feedback.count)

Strong Params

Strong Params allows us to require and control what data we accept from the browser request's parameters.

feedback = Feedback.new(feedback_params)

...

def feedback_params
  params.permit(:feedback).permit(:note)
end

http://edgeguides.rubyonrails.org/action_controller_overview.html#strong-parameters

Binding.pry

Adding a binding.pry statement anywhere in the code execution path will stop the execution at that point. It's a great tool for testing and exploring code, checking method return values and variables.

https://github.com/pry/pry/wiki

Flash

  • flash[:notice]
  • flash[:alert]
  • flash.now[:alert] vs flash[:alert]
  • redirect_to some_path, notice: "some notice" shorthand

Validations

ActiveRecord validations add constraints to your model (different from the database constraints) to ensure that Rails will only save valid data to the database. Today we use the presence validator, but there are many, many others.

  • validates :note, presence: true

http://guides.rubyonrails.org/active_record_validations.html

Redirect/Render

  • redirect_to some_path
  • render :some_action

http://tosbourn.com/difference-between-redirect-render-rails/

Controller Specs

  • render_template
  • flash
  • post :create, params: { some values }

https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment