1

I'm having custom controller

class Users::SessionsController < Devise::SessionsController
  # POST /resource/sign_in
  def create
    binding.pry
    super
  end
end

routes added

devise_for :users, controllers: { sessions: "users/sessions" }

and it works during signin using browser. But inside controller test breakpoint inside create is not being hit:

RSpec.describe Users::SessionsController, type: :controller do

  describe 'POST #create' do

    context 'pending activation user with expired password' do
      it 'could not login' do
        user = create :operator_user, status: User.statuses[:activation_pending], password_changed_at: (1.day + 1.second).ago
        @request.env['devise.mapping'] = Devise.mappings[:user]
        sign_in user

        user.reload
        expect(user).to be_locked
      end
    end
  end

end

RSpec.configure do |config|
  #...
  # Devise methods
  config.include Devise::TestHelpers, type: :controller
  # ...
end

I expect expression sign_in user to fall into create method that I've overrided. What am I doing wrong?

ps: it even falls into standard devise SessionsController#create

1 Answer 1

4

You have to send request to controller by using post :create, params: {...} inside your example instead of sign_in user

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.