From 7904cac5b7d0401ab29de24f46a72f2cae2a4d85 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Tue, 12 Jan 2021 20:39:02 -0600 Subject: [PATCH] Add Include Devise Helpers In Your Controller Tests as a rails til --- README.md | 3 ++- ...devise-helpers-in-your-controller-tests.md | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 rails/include-devise-helpers-in-your-controller-tests.md diff --git a/README.md b/README.md index af992a0..564a099 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_1005 TILs and counting..._ +_1006 TILs and counting..._ --- @@ -628,6 +628,7 @@ _1005 TILs and counting..._ - [Get The Column Names For A Model](rails/get-the-column-names-for-a-model.md) - [Hash Slicing](rails/hash-slicing.md) - [Ignore Poltergeist JavaScript Errors](rails/ignore-poltergeist-javascript-errors.md) +- [Include Devise Helpers In Your Controller Tests](rails/include-devise-helpers-in-your-controller-tests.md) - [Inspect Previous Changes To ActiveRecord Object](rails/inspect-previous-changes-to-activerecord-object.md) - [List All Installable Rails Versions](rails/list-all-installable-rails-versions.md) - [List The Enqueued Jobs](rails/list-the-enqueued-jobs.md) diff --git a/rails/include-devise-helpers-in-your-controller-tests.md b/rails/include-devise-helpers-in-your-controller-tests.md new file mode 100644 index 0000000..100f37e --- /dev/null +++ b/rails/include-devise-helpers-in-your-controller-tests.md @@ -0,0 +1,24 @@ +# Include Devise Helpers In Your Controller Tests + +For past versions of Devise, you could include `DeviseHelpers` as part of +`controller` or `request` type tests to have access to the `sign_in` and +`sign_out` helpers. + +```ruby +RSpec.configure do |config| + config.include Devise::TestHelpers, :type => :controller +end +``` + +As of [Devise +4.2.0+](https://github.com/heartcombo/devise/blob/master/CHANGELOG.md#420---2016-07-01), +the `Devise::TestHelpers` have been deprecated. The +`Devise::Test::ControllerHelpers` module should instead be included. + +```ruby +RSpec.configure do |config| + config.include Devise::Test::ControllerHelpers, :type => :controller +end +``` + +[source](https://github.com/heartcombo/devise/blob/98fc5e8e396b66b826528811287ea6680a6d0757/lib/devise/test/controller_helpers.rb#L26)