mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-15 05:34:53 +08:00
22 lines
699 B
Ruby
22 lines
699 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
require 'rails_helper'
|
||
|
|
||
|
RSpec.shared_examples 'a controller with authentication' do |actions_with_params, actions_to_skip|
|
||
|
let (:protected_actions) { described_class.instance_methods(false) - (actions_to_skip || []) }
|
||
|
|
||
|
describe 'controller actions' do
|
||
|
context 'unauthenticated user' do
|
||
|
it 'returns forbidden response for all actions' do
|
||
|
sign_out :user
|
||
|
actions_with_params ||= {}
|
||
|
protected_actions.each do |action|
|
||
|
params = actions_with_params[action]
|
||
|
get action, params: params
|
||
|
expect(response).to have_http_status(:forbidden).or redirect_to('/users/sign_in')
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|