diff --git a/spec/auth_helpers.rb b/spec/auth_helpers.rb new file mode 100644 index 0000000..27869d4 --- /dev/null +++ b/spec/auth_helpers.rb @@ -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 diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index dce28cc..28397cc 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -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|