Search code examples
ruby-on-railsrubydevisewarden

How to sign in without warden callback on rspec (request spec)


I'd like to call sign_in(user) on request spec without warden callback.
Does anybody know a workaround?

I want to use something like bypass_sign_in on request spec.

I tried below.

    1. I added Devise::Test::IntegrationHelpers to my spec/rails_helper.rb
config.include Devise::Test::IntegrationHelpers, type: :feature
  • 2-a. I write request spec like this. It works. but it calls warden callbacks
RSpec.describe '/ajax/stores', type: :request do
    context 'login as valid user' do
      it do
        sign_in(user)
      end
    end
end
  • 2-b. I write request another spec using login_as(warden's method) but it also calls warden callbacks
RSpec.describe '/ajax/stores', type: :request do
    context 'login as valid user' do
      it do
        login_as(user, bypass: true)
      end
    end
end

Solution

  • You can pass run_callbacks: false option to Warden's login_as helper:

    login_as(user, run_callbacks: false)