Skip to content
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

authenticate_user! disables all other callbacks, doesn't authenticate at all #331

Open
samnissen opened this issue Mar 7, 2018 · 0 comments
Labels
support request This issue is a request for support using Simple Token Authentication.

Comments

@samnissen
Copy link

Similar to #277 but worse because I can't write any code to route around, since attempting to authenticate is the last callback that can execute. (Note in the below example this_fn_does_not_exist! truly does not exist.)

class ApplicationController < ActionController::API
  acts_as_token_authentication_handler_for User, fallback: :none
  # ...
class MyModelsController < ApplicationController
  before_action :authenticate_user!
  before_action :this_fn_does_not_exist!
  # ...
require 'rails_helper'

RSpec.describe MyModelsController, type: :controller do
  # ...
  let(:invalid_session) { { } }

  describe "GET #show" do
    it "does not assign the requested my_model as @my_model" do
      @my_model = create(:my_model, valid_attributes)
      get :show, format: :json, params: { id: @my_model.id }, session: invalid_session
      expect(assigns(:my_model)).to eq(nil)
    end
  end
  # ...
$ rspec spec/controllers/my_models_controller.rb
F

Failures:

  1) MyModelsController GET #show does not assign the requested my_model as @my_model
     Failure/Error: expect(assigns(:my_model)).to eq(nil)

       expected: nil
            got: #<my_model id: 123, #...
@gonzalo-bulnes gonzalo-bulnes added the support request This issue is a request for support using Simple Token Authentication. label Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support request This issue is a request for support using Simple Token Authentication.
Projects
None yet
Development

No branches or pull requests

2 participants