heartcombo / devise

Flexible authentication solution for Rails with Warden.
http://blog.plataformatec.com.br/tag/devise/
MIT License
23.88k stars 5.54k forks source link

after_inactive_sign_up_path_for callback ins't called when testing it with ActionDispatch::IntegrationTest #5479

Closed jonibatista closed 2 years ago

jonibatista commented 2 years ago

Environment

Current behavior

Rails.application.routes.draw do
  root "home#index"

  ...

  devise_for :users, module: :users
end
class Users::RegistrationsController < Devise::RegistrationsController

  ...

  def after_inactive_sign_up_path_for(resource)
    debugger
    super(resource)
    root_url
  end
end

require 'test_helper'


class Users::RegistrationsControllerTest < ActionDispatch::IntegrationTest
  include Devise::Test::IntegrationHelpers

  ...

  test 'POST create' do
    post "/users", params: { email: "mail@mail.mail", 
      password: "secret", password_confirmation: "secret" }
    assert_redirected_to root_url
  end
end

Expected behavior

Although it works as expected when testing it manually, it fails when creating an integration test for the sign_up with activation account module:

Expected response to be a <3XX: redirect>, but was a <200: OK>

jonibatista commented 2 years ago

I was messing the user at params

test 'POST create' do
  assert_difference 'User.count' do
    post '/users', params: { user: { name: "Jóni", email: "mail@mail", 
      password: "secrets", password_confirmation: "secrets" } }
  end
  assert_redirected_to root_url
end

Then I realize that by default devise redirects to root_url. Since I'm using turbo I didn't notice this at first due to https://github.com/hotwired/turbo-rails/issues/122

class Users::RegistrationsController < Devise::RegistrationsController

  ...

  # def after_inactive_sign_up_path_for(resource)
  #  super(resource)
  # end
end