Add authentification helper to RSpec config

This commit is contained in:
Thor77 2018-11-24 19:16:55 +01:00
parent 8b3b8352e5
commit 3744bf6858
No known key found for this signature in database
GPG Key ID: 5051E71B46AA669A
2 changed files with 12 additions and 1 deletions

8
spec/auth_helpers.rb Normal file
View File

@ -0,0 +1,8 @@
# frozen_string_literal: true
module AuthHelpers
def apply_authentication_headers_for(user)
user_headers = user.create_new_auth_token
@request.headers.merge!(user_headers)
end
end

View File

@ -1,7 +1,8 @@
# frozen_string_literal: true
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
require 'auth_helpers'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
# Prevent database truncation if the environment is production
@ -61,6 +62,8 @@ RSpec.configure do |config|
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
config.include FactoryBot::Syntax::Methods
config.include Devise::Test::ControllerHelpers, type: :controller
config.include AuthHelpers
end
Shoulda::Matchers.configure do |config|