Skip to content

Getting undefined method make_response! for overridden Devise controller class #1158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
terenceponce opened this issue Apr 30, 2018 · 6 comments

Comments

@terenceponce
Copy link

When posting issues, please include the following information to speed up the troubleshooting process:

  • Version: 0.1.43
  • Rails Stacktrace:
Error:
Api::Devise::RegistrationsController#test_user_creation_with_valid_input_succeeds:
NoMethodError: undefined method `make_response!' for Api::Devise::RegistrationsController:Class
    test/controllers/api/devise/registrations_controller_test.rb:12:in `block in <class:RegistrationsController>'
  • Environmental Info:

    • Routes:
    mount_devise_token_auth_for 'User', at: 'auth', controllers: {
      registrations: 'api/devise/registrations'
    }
    
    • Gems: Just a fresh Rails app in API mode (--api)
    • Custom Overrides: I tried overriding the Registrations controller but haven't really done anything different yet:
    module Api
      module Devise
        class RegistrationsController < DeviseTokenAuth::RegistrationsController
          include DeviseTokenAuth::Concerns::SetUserByToken
    
          def create
            super
          end
        end
      end
    end
    
    • Custom Frontend: No frontend yet.

I made a fresh Rails app and tried using this gem. I was hoping to override the controllers so I can use this gem with Versionist and apipie-rails. Here's a test that I made just to make sure that the gem works as expected out of the box:

require 'test_helper'

class Api::Devise::RegistrationsController < ActionDispatch::IntegrationTest
  test "user creation with valid input succeeds" do
    user_params = {
      email: '[email protected]',
      password: 'securepassword',
      password_confirmation: 'securepassword',
      confirm_success_url: 'http://localhost:3000'
    }

    post user_registration_url, params: user_params
    body = JSON.parse(response.body)
    assert_response :success
  end
end

This test works if I just use the default route that devise_token_auth comes with. However, if I try to use my override controller instead, it produces this error:

Error:
Api::Devise::RegistrationsController#test_user_creation_with_valid_input_succeeds:
NoMethodError: undefined method `make_response!' for Api::Devise::RegistrationsController:Class
    test/controllers/api/devise/registrations_controller_test.rb:12:in `block in <class:RegistrationsController>'

I tried searching everywhere for the solution, but I found nothing so I'm hoping someone can help me out on this.

@MaicolBen
Copy link
Collaborator

is that your code? we don't have any make_response in the code

@terenceponce
Copy link
Author

No. It's just a fresh Rails 5.2 app. I certainly haven't written any code aside from the things needed to integrate devise_token_auth and override one of the controllers.

@MaicolBen
Copy link
Collaborator

MaicolBen commented May 4, 2018

The registrations controller could be inheriting from the wrong controller, also, Api::Devise::RegistrationsController in the test should be Api::Devise::RegistrationsControllerTest or something like that. Otherwise, you are putting a test in the real class.

@dlt
Copy link

dlt commented May 10, 2018

@terenceponce this happened because you're trying to open the Devise::RegistrationsController class to override it, but instead is creating a new class Api::Devise::RegistrationsController.

One way to solve your problem would be to create an initializer and put the following in it:

Devise::RegistrationsController.class_eval do
  include DeviseTokenAuth::Concerns::SetUserByToken
  def create
    super
  end
end

@iarobinson
Copy link

iarobinson commented Mar 5, 2019

I had this error and when my code was like this:

class Organizations::PaymentMethodsController
  def index
  end
end

... then I made it like this and it worked:

class Organizations::PaymentMethodsController < ApplicationController
  def index
  end
end

@juliofalbo
Copy link

juliofalbo commented May 19, 2021

I know that it is old, but you can just make a little workaround to trigger the autoloading.

stub_const("#{Model}::CONST", 2) as suggested here by @JonRowe: rspec/rspec-mocks#1079 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants