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

0.1.36 to 0.1.37 Breaks Test Suite #670

Closed
jclif opened this issue Jul 4, 2016 · 4 comments
Closed

0.1.36 to 0.1.37 Breaks Test Suite #670

jclif opened this issue Jul 4, 2016 · 4 comments

Comments

@jclif
Copy link

jclif commented Jul 4, 2016

I'm developing a Rails project with the following versions:

ruby '2.3.1'
gem 'rails', '4.2.6'

I have a working test suite on 0.1.36 using the following approach:

  • spec/support/devise.rb:
RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller
end
  • spec/support/sign_in.rb
module ValidUserHelper
  def sign_in_as_valid_user
    @current_user ||= FactoryGirl.create :user
    @current_user.confirm
    sign_in @current_user
  end
end

RSpec.configure do |config|
  config.include ValidUserHelper, :type => :controller
end
  • app/controllers/api/base_controller.rb
class API::BaseController < ApplicationController
  before_action :authenticate_user!
  respond_to :json
end

Upon upgrading to 0.1.37, I found that all of the requests in my controller specs were returning 401 Unauthorized. Has anyone else run into this issue?

@jclif jclif changed the title 0.1.34 to 0.1.37 Breaks Test Suite 0.1.35 to 0.1.37 Breaks Test Suite Jul 4, 2016
@jclif jclif changed the title 0.1.35 to 0.1.37 Breaks Test Suite 0.1.36 to 0.1.37 Breaks Test Suite Jul 4, 2016
@jclif
Copy link
Author

jclif commented Jul 7, 2016

Changing my sign_in_as_valid_user to this helped:

module ValidUserHelper
  def sign_in_as_valid_user
    @current_user ||= FactoryGirl.create :user
    @current_user.confirm
    sign_in @current_user
    request.headers.merge!(@current_user.create_new_auth_token)
  end
end

RSpec.configure do |config|
  config.include ValidUserHelper, :type => :controller
end

@adamsanderson
Copy link

adamsanderson commented Aug 21, 2016

Just wanted to mention that I ran into the same issue. I upgraded both devise and devise_token_auth so I can't be sure which introduced the issue, but for minitest the following fixed the sign_in method:

class ActionController::TestCase
  include Devise::Test::ControllerHelpers

  def sign_in(user)
    super
    request.headers.merge!(user.create_new_auth_token)
  end

I'm using devise (4.2.0) and devise_token_auth (0.1.39)

@ShaunSpringer
Copy link

👍 I am experiencing this issue too. The above solutions didn't work for me

seza443 added a commit to GeoHealth/HAppi_backend that referenced this issue Feb 8, 2017
Add `include DeviseTokenAuth::Concerns::SetUserByToken` to fix 302 redirection

Applying this solution to fix issue : lynndylanhurley/devise_token_auth#670 (comment)
@zachfeldman
Copy link
Contributor

Hi there @jclif ,

In an effort to cleanup this project and prioritize a bit, we're marking issues that haven't had any activity in a while with a "close-in-7-days" label. If we don't hear from you in about a week, we'll be closing this issue. Obviously feel free to re-open it at any time if it's the right time or this was done in error!

If you are still having the issue (especially if it's a bug report) please refer to our new Issue Template to provide some more details to help us solve it.

Hope all is well.

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

4 participants