Тестирование устройства входа пользователя, но получение 401 несанкционированного ответа
Я использую devise_auth_token
драгоценный камень в rails-api
приложение, в котором я пытаюсь проверить, если user
является logged_in
затем user
уполномочен render
через index
действие в welcome_controller
,
welcome_controller
class Api::WelcomeController < ApplicationController
before_action :authenticate_user!
def index
render json: {
data: {
message: "Welcome #{current_user.first_name}",
user: current_user
}
}, status: 200
end
end
Маршруты
Rails.application.routes.draw do
mount_devise_token_auth_for 'User', at: 'auth'
namespace :api do
get 'welcome', to: 'welcome#index'
resources :socities
end
end
welcome_controller_test
require 'test_helper'
class Api::WelcomeControllerTest < ActionDispatch::IntegrationTest
def test_index_renders_message
admin = users :admin
sign_in admin
get "/api/welcome"
assert_response :success
end
end
Светильник users.yml
admin:
uid: admin@example.com
provider: email
email: admin@example.com
first_name: Ahmad
last_name: Hamza
nickname: nil
society_id: 1
encrypted_password: $2a$10$kPXgGIFeHxoek/UgfwtVFeLCLYgIB82Cazj8c6GZz2I/p68ohfp9K #1234test
confirmed_at: 2017-01-02 08:31:23
confirmation_sent_at: 2017-01-02 08:30:59
role: admin
test_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
class ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
end
ошибка
Failure:
Api::WelcomeControllerTest#test_index_renders_message [/Users/ahmadhamza/sites/manage_society/test/controllers/api/welcome_controller_test.rb:8]:
Expected response to be a <2XX: success>, but was a <401: Unauthorized>
Как проверить, что не так происходит?