mercredi 23 septembre 2015

How to DRY up controller tests

I have dozens of controller tests that go to the tune of:

test "GET #show when not authenticated" do
  get :show, { id: 1 }
  assert_redirected_to '/login'
end

But my application_controller is locked down by default.

class ApplicationController < ActionController::Base
  before_action :ensure_logged_in
end

I should not have to add this test to every controller test. But I don't want to test one controller only.

How can I test that my application is locked down without littering my controller tests with this repetition?

Aucun commentaire:

Enregistrer un commentaire