-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcodeharbor_link_policy_spec.rb
79 lines (66 loc) · 2.29 KB
/
codeharbor_link_policy_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe CodeharborLinkPolicy do
subject(:policy) { described_class }
let(:codeharbor_link) { create(:codeharbor_link) }
context 'when CodeHarbor link is enabled' do
before do
allow(CodeharborLinkPolicy::CODEHARBOR_CONFIG).to receive(:[]).with(:enabled).and_return(true)
end
%i[index? show?].each do |action|
permissions(action) do
it 'does not grant access any user' do
%i[external_user teacher admin].each do |factory_name|
expect(policy).not_to permit(create(factory_name), codeharbor_link)
end
end
end
end
%i[new? create?].each do |action|
permissions(action) do
it 'grants access to teachers' do
%i[teacher admin].each do |factory_name|
expect(policy).to permit(create(factory_name), codeharbor_link)
end
end
it 'does not grant access to all other users' do
expect(policy).not_to permit(create(:external_user), codeharbor_link)
end
end
end
%i[destroy? edit? update?].each do |action|
permissions(action) do
it 'grants access to the owner of the link' do
expect(policy).to permit(codeharbor_link.user, codeharbor_link)
end
it 'grants access to admins' do
expect(policy).to permit(create(:admin), codeharbor_link)
end
it 'does not grant access to arbitrary users' do
%i[external_user teacher].each do |factory_name|
expect(policy).not_to permit(create(factory_name), codeharbor_link)
end
end
end
end
permissions :enabled? do
it 'reflects the config option' do
%i[external_user admin teacher].each do |factory_name|
expect(policy).to permit(create(factory_name), codeharbor_link)
end
end
end
end
context 'when CodeHabor link is disabled' do
before do
allow(CodeharborLinkPolicy::CODEHARBOR_CONFIG).to receive(:[]).with(:enabled).and_return(false)
end
permissions :enabled? do
it 'reflects the config option' do
%i[external_user admin teacher].each do |factory_name|
expect(policy).not_to permit(create(factory_name), codeharbor_link)
end
end
end
end
end