2019-10-24 20:06:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-27 08:56:50 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe ApplicationSetting::TermPolicy do
|
2018-04-27 08:56:50 -04:00
|
|
|
include TermsHelper
|
|
|
|
|
2020-02-18 10:08:51 -05:00
|
|
|
let_it_be(:term) { create(:term) }
|
2021-04-09 05:09:10 -04:00
|
|
|
|
2018-04-27 08:56:50 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
subject(:policy) { described_class.new(user, term) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the correct permissions', :aggregate_failures do
|
|
|
|
is_expected.to be_allowed(:accept_terms)
|
|
|
|
is_expected.to be_allowed(:decline_terms)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for anonymous users' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
|
|
|
it 'has the correct permissions', :aggregate_failures do
|
|
|
|
is_expected.to be_disallowed(:accept_terms)
|
|
|
|
is_expected.to be_disallowed(:decline_terms)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the terms are not current' do
|
|
|
|
before do
|
|
|
|
create(:term)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the correct permissions', :aggregate_failures do
|
|
|
|
is_expected.to be_disallowed(:accept_terms)
|
|
|
|
is_expected.to be_disallowed(:decline_terms)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user already accepted the terms' do
|
|
|
|
before do
|
|
|
|
accept_terms(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the correct permissions', :aggregate_failures do
|
|
|
|
is_expected.to be_disallowed(:accept_terms)
|
|
|
|
is_expected.to be_allowed(:decline_terms)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|